Skip to content

Commit b3defb7

Browse files
committed
ALSA: seq: Make ioctls race-free
The ALSA sequencer ioctls have no protection against racy calls while the concurrent operations may lead to interfere with each other. As reported recently, for example, the concurrent calls of setting client pool with a combination of write calls may lead to either the unkillable dead-lock or UAF. As a slightly big hammer solution, this patch introduces the mutex to make each ioctl exclusive. Although this may reduce performance via parallel ioctl calls, usually it's not demanded for sequencer usages, hence it should be negligible. Reported-by: Luo Quan <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Cc: <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent 23b19b7 commit b3defb7

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

sound/core/seq/seq_clientmgr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ static struct snd_seq_client *seq_create_client1(int client_index, int poolsize)
221221
rwlock_init(&client->ports_lock);
222222
mutex_init(&client->ports_mutex);
223223
INIT_LIST_HEAD(&client->ports_list_head);
224+
mutex_init(&client->ioctl_mutex);
224225

225226
/* find free slot in the client table */
226227
spin_lock_irqsave(&clients_lock, flags);
@@ -2130,7 +2131,9 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd,
21302131
return -EFAULT;
21312132
}
21322133

2134+
mutex_lock(&client->ioctl_mutex);
21332135
err = handler->func(client, &buf);
2136+
mutex_unlock(&client->ioctl_mutex);
21342137
if (err >= 0) {
21352138
/* Some commands includes a bug in 'dir' field. */
21362139
if (handler->cmd == SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT ||

sound/core/seq/seq_clientmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct snd_seq_client {
6161
struct list_head ports_list_head;
6262
rwlock_t ports_lock;
6363
struct mutex ports_mutex;
64+
struct mutex ioctl_mutex;
6465
int convert32; /* convert 32->64bit */
6566

6667
/* output pool */

0 commit comments

Comments
 (0)