]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
ALSA: usb-audio: Avoid dropping MIDI events at closing multiple ports
authorTakashi Iwai <tiwai@suse.de>
Tue, 18 Feb 2025 11:40:24 +0000 (12:40 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Mar 2025 17:25:28 +0000 (18:25 +0100)
commitee5d6cb5cc0bc7fd4bad7c7ad5741a9e90e6191c
tree7cb7896f2a1761663c4a85e4ffd01a5c2ea5b3cb
parent22a0ebfb183642689890491356b9e8df6d9135a9
ALSA: usb-audio: Avoid dropping MIDI events at closing multiple ports

[ Upstream commit a3bdd8f5c2217e1cb35db02c2eed36ea20fb50f5 ]

We fixed the UAF issue in USB MIDI code by canceling the pending work
at closing each MIDI output device in the commit below.  However, this
assumed that it's the only one that is tied with the endpoint, and it
resulted in unexpected data truncations when multiple devices are
assigned to a single endpoint and opened simultaneously.

For addressing the unexpected MIDI message drops, simply replace
cancel_work_sync() with flush_work().  The drain callback should have
been already invoked before the close callback, hence the port->active
flag must be already cleared.  So this just assures that the pending
work is finished before freeing the resources.

Fixes: 0125de38122f ("ALSA: usb-audio: Cancel pending work at closing a MIDI substream")
Reported-and-tested-by: John Keeping <jkeeping@inmusicbrands.com>
Closes: https://lore.kernel.org/20250217111647.3368132-1-jkeeping@inmusicbrands.com
Link: https://patch.msgid.link/20250218114024.23125-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/usb/midi.c