diff options
author | Takashi Iwai <tiwai@suse.de> | 2020-05-07 13:44:56 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2020-05-07 22:29:14 +0200 |
commit | c1f6e3c818dd734c30f6a7eeebf232ba2cf3181d (patch) | |
tree | f8f8f8ef8c01671898324e506a5fdce5ed6d2da1 /include/sound | |
parent | da7a8f1a8fc3e14c6dcc52b4098bddb8f20390be (diff) | |
download | linux-c1f6e3c818dd734c30f6a7eeebf232ba2cf3181d.tar.gz linux-c1f6e3c818dd734c30f6a7eeebf232ba2cf3181d.tar.bz2 linux-c1f6e3c818dd734c30f6a7eeebf232ba2cf3181d.zip |
ALSA: rawmidi: Fix racy buffer resize under concurrent accesses
The rawmidi core allows user to resize the runtime buffer via ioctl,
and this may lead to UAF when performed during concurrent reads or
writes: the read/write functions unlock the runtime lock temporarily
during copying form/to user-space, and that's the race window.
This patch fixes the hole by introducing a reference counter for the
runtime buffer read/write access and returns -EBUSY error when the
resize is performed concurrently against read/write.
Note that the ref count field is a simple integer instead of
refcount_t here, since the all contexts accessing the buffer is
basically protected with a spinlock, hence we need no expensive atomic
ops. Also, note that this busy check is needed only against read /
write functions, and not in receive/transmit callbacks; the race can
happen only at the spinlock hole mentioned in the above, while the
whole function is protected for receive / transmit callbacks.
Reported-by: butt3rflyh4ck <butterflyhuangxx@gmail.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/CAFcO6XMWpUVK_yzzCpp8_XP7+=oUpQvuBeCbMffEDkpe8jWrfg@mail.gmail.com
Link: https://lore.kernel.org/r/s5heerw3r5z.wl-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'include/sound')
-rw-r--r-- | include/sound/rawmidi.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h index a36b7227a15a..334842daa904 100644 --- a/include/sound/rawmidi.h +++ b/include/sound/rawmidi.h @@ -61,6 +61,7 @@ struct snd_rawmidi_runtime { size_t avail_min; /* min avail for wakeup */ size_t avail; /* max used buffer for wakeup */ size_t xruns; /* over/underruns counter */ + int buffer_ref; /* buffer reference count */ /* misc */ spinlock_t lock; wait_queue_head_t sleep; |