UPSTREAM: ALSA: usb-audio: fix race condition to UAF in snd_usbmidi_free

The previous commit 0718a78f6a9f ("ALSA: usb-audio: Kill timer properly at
removal") patched a UAF issue caused by the error timer.

However, because the error timer kill added in this patch occurs after the
endpoint delete, a race condition to UAF still occurs, albeit rarely.

Additionally, since kill-cleanup for urb is also missing, freed memory can
be accessed in interrupt context related to urb, which can cause UAF.

Therefore, to prevent this, error timer and urb must be killed before
freeing the heap memory.

Cc: <[email protected]>
Reported-by: [email protected]
Closes: https://syzkaller.appspot.com/bug?extid=f02665daa2abeef4a947
Fixes: 0718a78f6a9f ("ALSA: usb-audio: Kill timer properly at removal")
Signed-off-by: Jeongjun Park <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>

(cherry picked from commit 9f2c0ac1423d5f267e7f1d1940780fc764b0fee3)

BUG=b:447577646
TEST=built

Change-Id: I0d0428dc0f580025c26f866af837a9bae0746028
Signed-off-by: hikalium <[email protected]>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/7071187
Reviewed-by: Masami Hiramatsu <[email protected]>
Commit-Queue: Masami Hiramatsu <[email protected]>
Reviewed-by: Sean Paul <[email protected]>
1 file changed