Skip to contentSkip to conversation

ALSA: seq: Serialize compat port-info ioctls

PATCH In review Bruno Produit 2 participants 2 messages Sep 17

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

PATCH 1/1 ALSA: seq: Serialize compat port-info ioctls

From: Kyle Zeng <[email protected]>

The native sequencer ioctl path serializes handler calls with client->ioctl_mutex, but the translated port-info compat path invokes the same handlers through snd_seq_kernel_client_ctl() without taking that mutex.

This lets concurrent compat CREATE_PORT requests pass the port-count check before any request reaches the serialized insertion. The computed integer port index can then exceed the address field range and wrap to an existing index. Subsequent subscriber teardown can resolve the duplicate address to the wrong port and access a freed subscriber.

Take ioctl_mutex while dispatching converted port-info requests, matching the native ioctl path. All translated port-info commands share this helper, so their accesses to the client port state are serialized as well.

Fixes b3defb791b26 ("ALSA: seq: Make ioctls race-free")
Assisted-by Codex:gpt-5.6-sol gpt-6-astra

---

Trail of Bits has a reproducer for this bug that triggers a KASAN use-after-free and can it share if needed

 sound/core/seq/seq_compat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/core/seq/seq_compat.c +3 -1
index 22679dca9..80110501d 100644
@@ -44,7 +44,9 @@ static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned
 		return -EFAULT;
 	data->kernel = NULL;
 
-	err = snd_seq_kernel_client_ctl(client->number, cmd, data);
+	scoped_guard(mutex, &client->ioctl_mutex) {
+		err = snd_seq_kernel_client_ctl(client->number, cmd, data);
+	}
 	if (err < 0)
 		return err;
 
#1 lore raw
Quoted 24 lines · Bruno Produit

From: Kyle Zeng <[email protected]>

The native sequencer ioctl path serializes handler calls with client->ioctl_mutex, but the translated port-info compat path invokes the same handlers through snd_seq_kernel_client_ctl() without taking that mutex.

This lets concurrent compat CREATE_PORT requests pass the port-count check before any request reaches the serialized insertion. The computed integer port index can then exceed the address field range and wrap to an existing index. Subsequent subscriber teardown can resolve the duplicate address to the wrong port and access a freed subscriber.

Take ioctl_mutex while dispatching converted port-info requests, matching the native ioctl path. All translated port-info commands share this helper, so their accesses to the client port state are serialized as well.

Fixes b3defb791b26 ("ALSA: seq: Make ioctls race-free")
Assisted-by Codex:gpt-5.6-sol gpt-6-astra
Quoted 4 lines

---

Trail of Bits has a reproducer for this bug that triggers a KASAN use-after-free and can it share if needed

The bug looks obvious, a long-standing oversight.
Applied now.

thanks,

Takashi