ACPI: APEI: EINJ: Validate length of the Vendor Error Type Extension structure
PATCH 1/1 ACPI: APEI: EINJ: Validate length of the Vendor Error Type Extension structure
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.
---
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(+)
drivers/acpi/apei/einj-core.c +6 -0
@@ -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",
Signature · 1 line
2.33.0
Quoted 4 lines
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.
Production machine? Or just an internal development machine? I.e. is this broken BIOS out in the wild for others to hit this bug?
drivers/acpi/apei/einj-core.c static void check_vendor_extension(u64 paddr, · line 279
Quoted 4 lines
drivers/acpi/apei/einj-core.c +2
-0+if (v.length <sizeof (v) || v.length >PAGE_SIZE ) { + pr_warn(FW_BUG "Invalid vendor error extension length %u\n",
The "FW_BUG" tag was created specifically to point blame at BIOS and thus encourage OEMs to fix their BIOS. So correct use of it here :-)
drivers/acpi/apei/einj-core.c static void check_vendor_extension(u64 paddr, · line 283
Quoted 4 lines
drivers/acpi/apei/einj-core.c +4
-0+ v.length); +acpi_os_unmap_iomem (p,sizeof (v)); +return ; + }
The fix looks reasonable. If this has been seen on a production system, then seems a good idea to apply your patch.
-Tony
Hi Tony,
Quoted 7 lines · Tony
Quoted 4 lines
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.
Production machine? Or just an internal development machine? I.e. is this broken BIOS out in the wild for others to hit this bug?
The bug was hit on one of my development machines. The BIOS is pretty old.
$ cat /sys/class/dmi/id/bios_vendor Huawei Corp. $ cat /sys/class/dmi/id/bios_date 09/18/2019
I'm afraid that I can't tell whether this exact BIOS version ever shipped on production machines.
So this patch may effectively just be a workaround for my old machine. I'll leave the decision on whether it's worth taking to maintainers. ;-)
Quoted 12 lines
drivers/acpi/apei/einj-core.c static void check_vendor_extension(u64 paddr, · line 279
Quoted 3 lines
drivers/acpi/apei/einj-core.c +2
-0+if (v.length <sizeof (v) || v.length >PAGE_SIZE ) { + pr_warn(FW_BUG "Invalid vendor error extension length %u\n",The "
FW_BUG" tag was created specifically to point blame at BIOS and thus encourage OEMs to fix their BIOS. So correct use of it here :-)drivers/acpi/apei/einj-core.c static void check_vendor_extension(u64 paddr, · line 283
Quoted 4 lines
drivers/acpi/apei/einj-core.c +4
-0+ v.length); +acpi_os_unmap_iomem (p,sizeof (v)); +return ; + }
Quoted 4 lines
The fix looks reasonable. If this has been seen on a production system, then seems a good idea to apply your patch.
Reviewed-by Tony Luck <[email protected]>
Thanks for your review!
Zenghui
Mauro Carvalho Chehab
Reviewed-byQuoted 7 lines · Tony
Quoted 4 lines
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.
Production machine? Or just an internal development machine? I.e. is this broken BIOS out in the wild for others to hit this bug?
As a reminder, any VM runs with a BIOS that is not produced by an OEM, and there are lots of production environments running VMs out there.
So, I'd say that, if the fix is good, better apply it.
From my side:
Thanks,
Mauro
Quoted 12 lines · Mauro Carvalho Chehab
Quoted 7 lines · Tony
Quoted 4 lines
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.
Production machine? Or just an internal development machine? I.e. is this broken BIOS out in the wild for others to hit this bug?
Quoted 8 lines
As a reminder, any VM runs with a BIOS that is not produced by an OEM, and there are lots of production environments running VMs out there.
So, I'd say that, if the fix is good, better apply it.
From my side:
Reviewed-by Mauro Carvalho Chehab <[email protected]>
Applied as 7.5 material, thanks!