Skip to contentSkip to conversation

ASoC: Intel: fix possible acpi enumeration panic

PATCH In review Kevin Strasser 3 participants 7 messages Dec 11, 2014 – Dec 16, 2014

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

PATCH 1/1 ASoC: Intel: fix possible acpi enumeration panic

A crash can occur on some platforms where adsp is enumerated but codec is not matched. Check that the codec_id string is valid before attempting to match.

---
 sound/soc/intel/sst/sst_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/intel/sst/sst_acpi.c +1 -1
index 31124aa..dd72e58 100644
@@ -236,7 +236,7 @@ static struct sst_machines *sst_acpi_find_machine(
 	struct sst_machines *mach;
 	bool found = false;
 
-	for (mach = machines; mach->codec_id; mach++)
+	for (mach = machines; mach->codec_id[0]; mach++)
 		if (ACPI_SUCCESS(acpi_get_devices(mach->codec_id,
 						  sst_acpi_mach_match,
 						  &found, NULL)) && found)
Signature · 1 line
1.9.1
maintainer
#1 lore raw

sound/soc/intel/sst/sst_acpi.c static struct sst_machines *sst_acpi_find_machine( · line 239

Quoted 6 lines · Kevin Strasser

A crash can occur on some platforms where adsp is enumerated but codec is not matched. Check that the codec_id string is valid before attempting to match.

sound/soc/intel/sst/sst_acpi.c +1 -1
-	for (mach = machines; mach->codec_id; mach++)
+	for (mach = machines; mach->codec_id[0]; mach++)

This changes the check from verifying if a codec_id is present to verifying if the first character in the codec_id is non-NULL. That doesn't seem obviously safer and the tables of machines seem to be terminated by having an entry with all fields set to zero (which is a common idiom in Linux) which would now crash with this change.

#2 lore raw
Quoted 9 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Thursday, December 11, 2014 5:20 AM>

Quoted 3 lines · Kevin Strasser

A crash can occur on some platforms where adsp is enumerated but codec is not matched. Check that the codec_id string is valid before attempting to match.

Quoted 8 lines

sound/soc/intel/sst/sst_acpi.c static struct sst_machines *sst_acpi_find_machine( · line 239

Quoted 2 lines
sound/soc/intel/sst/sst_acpi.c +1 -1
-	for (mach = machines; mach->codec_id; mach++)
+	for (mach = machines; mach->codec_id[0]; mach++)

This changes the check from verifying if a codec_id is present to verifying if the first character in the codec_id is non-NULL. That doesn't seem obviously safer and the tables of machines seem to be terminated by having an entry with all fields set to zero (which is a common idiom in Linux) which would now crash with this change.

In this case mach->codec_id is non-NULL, even for the terminating element, because it is defined to be a fixed width. So we have to take a look at the first character to see if it has been initialized.

-Kevin

maintainer
#3 lore raw

On Thu, Dec 11, 2014 at 09:55:38PM +0000, Strasser, Kevin wrote:

Please fix your mailer to word wrap comfortably under 80 colums so that your mails are easily legible.

Quoted 9 lines
Quoted 5 lines

This changes the check from verifying if a codec_id is present to verifying if the first character in the codec_id is non-NULL. That doesn't seem obviously safer and the tables of machines seem to be terminated by having an entry with all fields set to zero (which is a common idiom in Linux) which would now crash with this change.

In this case mach->codec_id is non-NULL, even for the terminating element, because it is defined to be a fixed width. So we have to take a look at the first character to see if it has been initialized.

That's a really unusual and (as you've seen) error prone idiom - is it not better to fix the struct to use the more common idiom?

#4 lore raw
Quoted 2 lines · Mark Brown

Please fix your mailer to word wrap comfortably under 80 colums so that your mails are easily legible.

Understood

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

This changes the check from verifying if a codec_id is present to verifying if the first character in the codec_id is non-NULL. That doesn't seem obviously safer and the tables of machines seem to be terminated by having an entry with all fields set to zero (which is a common idiom in Linux) which would now crash with this change.

Quoted 6 lines
Quoted 3 lines

In this case mach->codec_id is non-NULL, even for the terminating element, because it is defined to be a fixed width. So we have to take a look at the first character to see if it has been initialized.

That's a really unusual and (as you've seen) error prone idiom - is it not better to fix the struct to use the more common idiom?

That seems like a good idea to me. I'll prepare a new patch to change the sst_machines definition so that codec_id gets initialized to NULL.

-Kevin

#5 lore raw

PATCH v2 1/1 ASoC: Intel: fix possible acpi enumeration panic

In reply to Kevin Strasser

A crash can occur on some platforms where adsp is enumerated but codec is not matched. Define codec_id as a pointer intead of an array so that it gets initialized to NULL for the terminating element of sst_acpi_bytcr[] and sst_acpi_chv[].

---
 sound/soc/intel/sst/sst_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/intel/sst/sst_acpi.c +1 -1
index 31124aa..87b5090 100644
@@ -43,7 +43,7 @@
 #include "sst.h"
 
 struct sst_machines {
-	char codec_id[32];
+	char *codec_id;
 	char board[32];
 	char machine[32];
 	void (*machine_quirk)(void);
Signature · 1 line
1.9.1
maintainer Applied
#6 lore raw
Quoted 4 lines · Kevin Strasser

A crash can occur on some platforms where adsp is enumerated but codec is not matched. Define codec_id as a pointer intead of an array so that it gets initialized to NULL for the terminating element of sst_acpi_bytcr[] and sst_acpi_chv[].

Applied, thanks.