Skip to contentSkip to conversation

snd/hda: fix use-after-free after module unload

PATCH In review Takashi Iwai 2 participants 4 messages Jul 11, 2016 1 message not in the archive Sound

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 17 lines · Peter Wu

register_vga_switcheroo() sets the PM ops from the hda structure which is freed later in azx_free. Make sure that these ops are cleared.

Caught by KASAN.

Fixes 246efa4a072f ("snd/hda: add runtime suspend/resume on optimus support (v4)")
---
 sound/pci/hda/hda_intel.c | 1 +
 1 file changed, 1 insertion(+)
sound/pci/hda/hda_intel.c +0 -0
index 94089fc..a339066 100644

sound/pci/hda/hda_intel.c static int azx_free(struct azx *chip) · line 1222

Quoted 4 lines
sound/pci/hda/hda_intel.c +1 -0
@@ -1219,6 +1219,7 @@ static int azx_free(struct azx *chip)
 			snd_hda_unlock_devices(&chip->bus);
 		if (hda->vga_switcheroo_registered)
 			vga_switcheroo_unregister_client(chip->pci);
+        vga_switcheroo_fini_domain_pm_ops(chip->card->dev);

The domain pm ops is set only when hda->vga_switcheroo_registered flag is set. So the call should be in the previous if block.

Also, the indentation looks wrong. Please use the correct indentation.

Could you resubmit with these fixes?

thanks,

Takashi

#2 lore raw
Quoted 14 lines · Takashi Iwai
Quoted 12 lines · Peter Wu

register_vga_switcheroo() sets the PM ops from the hda structure which is freed later in azx_free. Make sure that these ops are cleared.

Caught by KASAN.

Fixes 246efa4a072f ("snd/hda: add runtime suspend/resume on optimus support (v4)")
---
 sound/pci/hda/hda_intel.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 12 lines

sound/pci/hda/hda_intel.c static int azx_free(struct azx *chip) · line 1222

Quoted 9 lines
sound/pci/hda/hda_intel.c +1 -0
index 94089fc..a339066 100644
@@ -1219,6 +1219,7 @@ static int azx_free(struct azx *chip)
 			snd_hda_unlock_devices(&chip->bus);
 		if (hda->vga_switcheroo_registered)
 			vga_switcheroo_unregister_client(chip->pci);
+        vga_switcheroo_fini_domain_pm_ops(chip->card->dev);

The domain pm ops is set only when hda->vga_switcheroo_registered flag is set. So the call should be in the previous if block.

Yes that would be cleaner, will do that.

Quoted 2 lines

Also, the indentation looks wrong. Please use the correct indentation.

Noticed too late that the editor config was wrong on the testing machine.

Quoted 1 line

Could you resubmit with these fixes?

I will, thanks for the feedback!

Signature · 3 lines
Kind regards,
Peter Wu
https://lekensteyn.nl
#3 lore raw

PATCH v2 1/1 snd/hda: fix use-after-free after module unload

In reply to Takashi Iwai

register_vga_switcheroo() sets the PM ops from the hda structure which is freed later in azx_free. Make sure that these ops are cleared.

Caught by KASAN, initially noticed due to a general protection fault.

Fixes 246efa4a072f ("snd/hda: add runtime suspend/resume on optimus support (v4)")

---
Maybe Cc stable?

---
 sound/pci/hda/hda_intel.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/pci/hda/hda_intel.c +3 -1
index 94089fc..4aeed98 100644
@@ -1217,8 +1217,10 @@ static int azx_free(struct azx *chip)
 	if (use_vga_switcheroo(hda)) {
 		if (chip->disabled && hda->probe_continued)
 			snd_hda_unlock_devices(&chip->bus);
-		if (hda->vga_switcheroo_registered)
+		if (hda->vga_switcheroo_registered) {
 			vga_switcheroo_unregister_client(chip->pci);
+			vga_switcheroo_fini_domain_pm_ops(chip->card->dev);
+		}
 	}
 
 	if (bus->chip_init) {
Signature · 1 line
2.9.0
#4 lore raw
Quoted 10 lines · Peter Wu

register_vga_switcheroo() sets the PM ops from the hda structure which is freed later in azx_free. Make sure that these ops are cleared.

Caught by KASAN, initially noticed due to a general protection fault.

Fixes 246efa4a072f ("snd/hda: add runtime suspend/resume on optimus support (v4)")

---
Maybe Cc stable?

Yes, I applied with Cc to stable now.

thanks,

Takashi