Skip to contentSkip to conversation

ALSA: hda: ignore invalid NHLT table

PATCH Applied Mark Pearson 3 participants 5 messages Mar 2, 2021 – Mar 4, 2021 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda: ignore invalid NHLT table

On some Lenovo systems if the microphone is disabled in the BIOS only the NHLT table header is created, with no data. This means the endpoints field is not correctly set to zero - leading to an unintialised variable and hence invalid descriptors are parsed leading to page faults.

The Lenovo firmware team is addressing this, but adding a check preventing invalid tables being parsed is worthwhile.

Tested on a Lenovo T14.

---
 sound/hda/intel-nhlt.c | 5 +++++
 1 file changed, 5 insertions(+)
sound/hda/intel-nhlt.c +5 -0
index 059aaf04f..0889f2cc5 100644
@@ -37,6 +37,11 @@ int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt)
 	if (!nhlt)
 		return 0;
 
+	if (nhlt->header.length <= sizeof(struct acpi_table_header)) {
+		dev_warn(dev, "Invalid DMIC description table\n");
+		return 0;
+	}
+
 	epnt = (struct nhlt_endpoint *)nhlt->desc;
 
 	for (j = 0; j < nhlt->endpoint_count; j++) {
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw

Adding Mark, Takashi, Jaroslav and Cezary in Cc:

Quoted 6 lines · Mark Pearson

On some Lenovo systems if the microphone is disabled in the BIOS only the NHLT table header is created, with no data. This means the endpoints field is not correctly set to zero - leading to an unintialised variable and hence invalid descriptors are parsed leading to page faults.

Quoted 8 lines

The Lenovo firmware team is addressing this, but adding a check preventing invalid tables being parsed is worthwhile.

Tested on a Lenovo T14.

The change looks good to me

Out of curiosity, does this impact Kabylake or CometLake+ systems?

Thanks!

Quoted 21 lines
---
  sound/hda/intel-nhlt.c | 5 +++++
  1 file changed, 5 insertions(+)
sound/hda/intel-nhlt.c +5 -0
index 059aaf04f..0889f2cc5 100644
@@ -37,6 +37,11 @@ int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt)
  	if (!nhlt)
  		return 0;
 
+	if (nhlt->header.length <= sizeof(struct acpi_table_header)) {
+		dev_warn(dev, "Invalid DMIC description table\n");
+		return 0;
+	}
+
  	epnt = (struct nhlt_endpoint *)nhlt->desc;
 
  	for (j = 0; j < nhlt->endpoint_count; j++) {
#2 lore raw

Hi Pierre-Louis,

Quoted 1 line · Pierre-Louis Bossart

Adding Mark, Takashi, Jaroslav and Cezary in Cc:

Thanks - I wasn't sure who needed to be on this :)

Quoted 17 lines · Mark Pearson
Quoted 6 lines

On some Lenovo systems if the microphone is disabled in the BIOS only the NHLT table header is created, with no data. This means the endpoints field is not correctly set to zero - leading to an unintialised variable and hence invalid descriptors are parsed leading to page faults.

Quoted 8 lines

The Lenovo firmware team is addressing this, but adding a check preventing invalid tables being parsed is worthwhile.

Tested on a Lenovo T14.

Quoted 5 lines

The change looks good to me

Out of curiosity, does this impact Kabylake or CometLake+ systems?

We've seen it on some of our CometLake systems so far. T14 & T15 are confirmed, but it will take a while to cycle through all the platforms. We're unlikely to catch any non-Linux certified systems that folk still put Linux on - I'd like to have this available for them too.

Quoted 23 lines

Thanks!

Quoted 20 lines

---
  sound/hda/intel-nhlt.c | 5 +++++

  1 file changed, 5 insertions(+)
sound/hda/intel-nhlt.c +4 -0
index 059aaf04f..0889f2cc5 100644
@@ -37,6 +37,11 @@ int intel_nhlt_get_dmic_geo(struct device *dev,
 struct nhlt_acpi_table *nhlt)
       if (!nhlt)
           return 0;
   +    if (nhlt->header.length <= sizeof(struct acpi_table_header)) {
+        dev_warn(dev, "Invalid DMIC description table\n");
+        return 0;
+    }
+
       epnt = (struct nhlt_endpoint *)nhlt->desc;
         for (j = 0; j < nhlt->endpoint_count; j++) {
Applied
#3 lore raw
Quoted 7 lines · Mark Pearson

Hi Pierre-Louis,

Quoted 1 line · Pierre-Louis Bossart

Adding Mark, Takashi, Jaroslav and Cezary in Cc:

Thanks - I wasn't sure who needed to be on this :)

Thanks, applied now.

Unfortunately the patch conflicted slightly with the recent change by Pierre, so I corrected in my side. Please check it later.

Takashi

#4 lore raw
Quoted 6 lines · Takashi Iwai
Quoted 4 lines · Mark Pearson

Hi Pierre-Louis,

On 02/03/2021 09:46, Pierre-Louis Bossart wrote:

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

Adding Mark, Takashi, Jaroslav and Cezary in Cc:

Thanks - I wasn't sure who needed to be on this :)

Thanks, applied now.

Unfortunately the patch conflicted slightly with the recent change by Pierre, so I corrected in my side. Please check it later.

Will do.

Thanks!
Mark