|
Lee, Chun-Yi |
8d2002 |
From: Mark Langsdorf <mlangsdo@redhat.com>
|
|
Lee, Chun-Yi |
8d2002 |
Date: Wed, 5 Jan 2022 11:47:14 -0600
|
|
Lee, Chun-Yi |
8d2002 |
Subject: ACPI: SPCR: check if table->serial_port.access_width is too wide
|
|
Lee, Chun-Yi |
8d2002 |
Patch-mainline: v5.17-rc1
|
|
Lee, Chun-Yi |
8d2002 |
Git-commit: ee3fe99ff0a27108ac38d9766ac0e92f5ec35692
|
|
Lee, Chun-Yi |
8d2002 |
References: jsc#PED-1408
|
|
Lee, Chun-Yi |
8d2002 |
|
|
Lee, Chun-Yi |
8d2002 |
If table->serial_port.access_width is more than 29, it causes
|
|
Lee, Chun-Yi |
8d2002 |
undefined behavior when ACPI_ACCESS_BIT_WIDTH shifts it to
|
|
Lee, Chun-Yi |
8d2002 |
(1 << ((size) + 2)):
|
|
Lee, Chun-Yi |
8d2002 |
|
|
Lee, Chun-Yi |
8d2002 |
[ 0.000000] UBSAN: Undefined behaviour in drivers/acpi/spcr.c:114:11
|
|
Lee, Chun-Yi |
8d2002 |
[ 0.000000] shift exponent 102 is too large for 32-bit type 'int'
|
|
Lee, Chun-Yi |
8d2002 |
|
|
Lee, Chun-Yi |
8d2002 |
Use the new ACPI_ACCESS_ defines to test that serial_port.access_width
|
|
Lee, Chun-Yi |
8d2002 |
is less than 30 and set it to 6 if it is not.
|
|
Lee, Chun-Yi |
8d2002 |
|
|
Lee, Chun-Yi |
8d2002 |
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
|
|
Lee, Chun-Yi |
8d2002 |
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
|
|
Lee, Chun-Yi |
8d2002 |
Acked-by: Lee, Chun-Yi <jlee@suse.com>
|
|
Lee, Chun-Yi |
8d2002 |
---
|
|
Lee, Chun-Yi |
8d2002 |
drivers/acpi/spcr.c | 9 +++++++--
|
|
Lee, Chun-Yi |
8d2002 |
1 file changed, 7 insertions(+), 2 deletions(-)
|
|
Lee, Chun-Yi |
8d2002 |
|
|
Lee, Chun-Yi |
8d2002 |
--- a/drivers/acpi/spcr.c
|
|
Lee, Chun-Yi |
8d2002 |
+++ b/drivers/acpi/spcr.c
|
|
Lee, Chun-Yi |
8d2002 |
@@ -107,8 +107,13 @@ int __init acpi_parse_spcr(bool enable_e
|
|
Lee, Chun-Yi |
8d2002 |
pr_info("SPCR table version %d\n", table->header.revision);
|
|
Lee, Chun-Yi |
8d2002 |
|
|
Lee, Chun-Yi |
8d2002 |
if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
|
|
Lee, Chun-Yi |
8d2002 |
- switch (ACPI_ACCESS_BIT_WIDTH((
|
|
Lee, Chun-Yi |
8d2002 |
- table->serial_port.access_width))) {
|
|
Lee, Chun-Yi |
8d2002 |
+ u32 bit_width = table->serial_port.access_width;
|
|
Lee, Chun-Yi |
8d2002 |
+
|
|
Lee, Chun-Yi |
8d2002 |
+ if (bit_width > ACPI_ACCESS_BIT_MAX) {
|
|
Lee, Chun-Yi |
8d2002 |
+ pr_err("Unacceptable wide SPCR Access Width. Defaulting to byte size\n");
|
|
Lee, Chun-Yi |
8d2002 |
+ bit_width = ACPI_ACCESS_BIT_DEFAULT;
|
|
Lee, Chun-Yi |
8d2002 |
+ }
|
|
Lee, Chun-Yi |
8d2002 |
+ switch (ACPI_ACCESS_BIT_WIDTH((bit_width))) {
|
|
Lee, Chun-Yi |
8d2002 |
default:
|
|
Lee, Chun-Yi |
8d2002 |
pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n");
|
|
Lee, Chun-Yi |
8d2002 |
fallthrough;
|