]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
ALSA: pcm: Fix possible inconsistent appl_ptr update via mmap
authorTakashi Iwai <tiwai@suse.de>
Fri, 16 Jun 2017 20:29:55 +0000 (22:29 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 20 Jun 2017 05:55:59 +0000 (07:55 +0200)
commitaa30db060121f688d01f74f8d3fe603f7c4c731c
tree394bf468d0fe87aae513a108bc60caec7413dde0
parenteb8d0eaaf84b0398533a7c091a0b65663f2fd7ea
ALSA: pcm: Fix possible inconsistent appl_ptr update via mmap

The ALSA PCM core refers to the appl_ptr value stored on the mmapped
page that is shared between kernel and user-space.  Although the
reference is performed in the PCM stream lock, it doesn't guarantee
the atomic access when the value gets updated concurrently from the
user-space on another CPU.

In most of codes, this is no big problem, but still there are a few
places that may result in slight inconsistencies because they access
runtime->control->appl_ptr multiple times; that is, the second read
might be a different value from the first value.  It can be even
backward or jumping, as we have no control for it.  Hence, the
calculation may give an unexpected value.  Luckily, there is no
security vulnerability by that, as far as I've checked.  But still we
should address it.

This patch tries to reduce such possible cases.  The fix is simple --
we just read once, store it to a local variable and use it for the
rest calculations.  The READ_ONCE() macro is used for it in order to
avoid the ill-effect by possible compiler optimizations.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/pcm_lib.c