mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zenghui Yu <yuzenghui@huawei.com>
To: <linux-acpi@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <rafael@kernel.org>, <tony.luck@intel.com>, <bp@alien8.de>,
	<guohanjun@huawei.com>, <mchehab@kernel.org>,
	<xueshuai@linux.alibaba.com>, <lenb@kernel.org>,
	<wangzhigang17@huawei.com>, Zenghui Yu <yuzenghui@huawei.com>
Subject: [PATCH] ACPI: APEI: EINJ: Validate length of the Vendor Error Type Extension structure
Date: Wed, 11 Nov 2026 19:57:29 +0800	[thread overview]
Message-ID: <20261111115729.253-1-yuzenghui@huawei.com> (raw)

Add a sanity check for the length field of the Vendor Error Type Extension
structure to guard against a buggy BIOS, in the same way einjv2_init()
checks the EINJv2 Extension length.

The BIOS on my machine provides a zeroed structure, so the length is 0 and
vendor_size in get_oem_vendor_struct() underflows to a huge value. The
vendor error data is then exposed to user sapce through the "oem_error"
debugfs file with that bogus size, and reading it walks out of the mapped
area and panics the kernel.

Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
---

The BIOS on my machine is obviously buggy (non-zero Vendor Extension offset
pointing to zeroed memory, and bit 31 is not set in the error type either)
and needs fixing. I'm not sure if it is necessary to add such a sanity
check for EINJ at all.

The PAGE_SIZE upper bound is borrowed from the EINJv2 check in
einjv2_init(). Not sure if it is reasonable here.

 drivers/acpi/apei/einj-core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/acpi/apei/einj-core.c b/drivers/acpi/apei/einj-core.c
index 1f3fa2278584..947f32812cfe 100644
--- a/drivers/acpi/apei/einj-core.c
+++ b/drivers/acpi/apei/einj-core.c
@@ -275,6 +275,12 @@ static void check_vendor_extension(u64 paddr,
 	if (!p)
 		return;
 	memcpy_fromio(&v, p, sizeof(v));
+	if (v.length < sizeof(v) || v.length > PAGE_SIZE) {
+		pr_warn(FW_BUG "Invalid vendor error extension length %u\n",
+			v.length);
+		acpi_os_unmap_iomem(p, sizeof(v));
+		return;
+	}
 	get_oem_vendor_struct(paddr, offset, &v);
 	sbdf = v.pcie_sbdf;
 	sprintf(vendor_dev, "%x:%x:%x.%x vendor_id=%x device_id=%x rev_id=%x\n",
-- 
2.33.0


                 reply	other threads:[~2026-11-11 11:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261111115729.253-1-yuzenghui@huawei.com \
    --to=yuzenghui@huawei.com \
    --cc=bp@alien8.de \
    --cc=guohanjun@huawei.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rafael@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=wangzhigang17@huawei.com \
    --cc=xueshuai@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®