From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D03AA1714AE; Thu, 15 Aug 2024 13:36:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723728980; cv=none; b=Vwzfg9sLbXlksJSQTgGSsnmgK1VwRDGZl7cTe4IFvOcIEj6qCvw6sN0YcUnJzbpE6Cqt3sNJ0XzCiJBX27WHwy1QajGd15DAFBUX0+qxdsDmavd6IA8+8d5CPr8YSCPjc3ym+CsY6O26HymoZ6MXd2VdTI2Xb0P5gf4NAk1orUE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723728980; c=relaxed/simple; bh=ZxbUUQKlrXCNC7xWmZeoS9uMR8h6BCfBgxZPFcIlg/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GG7FDKRAcSxRBGfRCXMrJbaFOOvhdNiwR15KfTyD2lpwrnlD6uVALI2gwlBzsxqEb2AdLBUaGJ0U2GUCZ2g3B8MkFKDT6vXp98PD3nDUYJ8D6khZqTzS6jzMhFyMsE0VEC9vY1lHVzVASay8jl8f02oQOHU8+W0TX54yNV9H/nc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=THEI1J6X; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="THEI1J6X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03232C32786; Thu, 15 Aug 2024 13:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1723728980; bh=ZxbUUQKlrXCNC7xWmZeoS9uMR8h6BCfBgxZPFcIlg/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THEI1J6XJUowZyCEZmxIQkQNknOY9L5V9aHQe13YIvuGSqDDwJMdKINI5eNoYMK9A zQjMIf/JdtoG0gJB7MS69Tr7jEk0tm6vGDHrvwU35N56Rw+0YS5EkmABpIZVb0vVey BuXt9IOBQqWcWS/rAdyXmY7/dKtQ88xL8htIIt8Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+78eccfb8b3c9a85fc6c5@syzkaller.appspotmail.com, Takashi Iwai Subject: [PATCH 4.19 172/196] ALSA: line6: Fix racy access to midibuf Date: Thu, 15 Aug 2024 15:24:49 +0200 Message-ID: <20240815131858.651781774@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240815131852.063866671@linuxfoundation.org> References: <20240815131852.063866671@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit 15b7a03205b31bc5623378c190d22b7ff60026f1 upstream. 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: syzbot+78eccfb8b3c9a85fc6c5@syzkaller.appspotmail.com Closes: https://lore.kernel.org/00000000000000949c061df288c5@google.com Cc: Link: https://patch.msgid.link/20240805130129.10872-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/usb/line6/driver.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -300,12 +300,14 @@ static void line6_data_received(struct u { struct usb_line6 *line6 = (struct usb_line6 *)urb->context; struct midi_buffer *mb = &line6->line6midi->midibuf_in; + unsigned long flags; int done; if (urb->status == -ESHUTDOWN) return; if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) { + spin_lock_irqsave(&line6->line6midi->lock, flags); done = line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length); @@ -314,12 +316,15 @@ static void line6_data_received(struct u dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n", done, urb->actual_length); } + spin_unlock_irqrestore(&line6->line6midi->lock, flags); for (;;) { + spin_lock_irqsave(&line6->line6midi->lock, flags); done = line6_midibuf_read(mb, line6->buffer_message, LINE6_MIDI_MESSAGE_MAXLEN, LINE6_MIDIBUF_READ_RX); + spin_unlock_irqrestore(&line6->line6midi->lock, flags); if (done <= 0) break;