Skip to contentSkip to conversation

ALSA: fireworks: bound device-supplied status before string array lookup

PATCH In review Greg Kroah-Hartman 3 participants 3 messages Apr 9 – Apr 10

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

PATCH 1/1 ALSA: fireworks: bound device-supplied status before string array lookup

The status field in an EFW response is a 32-bit value supplied by the firewire device. efr_status_names[] has 17 entries so a status value outside that range goes off into the weeds when looking at the %s value.

Even worse, the status could return EFR_STATUS_INCOMPLETE which is 0x80000000, and is obviously not in that array of potential strings.

Fix this up by properly bounding the index against the array size and printing "unknown" if it's not recognized.

Cc Clemens Ladisch <[email protected]>
Cc Takashi Sakamoto <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
Fixes bde8a8f23bbe ("ALSA: fireworks: Add transaction and some commands")
Cc stable <[email protected]>
Assisted-by gregkh_clanker_t1000
---
 sound/firewire/fireworks/fireworks_command.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
sound/firewire/fireworks/fireworks_command.c +4 -1
index 2b595ee0bc35..05550f36fac5 100644
@@ -151,10 +151,13 @@ efw_transaction(struct snd_efw *efw, unsigned int category,
 	    (be32_to_cpu(header->category) != category) ||
 	    (be32_to_cpu(header->command) != command) ||
 	    (be32_to_cpu(header->status) != EFR_STATUS_OK)) {
+		u32 st = be32_to_cpu(header->status);
+
 		dev_err(&efw->unit->device, "EFW command failed [%u/%u]: %s\n",
 			be32_to_cpu(header->category),
 			be32_to_cpu(header->command),
-			efr_status_names[be32_to_cpu(header->status)]);
+			st < ARRAY_SIZE(efr_status_names) ?
+				efr_status_names[st] : "unknown");
 		err = -EIO;
 		goto end;
 	}
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 18 lines · Greg Kroah-Hartman

The status field in an EFW response is a 32-bit value supplied by the firewire device. efr_status_names[] has 17 entries so a status value outside that range goes off into the weeds when looking at the %s value.

Even worse, the status could return EFR_STATUS_INCOMPLETE which is 0x80000000, and is obviously not in that array of potential strings.

Fix this up by properly bounding the index against the array size and printing "unknown" if it's not recognized.

Cc Clemens Ladisch <[email protected]>
Cc Takashi Sakamoto <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
Fixes bde8a8f23bbe ("ALSA: fireworks: Add transaction and some commands")
Cc stable <[email protected]>
Assisted-by gregkh_clanker_t1000
Quoted 3 lines
---
 sound/firewire/fireworks/fireworks_command.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Good catch.

Thanks

Takashi Sakamoto

#2 lore raw
In reply to Greg Kroah-Hartman
Quoted 11 lines · Greg Kroah-Hartman

The status field in an EFW response is a 32-bit value supplied by the firewire device. efr_status_names[] has 17 entries so a status value outside that range goes off into the weeds when looking at the %s value.

Even worse, the status could return EFR_STATUS_INCOMPLETE which is 0x80000000, and is obviously not in that array of potential strings.

Fix this up by properly bounding the index against the array size and printing "unknown" if it's not recognized.

Quoted 8 lines
Cc Clemens Ladisch <[email protected]>
Cc Takashi Sakamoto <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
Fixes bde8a8f23bbe ("ALSA: fireworks: Add transaction and some commands")
Cc stable <[email protected]>
Assisted-by gregkh_clanker_t1000

Applied now to for-next branch. Thanks.

Takashi