Skip to contentSkip to conversation

ALSA: hda: handle UAF at probe error

PATCH Lucas De Marchi 3 participants 4 messages Apr 15, 2022 – Apr 19, 2022 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 6 lines · Nirmoy Das

Call snd_card_free_on_error() on probe error instead of calling snd_card_free() which should handle devres call orders.

Issues: https://gitlab.freedesktop.org/drm/intel/-/issues/5701

Fixes e8ad415b7a55 ("ALSA: core: Add managed card creation")

This failure in i915 CI seems suspicious since is around module removal.
https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_102714v1/fi-tgl-1115g4/igt@[email protected]

And it seems it didn't fix the issue in dg2:

https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_102714v1/bat-dg2-8/igt@[email protected]

Lucas De Marchi

Quoted 39 lines

---
sound/pci/hda/hda_intel.c | 7 ++++---

1 file changed, 4 insertions(+), 3 deletions(-)
sound/pci/hda/hda_intel.c +4 -2
index 82a45f2b31c4..eb4228c9e37f 100644
@@ -1730,7 +1730,9 @@ static void azx_check_snoop_available(struct azx *chip)
 static void azx_probe_work(struct work_struct *work)
 {
 	struct hda_intel *hda = container_of(work, struct hda_intel, probe_work.work);
-	azx_probe_continue(&hda->chip);
+	struct azx *chip = &hda->chip;
+
+	snd_card_free_on_error(&chip->pci->dev, azx_probe_continue(chip));
 }
 
 static int default_bdl_pos_adj(struct azx *chip)
@@ -2028,7 +2030,7 @@ static void azx_firmware_cb(const struct firmware *fw, void *context)
 		dev_err(card->dev, "Cannot load firmware, continue without patching\n");
 	if (!chip->disabled) {
 		/* continue probing */
-		azx_probe_continue(chip);
+		snd_card_free_on_error(&chip->pci->dev, azx_probe_continue(chip));
 	}
 }
 #endif
@@ -2338,7 +2340,6 @@ static int azx_probe_continue(struct azx *chip)

out_free:

	if (err < 0) {
		pci_set_drvdata(pci, NULL);
sound/pci/hda/hda_intel.c +0 -1
-		snd_card_free(chip->card);
		return err;
	}
Signature · 1 line
2.35.1
#2 lore raw
Quoted 11 lines · Lucas De Marchi
Quoted 6 lines · Nirmoy Das

Call snd_card_free_on_error() on probe error instead of calling snd_card_free() which should handle devres call orders.

Issues: https://gitlab.freedesktop.org/drm/intel/-/issues/5701

Fixes e8ad415b7a55 ("ALSA: core: Add managed card creation")

This failure in i915 CI seems suspicious since is around module removal.
https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_102714v1/fi-tgl-1115g4/igt@[email protected]

Yes, the issue is related to module reload  because I can reproduce a UAF by running the module reload test twice.

Quoted 4 lines

And it seems it didn't fix the issue in dg2:

https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_102714v1/bat-dg2-8/igt@[email protected]

I guess this is some timing bug around device hotplug  as this patch seems to help even though this driver doesn't use devres. I need to check more.

Thanks,

Nirmoy

Quoted 45 lines

Lucas De Marchi

Quoted 42 lines

---
sound/pci/hda/hda_intel.c | 7 ++++---

1 file changed, 4 insertions(+), 3 deletions(-)
sound/pci/hda/hda_intel.c +3 -1
index 82a45f2b31c4..eb4228c9e37f 100644
@@ -1730,7 +1730,9 @@ static void azx_check_snoop_available(struct 
 azx *chip)
 static void azx_probe_work(struct work_struct *work)
 {
     struct hda_intel *hda = container_of(work, struct hda_intel, probe_work.work);
-    azx_probe_continue(&hda->chip);
+    struct azx *chip = &hda->chip;
+
+    snd_card_free_on_error(&chip->pci->dev, azx_probe_continue(chip));
 }
 

static int default_bdl_pos_adj(struct azx *chip)

sound/pci/hda/hda_intel.c +1 -1
@@ -2028,7 +2030,7 @@ static void azx_firmware_cb(const struct 
 firmware *fw, void *context)
         dev_err(card->dev, "Cannot load firmware, continue without patching\n");
     if (!chip->disabled) {
         /* continue probing */
-        azx_probe_continue(chip);
+        snd_card_free_on_error(&chip->pci->dev, 
 azx_probe_continue(chip));
     }

}
#endif

sound/pci/hda/hda_intel.c +0 -0
@@ -2338,7 +2340,6 @@ static int azx_probe_continue(struct azx *chip)

out_free:
    if (err < 0) {
        pci_set_drvdata(pci, NULL);
-        snd_card_free(chip->card);
        return err;
    }

Signature · 1 line
2.35.1
#3 lore raw
In reply to a message not in the archive
Quoted 3 lines · Nirmoy Das

Call snd_card_free_on_error() on probe error instead of calling snd_card_free() which should handle devres call orders.

This won't change any practical behavior, because HD-audio driver doesn't use snd_devm_card_new(). snd_card_free() still gets called explicitly in the relevant code paths.

Quoted 1 line

Issues: https://gitlab.freedesktop.org/drm/intel/-/issues/5701

So it must be a different cause for this problem...

thanks,

Takashi

#4 lore raw
Quoted 6 lines · Takashi Iwai
Quoted 2 lines · Nirmoy Das

Call snd_card_free_on_error() on probe error instead of calling snd_card_free() which should handle devres call orders.

This won't change any practical behavior, because HD-audio driver doesn't use snd_devm_card_new().

OK, I guess I am looking into some timing dependent issue because with the

patch I didn't see the UAF.

Thanks,

Nirmoy

Quoted 10 lines

snd_card_free() still gets called
explicitly in the relevant code paths.

Quoted 1 line

Issues: https://gitlab.freedesktop.org/drm/intel/-/issues/5701

So it must be a different cause for this problem...

thanks,

Takashi