Skip to contentSkip to conversation

ALSA: ump: fix double free of out_cvts on rawmidi error

PATCH In review Baul Lee 2 participants 2 messages Jul 26

Subsystems (2)
lore
Share & tools
lore

Baul Lee

author
#0 lore raw

PATCH 1/1 ALSA: ump: fix double free of out_cvts on rawmidi error

snd_ump_attach_legacy_rawmidi() allocates the legacy conversion array ump->out_cvts and, on the snd_rawmidi_new() error path, frees it with kfree() but leaves ump->out_cvts pointing at the freed memory. When the endpoint is later torn down, snd_ump_endpoint_free() frees ump->out_cvts a second time, resulting in a double free.

The host snd-usb-audio driver attaches the legacy rawmidi for any USB MIDI 2.0 (UMP) device, so a device that makes snd_rawmidi_new() fail reaches this path on enumeration.

Clear ump->out_cvts after freeing it on the error path so it is not freed again during teardown.

Discovered by XBOW, triaged by Baul Lee <[email protected]>

Fixes 33cd7630782d ("ALSA: ump: Export MIDI1 / UMP conversion helpers")
---
 sound/core/ump.c | 1 +
 1 file changed, 1 insertion(+)
sound/core/ump.c +1 -0
index 70520c7ca293..632c13baf21e 100644
@@ -1365,6 +1365,7 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
 			      &rmidi);
 	if (err < 0) {
 		kfree(ump->out_cvts);
+		ump->out_cvts = NULL;
 		return err;
 	}
 
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Quoted 14 lines · Baul Lee

snd_ump_attach_legacy_rawmidi() allocates the legacy conversion array ump->out_cvts and, on the snd_rawmidi_new() error path, frees it with kfree() but leaves ump->out_cvts pointing at the freed memory. When the endpoint is later torn down, snd_ump_endpoint_free() frees ump->out_cvts a second time, resulting in a double free.

The host snd-usb-audio driver attaches the legacy rawmidi for any USB MIDI 2.0 (UMP) device, so a device that makes snd_rawmidi_new() fail reaches this path on enumeration.

Clear ump->out_cvts after freeing it on the error path so it is not freed again during teardown.

Quoted 7 lines

Discovered by XBOW, triaged by Baul Lee <[email protected]>

Fixes 33cd7630782d ("ALSA: ump: Export MIDI1 / UMP conversion helpers")

Applied now. Thanks.

Takashi