Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Mark Langsdorf and committed by
Rafael J. Wysocki
ee3fe99f bca21755

+7 -2
+7 -2
drivers/acpi/spcr.c
··· 107 107 pr_info("SPCR table version %d\n", table->header.revision); 108 108 109 109 if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 110 - switch (ACPI_ACCESS_BIT_WIDTH(( 111 - table->serial_port.access_width))) { 110 + u32 bit_width = table->serial_port.access_width; 111 + 112 + if (bit_width > ACPI_ACCESS_BIT_MAX) { 113 + pr_err("Unacceptable wide SPCR Access Width. Defaulting to byte size\n"); 114 + bit_width = ACPI_ACCESS_BIT_DEFAULT; 115 + } 116 + switch (ACPI_ACCESS_BIT_WIDTH((bit_width))) { 112 117 default: 113 118 pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n"); 114 119 fallthrough;