Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp4763115pxb; Wed, 20 Apr 2022 09:33:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqvzUHBgykLeLNIULQz174zydXOUcEhZFVtnpdMubLH12i0jsNzrbOr/OF3rsR4Gm+3mrp X-Received: by 2002:a05:6402:10d5:b0:408:f881:f0f3 with SMTP id p21-20020a05640210d500b00408f881f0f3mr24149036edu.112.1650472427083; Wed, 20 Apr 2022 09:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650472427; cv=none; d=google.com; s=arc-20160816; b=xsS9rTCKfF3Wdi5fSVkq1Xc/ohcoH6DV2gaWHNIGHWIBBfTQMleRkbD6w2O4tcnsbV sO8IPPRN+O+MiA8c2Y+6S4LyUc+SjgfeQPOenWdyJSrEviwCQoltLXZdzFBNAV2DtIJu 00XlTE3tRKX972ctok7CGp7rLdEwjB71M7DJj7eHfi8TibJpP33+hS5/b2Vyh1TRP7+n eLgU/DyGQ7oGvZhyuzci1b7XvPOL8Cmxj3jLXTPT+Ijsf/zBedsF1OP23cRxKb3mdeh0 EURND2LMqvT+WBNfX35Cj1ziG/SGpj0sAyqX/+8F3f+Ul/PkBqknstRgIHwOBVSW4Iss D/Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=JFQwrU2hFb4VPzzetH0Da+TO97GCBAM9wcZD3DZvdts=; b=dnusCYCjiQ7hzgXswkTJg1//Zy3qOgRD4k9wRhPGVliYunrD9lPOpMdWML47fex+w9 jzhn0P9MoDMwtDHEfy1DqMo9XHC9LRlM5r7bB2hwSSRJLpXP47cPkHT4vS9hd+oBnGX+ 6X4QRALTaW0al9DBRUvvp8RBNl+Thfo6DesAR2ykryt0zI/wRQVtfgwaHTCkatBK3Rf9 w6rEz+D+rPr4sEGkRWOT/itp5/IRd9JOBlCSVIi5qD8jrL13PIqBhsvs9iNYeYdj6WY6 sMhhw1YZf/wsq7n85fOV6LJwKaHZgXhqG77REY8nYNa+g5/UJbUuSiAEMMkqcsAgLxL7 fuNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NxuByR3i; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m11-20020a170906580b00b006e8c741b77esi2179511ejq.280.2022.04.20.09.33.18; Wed, 20 Apr 2022 09:33:47 -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=@suse.de header.s=susede2_rsa header.b=NxuByR3i; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242081AbiDSKDG (ORCPT + 99 others); Tue, 19 Apr 2022 06:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238346AbiDSKDD (ORCPT ); Tue, 19 Apr 2022 06:03:03 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB24613DC8 for ; Tue, 19 Apr 2022 03:00:20 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 861A01F74D; Tue, 19 Apr 2022 10:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1650362419; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JFQwrU2hFb4VPzzetH0Da+TO97GCBAM9wcZD3DZvdts=; b=NxuByR3iL0REQSwYvutp0rBCshkXiyJZ/QF4YoQv2O5J4y6RiOqhiF/Gxa2L6pE9XVdcxl CfYTCiE8xfo8El787gXrutmxKKNVd+jZnmnZ7emxCHb9hWKfjYV2fpdBS+dbokAhiyj/4O HozU7hWpE7zGRHkYwx+4zLIuROQKl1Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1650362419; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JFQwrU2hFb4VPzzetH0Da+TO97GCBAM9wcZD3DZvdts=; b=1s07dcO7q5RJV0Hrz1dzDIu/zQAaZRLdetxqUN0kTOPbs+kCyvMw8QIAULDf0T+v/8r9sf lOqILb7AqFMW8UAA== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 6BF7B2C14E; Tue, 19 Apr 2022 10:00:19 +0000 (UTC) Date: Tue, 19 Apr 2022 12:00:19 +0200 Message-ID: From: Takashi Iwai To: syzbot Cc: alsa-devel@alsa-project.org, coding@diwic.se, colin.king@intel.com, linux-kernel@vger.kernel.org, perex@perex.cz, syzkaller-bugs@googlegroups.com, tiwai@suse.com Subject: Re: [syzbot] KASAN: use-after-free Read in __snd_rawmidi_transmit_peek In-Reply-To: References: <00000000000011555605dceaff03@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SORTED_RECIPS, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Tue, 19 Apr 2022 11:01:47 +0200, Takashi Iwai wrote: > > On Mon, 18 Apr 2022 12:12:23 +0200, > syzbot wrote: > > > > Hello, > > > > syzbot found the following issue on: > > > > HEAD commit: a19944809fe9 Merge tag 'hardening-v5.18-rc3' of git://git... > > git tree: upstream > > console output: https://syzkaller.appspot.com/x/log.txt?x=16a40ae0f00000 > > kernel config: https://syzkaller.appspot.com/x/.config?x=eb177500e563582f > > dashboard link: https://syzkaller.appspot.com/bug?extid=70e777a39907d6d5fd0a > > compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2 > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1590dfa8f00000 > > > > IMPORTANT: if you fix the issue, please add the following tag to the commit: > > Reported-by: syzbot+70e777a39907d6d5fd0a@syzkaller.appspotmail.com > > > > ================================================================== > > BUG: KASAN: use-after-free in __snd_rawmidi_transmit_peek+0x261/0x360 sound/core/rawmidi.c:1286 > > Looks like a leftover work. The fix patch is below. On the second thought, this would be rather in a different code path, and the fix should be smaller like below. Let's see. Takashi -- 8< -- From: Takashi Iwai Subject: [PATCH] ALSA: usb-audio: Clear MIDI port active flag after draining 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 Signed-off-by: Takashi Iwai --- sound/usb/midi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/usb/midi.c b/sound/usb/midi.c index 2c01649c70f6..7c6ca2b433a5 100644 --- a/sound/usb/midi.c +++ b/sound/usb/midi.c @@ -1194,6 +1194,7 @@ static void snd_usbmidi_output_drain(struct snd_rawmidi_substream *substream) } while (drain_urbs && timeout); finish_wait(&ep->drain_wait, &wait); } + port->active = 0; spin_unlock_irq(&ep->buffer_lock); } -- 2.34.1