Skip to content

Commit 15b7a03

Browse files
committed
ALSA: line6: Fix racy access to midibuf
There can be concurrent accesses to line6 midibuf from both the URB completion callback and the rawmidi API access. This could be a cause of KMSAN warning triggered by syzkaller below (so put as reported-by here). This patch protects the midibuf call of the former code path with a spinlock for avoiding the possible races. Reported-by: [email protected] Closes: https://lore.kernel.org/[email protected] Cc: <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 312c04c commit 15b7a03

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

sound/usb/line6/driver.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,14 @@ static void line6_data_received(struct urb *urb)
286286
{
287287
struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
288288
struct midi_buffer *mb = &line6->line6midi->midibuf_in;
289+
unsigned long flags;
289290
int done;
290291

291292
if (urb->status == -ESHUTDOWN)
292293
return;
293294

294295
if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
296+
spin_lock_irqsave(&line6->line6midi->lock, flags);
295297
done =
296298
line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
297299

@@ -300,12 +302,15 @@ static void line6_data_received(struct urb *urb)
300302
dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n",
301303
done, urb->actual_length);
302304
}
305+
spin_unlock_irqrestore(&line6->line6midi->lock, flags);
303306

304307
for (;;) {
308+
spin_lock_irqsave(&line6->line6midi->lock, flags);
305309
done =
306310
line6_midibuf_read(mb, line6->buffer_message,
307311
LINE6_MIDI_MESSAGE_MAXLEN,
308312
LINE6_MIDIBUF_READ_RX);
313+
spin_unlock_irqrestore(&line6->line6midi->lock, flags);
309314

310315
if (done <= 0)
311316
break;

0 commit comments

Comments
 (0)