• T
    ALSA: rawmidi: Fix race at copying & updating the position · 81f57754
    Takashi Iwai 提交于
    The rawmidi read and write functions manage runtime stream status
    such as runtime->appl_ptr and runtime->avail.  These point where to
    copy the new data and how many bytes have been copied (or to be
    read).  The problem is that rawmidi read/write call copy_from_user()
    or copy_to_user(), and the runtime spinlock is temporarily unlocked
    and relocked while copying user-space.  Since the current code
    advances and updates the runtime status after the spin unlock/relock,
    the copy and the update may be asynchronous, and eventually
    runtime->avail might go to a negative value when many concurrent
    accesses are done.  This may lead to memory corruption in the end.
    
    For fixing this race, in this patch, the status update code is
    performed in the same lock before the temporary unlock.  Also, the
    spinlock is now taken more widely in snd_rawmidi_kernel_read1() for
    protecting more properly during the whole operation.
    
    BugLink: http://lkml.kernel.org/r/CACT4Y+b-dCmNf1GpgPKfDO0ih+uZCL2JV4__j-r1kdhPLSgQCQ@mail.gmail.comReported-by: NDmitry Vyukov <dvyukov@google.com>
    Tested-by: NDmitry Vyukov <dvyukov@google.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: NTakashi Iwai <tiwai@suse.de>
    81f57754
rawmidi.c 49.3 KB
反馈
建议
客服 返回
顶部