ALSA: seq: Serialize compat port-info ioctls
Subsystems (2)
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.
---
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
@@ -44,7 +44,9 @@ static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsignedreturn -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;
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 throughsnd_seq_kernel_client_ctl()without taking that mutex.This lets concurrent compat
CREATE_PORTrequests 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_mutexwhile 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-astraSigned-off-by Kyle Zeng <[email protected]>Signed-off-by Bruno Produit <[email protected]>
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