From 22e16db4c5e2125409abc77b888493e63bbeea86 Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Mon, 11 Sep 2023 13:40:55 -0600 Subject: acpi/soundwire.[ch]: Fix dpn entry array overrun In soundwire.h, SOUNDWIRE_DPN MIN & MAX are set to 1 and 14. When creating the dpn array, the length was set to MAX - MIN or 13, numbered 0 to 12. When accessing the array, the code was bailing out if a value greater than MAX was trying to be accessed, so the array was able to be overrun by two structure lengths. Fix this problem by: 1) Not subtracting the MIN value when creating the array, which does waste a little space. If anyone wants to refactor the code to fix that, please feel free. 2) Breaking out of the loop when the port is equal to the MAX port number instead of just when it's greater than the max port number. Reported-by: Coverity (CID:1429766 & CID:1429771) Signed-off-by: Martin Roth Change-Id: I0841bb8c9869fe9f53958f05614848785a98b766 Reviewed-on: https://review.coreboot.org/c/coreboot/+/77777 Tested-by: build bot (Jenkins) Reviewed-by: Tim Wawrzynczak --- src/acpi/soundwire.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/acpi') diff --git a/src/acpi/soundwire.c b/src/acpi/soundwire.c index af4ca7cf15..961f45b5b2 100644 --- a/src/acpi/soundwire.c +++ b/src/acpi/soundwire.c @@ -400,7 +400,7 @@ void soundwire_gen_codec(struct acpi_dp *dsd, const struct soundwire_codec *code struct acpi_dp *dpn; /* Stop processing at the first invalid data port. */ - if (entry->port < SOUNDWIRE_MIN_DPN || entry->port > SOUNDWIRE_MAX_DPN) + if (entry->port < SOUNDWIRE_MIN_DPN || entry->port >= SOUNDWIRE_MAX_DPN) break; if (entry->source) { -- cgit v1.2.3