ALSA: aloop: Fix access to not-yet-ready substream via cable
authorTakashi Iwai <tiwai@suse.de>
Thu, 22 Mar 2018 09:40:27 +0000 (10:40 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 31 May 2018 23:30:24 +0000 (00:30 +0100)
commit6acf1f11d393616cfd6cd8417e2dfe7da89bf9eb
treee55b57e022f0776f09924943fde2541540c37769
parentdc602c18947a838a422071849965ce611f9a18e1
ALSA: aloop: Fix access to not-yet-ready substream via cable

commit 8e6b1a72a75bb5067ccb6b56d8ca4aa3a300a64e upstream.

In loopback_open() and loopback_close(), we assign and release the
substream object to the corresponding cable in a racy way.  It's
neither locked nor done in the right position.  The open callback
assigns the substream before its preparation finishes, hence the other
side of the cable may pick it up, which may lead to the invalid memory
access.

This patch addresses these: move the assignment to the end of the open
callback, and wrap with cable->lock for avoiding concurrent accesses.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
sound/drivers/aloop.c