Skip to content

Commit

Permalink
ALSA: line6: Fix endless MIDI read loop
Browse files Browse the repository at this point in the history
The MIDI input event parser of the LINE6 driver may enter into an
endless loop when the unexpected data sequence is given, as it tries
to continue the secondary bytes without termination.  Also, when the
input data is too short, the parser returns a negative error, while
the caller doesn't handle it properly.  This would lead to the
unexpected behavior as well.

This patch addresses those issues by checking the return value
correctly and handling the one-byte event in the parser properly.

The bug was reported by syzkaller.

Reported-by: syzbot+cce32521ee0a824c21f7@syzkaller.appspotmail.com
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/000000000000033087059f8f8fa3@google.com
Link: https://lore.kernel.org/r/20200309095922.30269-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Mar 9, 2020
1 parent f2ecf90 commit d683469
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sound/usb/line6/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static void line6_data_received(struct urb *urb)
line6_midibuf_read(mb, line6->buffer_message,
LINE6_MIDI_MESSAGE_MAXLEN);

if (done == 0)
if (done <= 0)
break;

line6->message_length = done;
Expand Down
2 changes: 1 addition & 1 deletion sound/usb/line6/midibuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ int line6_midibuf_read(struct midi_buffer *this, unsigned char *data,
int midi_length_prev =
midibuf_message_length(this->command_prev);

if (midi_length_prev > 0) {
if (midi_length_prev > 1) {
midi_length = midi_length_prev - 1;
repeat = 1;
} else
Expand Down

0 comments on commit d683469

Please sign in to comment.