Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3551836ioa; Tue, 26 Apr 2022 05:59:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhFQDaXaVOG7Ww8yg/jZad4X4f3RbXxqDZe55dEqm1ZMsxXOC3LemoKXtuVaKrKqMU4tu0 X-Received: by 2002:a17:907:168a:b0:6da:9167:47dc with SMTP id hc10-20020a170907168a00b006da916747dcmr21082069ejc.126.1650977990626; Tue, 26 Apr 2022 05:59:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650977990; cv=none; d=google.com; s=arc-20160816; b=bPcRtvNhCclrRVmAWRXP9U+1XroFZAEq/4iGUZ5jAJGJG3cBY15jshMSX8ciJ5n8GI TXLFH2oXGVYzI1NSnNNggFV00suulr71xNSteY7MuWGO8Gt+10fmqqvL4VIJyJIlNZeN RC0cwismF4tI5WXYkfVnsEXGnq4xqna/5VFyvOMRgmvZrNtDDiD8THPl+M4e1fWyJLqT 0Dh9YhcBrE/jfySpRmb92UxV7166xcrEcZgmJSQKWHLoRfESyf2n3CKXxd6YhkWXIG5I 0CMehnNiFNThA3vMYI8ZEdN2aw1TLjM4pqwdfJzBXJbgdRHnjCb2A/ybkroHGupNHsQQ hOvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=56Aj5VvM1NMAat7Vab7+CpswIqY3x1I5urpJDpylIfY=; b=iqGlGEyz58uTly3mCmYVEyWvG4Cs5vWIVJRJCCZkmOCLIjN5m46E14IF2uKhGYnDTR 3+mndg+HB4fzBjyCYwnN26tsC97JKi5N0wJye+eARrouEzOBDTSqGhUh/7NIiCSg2Zvy th0gZKJG/VSTIXMk2TV82H8HxJM52R/CowEbUVzk3QT4sCytpnFc53iuH8BnCpzWp3sy wh6Jm9egjlbbEbbwMhdXNk3RcOiZ1A6dSks3NqV8j/2Wt5maEG4Fn1sqMLMT0+TUgu9R Agu+WHUv1D9x/dQLtRL+6jl09S60nn59wNJKRCHPSSqJ7mqrD4xqZaUg4W7SfSJKPEZG PhRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OrL9imO4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n26-20020aa7c45a000000b00425d4551781si7645033edr.434.2022.04.26.05.59.26; Tue, 26 Apr 2022 05:59:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OrL9imO4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346901AbiDZJBb (ORCPT + 99 others); Tue, 26 Apr 2022 05:01:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346899AbiDZIp3 (ORCPT ); Tue, 26 Apr 2022 04:45:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F93611C3D; Tue, 26 Apr 2022 01:36:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2C85E617E7; Tue, 26 Apr 2022 08:36:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27257C385AC; Tue, 26 Apr 2022 08:36:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962186; bh=NVsQUUF/tJdoP9yIQoTGPFAQXLh4WYEGBYuFJEQX1SE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OrL9imO4aqcB3y8aNIZSDL4nxv4eP61jJusEIl6osKeQ1uuLBDK3tBt8LVYviTCK+ 0ePvMCmRJDinbAXnsiDHusjc5EN51tVREqjR5FHq7Yxgf0XXy7UQExsOb8EDAKd903 MqvmpzSztLWCRdYbXD8Dpy2A91D2MYEmr5dhwjz8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+70e777a39907d6d5fd0a@syzkaller.appspotmail.com, Takashi Iwai Subject: [PATCH 5.15 015/124] ALSA: usb-audio: Clear MIDI port active flag after draining Date: Tue, 26 Apr 2022 10:20:16 +0200 Message-Id: <20220426081747.734351104@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081747.286685339@linuxfoundation.org> References: <20220426081747.286685339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai commit 0665886ad1392e6b5bae85d7a6ccbed48dca1522 upstream. When a rawmidi output stream is closed, it calls the drain at first, then does trigger-off only when the drain returns -ERESTARTSYS as a fallback. It implies that each driver should turn off the stream properly after the drain. Meanwhile, USB-audio MIDI interface didn't change the port->active flag after the drain. This may leave the output work picking up the port that is closed right now, which eventually leads to a use-after-free for the already released rawmidi object. This patch fixes the bug by properly clearing the port->active flag after the output drain. Reported-by: syzbot+70e777a39907d6d5fd0a@syzkaller.appspotmail.com Cc: Link: https://lore.kernel.org/r/00000000000011555605dceaff03@google.com Link: https://lore.kernel.org/r/20220420130247.22062-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/usb/midi.c | 1 + 1 file changed, 1 insertion(+) --- a/sound/usb/midi.c +++ b/sound/usb/midi.c @@ -1194,6 +1194,7 @@ static void snd_usbmidi_output_drain(str } while (drain_urbs && timeout); finish_wait(&ep->drain_wait, &wait); } + port->active = 0; spin_unlock_irq(&ep->buffer_lock); }