Skip to contentSkip to conversation

Input: applespi - validate ACPI property buffer length

PATCH Applied Tristan Madani 2 participants 2 messages Oct 29 – Nov 10

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Input: applespi - validate ACPI property buffer length

From: Tristan Madani <[email protected]>

applespi_get_spi_settings() reads three ACPI _DSD properties (spiCSDelay, resetA2RUsec, resetRecUsec) as u64 values from their buffer pointers without verifying that the buffer is at least 8 bytes long. If a firmware implementation provides a shorter buffer, the u64 dereference reads beyond the allocated object.

Add buffer length checks before each u64 dereference.

Fixes 038b1a05eae6 ("Input: add Apple SPI keyboard and trackpad driver")

---
Changes in v3:
- Drop Cc: stable since this is hardening rather than a fix for a specific regression, per Dmitry Torokhov

Changes in v2:
- Fix alignment of continued condition lines

 drivers/input/keyboard/applespi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/input/keyboard/applespi.c +6 -3
index cf25177b48301..db8947b5cf11c 100644
@@ -642,19 +642,22 @@ static int applespi_get_spi_settings(struct applespi_data *applespi)
 	const union acpi_object *o;
 	struct spi_settings *settings = &applespi->spi_settings;
 
-	if (!acpi_dev_get_property(adev, "spiCSDelay", ACPI_TYPE_BUFFER, &o))
+	if (!acpi_dev_get_property(adev, "spiCSDelay", ACPI_TYPE_BUFFER, &o) &&
+	    o->buffer.length >= sizeof(u64))
 		settings->spi_cs_delay = *(u64 *)o->buffer.pointer;
 	else
 		dev_warn(&applespi->spi->dev,
 			 "Property spiCSDelay not found\n");
 
-	if (!acpi_dev_get_property(adev, "resetA2RUsec", ACPI_TYPE_BUFFER, &o))
+	if (!acpi_dev_get_property(adev, "resetA2RUsec", ACPI_TYPE_BUFFER, &o) &&
+	    o->buffer.length >= sizeof(u64))
 		settings->reset_a2r_usec = *(u64 *)o->buffer.pointer;
 	else
 		dev_warn(&applespi->spi->dev,
 			 "Property resetA2RUsec not found\n");
 
-	if (!acpi_dev_get_property(adev, "resetRecUsec", ACPI_TYPE_BUFFER, &o))
+	if (!acpi_dev_get_property(adev, "resetRecUsec", ACPI_TYPE_BUFFER, &o) &&
+	    o->buffer.length >= sizeof(u64))
 		settings->reset_rec_usec = *(u64 *)o->buffer.pointer;
 	else
 		dev_warn(&applespi->spi->dev,
Signature · 1 line
2.47.3
maintainer Applied
#1 lore raw
Quoted 8 lines · Tristan Madani

From: Tristan Madani <[email protected]>

applespi_get_spi_settings() reads three ACPI _DSD properties (spiCSDelay, resetA2RUsec, resetRecUsec) as u64 values from their buffer pointers without verifying that the buffer is at least 8 bytes long. If a firmware implementation provides a shorter buffer, the u64 dereference reads beyond the allocated object.

Quoted 4 lines

Add buffer length checks before each u64 dereference.

Fixes 038b1a05eae6 ("Input: add Apple SPI keyboard and trackpad driver")

Applied, thank you.

Signature · 1 line
Dmitry