Skip to content

Commit d15d662

Browse files
committed
ALSA: seq: Fix racy pool initializations
ALSA sequencer core initializes the event pool on demand by invoking snd_seq_pool_init() when the first write happens and the pool is empty. Meanwhile user can reset the pool size manually via ioctl concurrently, and this may lead to UAF or out-of-bound accesses since the function tries to vmalloc / vfree the buffer. A simple fix is to just wrap the snd_seq_pool_init() call with the recently introduced client->ioctl_mutex; as the calls for snd_seq_pool_init() from other side are always protected with this mutex, we can avoid the race. Reported-by: 范龙飞 <[email protected]> Cc: <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent 1dcb185 commit d15d662

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sound/core/seq/seq_clientmgr.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
10031003
{
10041004
struct snd_seq_client *client = file->private_data;
10051005
int written = 0, len;
1006-
int err = -EINVAL;
1006+
int err;
10071007
struct snd_seq_event event;
10081008

10091009
if (!(snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT))
@@ -1018,11 +1018,15 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
10181018

10191019
/* allocate the pool now if the pool is not allocated yet */
10201020
if (client->pool->size > 0 && !snd_seq_write_pool_allocated(client)) {
1021-
if (snd_seq_pool_init(client->pool) < 0)
1021+
mutex_lock(&client->ioctl_mutex);
1022+
err = snd_seq_pool_init(client->pool);
1023+
mutex_unlock(&client->ioctl_mutex);
1024+
if (err < 0)
10221025
return -ENOMEM;
10231026
}
10241027

10251028
/* only process whole events */
1029+
err = -EINVAL;
10261030
while (count >= sizeof(struct snd_seq_event)) {
10271031
/* Read in the event header from the user */
10281032
len = sizeof(event);

0 commit comments

Comments
 (0)