diff options
author | Takashi Iwai <tiwai@suse.de> | 2021-04-15 15:18:56 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2021-04-16 09:57:49 +0200 |
commit | 998f26f47e556f14cd124c508d76bceb2c3f6e6a (patch) | |
tree | 8c7720ee8e97ab081bcf3b5c38f85d7b0362c358 /sound/pci | |
parent | ebe8dc5afb3912e2d4f5c62cf7c492a13143a77a (diff) | |
download | linux-stable-998f26f47e556f14cd124c508d76bceb2c3f6e6a.tar.gz linux-stable-998f26f47e556f14cd124c508d76bceb2c3f6e6a.tar.bz2 linux-stable-998f26f47e556f14cd124c508d76bceb2c3f6e6a.zip |
ALSA: control: Fix racy management of user ctl memory size account
We've got a report about the possible race in the user control element
counts (card->user_ctl_count), and it was confirmed that the race
wasn't serious in the old code up to 5.12. There, the value
modification itself was exclusive and protected via a write semaphore,
hence it's at most concurrent reads and evaluations before the
increment. Since it's only about the soft-limit to avoid the
exhausting memory usage, one-off isn't a big problem at all.
Meanwhile, the relevant code has been largely modified recently, and
now card->user_ctl_count was replaced with card->user_ctl_alloc_size,
and a few more places were added to access this field. And, in this
new code, it turned out to be more serious: the modifications are
scattered in various places, and a few of them are without protection.
It implies that it may lead to an inconsistent value by racy
accesses.
For addressing it, this patch extends the range covered by the
card->controls_rwsem write lock at snd_ctl_elem_add() so that the all
code paths that modify and refer to card->user_ctl_alloc_size are
protected by the rwsem properly.
The patch adds also comments in a couple of functions to indicate that
they are under the rwsem lock.
Fixes: 66c6d1ef86ff ("ALSA: control: Add memory consumption limit to user controls")
Link: https://lore.kernel.org/r/FEEBF384-44BE-42CF-8FB3-93470933F64F@purdue.edu
Link: https://lore.kernel.org/r/20210415131856.13113-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci')
0 files changed, 0 insertions, 0 deletions