Skip to contentSkip to conversation

ACPI: SPCR: check if table->serial_port.access_width is too wide

PATCH Applied Mark Langsdorf 2 participants 2 messages Jan 5, 2022 – Jan 11, 2022 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: SPCR: check if table->serial_port.access_width is too wide

If table->serial_port.access_width is more than 29, it causes undefined behavior when ACPI_ACCESS_BIT_WIDTH shifts it to (1 << ((size) + 2)):

[    0.000000] UBSAN: Undefined behaviour in drivers/acpi/spcr.c:114:11
[    0.000000] shift exponent 102 is too large for 32-bit type 'int'

Use the new ACPI_ACCESS_ defines to test that serial_port.access_width is less than 30 and set it to 6 if it is not.

---
 drivers/acpi/spcr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/acpi/spcr.c +7 -2
index 25c2d0be953e..d589543875b8 100644
@@ -107,8 +107,13 @@ int __init acpi_parse_spcr(bool enable_earlycon, bool enable_console)
 		pr_info("SPCR table version %d\n", table->header.revision);
 
 	if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
-		switch (ACPI_ACCESS_BIT_WIDTH((
-			table->serial_port.access_width))) {
+		u32 bit_width = table->serial_port.access_width;
+
+		if (bit_width > ACPI_ACCESS_BIT_MAX) {
+			pr_err("Unacceptable wide SPCR Access Width.  Defaulting to byte size\n");
+			bit_width = ACPI_ACCESS_BIT_DEFAULT;
+		}
+		switch (ACPI_ACCESS_BIT_WIDTH((bit_width))) {
 		default:
 			pr_err("Unexpected SPCR Access Width.  Defaulting to byte size\n");
 			fallthrough;
Signature · 1 line
2.26.3
maintainer Applied
#1 lore raw
Quoted 27 lines · Mark Langsdorf

If table->serial_port.access_width is more than 29, it causes undefined behavior when ACPI_ACCESS_BIT_WIDTH shifts it to (1 << ((size) + 2)):

[    0.000000] UBSAN: Undefined behaviour in drivers/acpi/spcr.c:114:11
[    0.000000] shift exponent 102 is too large for 32-bit type 'int'

Use the new ACPI_ACCESS_ defines to test that serial_port.access_width is less than 30 and set it to 6 if it is not.

---
 drivers/acpi/spcr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/acpi/spcr.c +1 -2
index 25c2d0be953e..d589543875b8 100644
@@ -107,8 +107,13 @@ int __init acpi_parse_spcr(bool enable_earlycon, bool enable_console)
                pr_info("SPCR table version %d\n", table->header.revision);
 
        if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
-               switch (ACPI_ACCESS_BIT_WIDTH((
-                       table->serial_port.access_width))) {
+               u32 bit_width = table->serial_port.access_width;

drivers/acpi/spcr.c int __init acpi_parse_spcr(bool enable_earlycon, bool enable_console)

Quoted 10 lines
drivers/acpi/spcr.c +6 -1
+
+               if (bit_width > ACPI_ACCESS_BIT_MAX) {
+                       pr_err("Unacceptable wide SPCR Access Width.  Defaulting to byte size\n");
+                       bit_width = ACPI_ACCESS_BIT_DEFAULT;
+               }
+               switch (ACPI_ACCESS_BIT_WIDTH((bit_width))) {
                default:
                        pr_err("Unexpected SPCR Access Width.  Defaulting to byte size\n");
                        fallthrough;
--

Applied as 5.17-rc material, thanks!