From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE517C54EE9 for ; Mon, 19 Sep 2022 08:31:56 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 905F115C1; Mon, 19 Sep 2022 10:31:04 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 905F115C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1663576314; bh=vPNCAvWdK4S4tBAf5nTcXkrEcSPuo8U+YI9YgKe8nx0=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mkf+eHWYVMPYTY7ewkL/b8tSzfHDUfepOaVSBz15k9Zrm6OSwAFLI0V/14/lrBaMG 1LRS4PUctocYGMUu10Nkwd1JbnIg1zOQwbwPmFTpogFQi0/oq0bRPl1fK73toWcHvq vrfANs/h3uQiam+nv55OgOUqpI7LG7ZegZ6hhLt8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 22637F8016D; Mon, 19 Sep 2022 10:31:04 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A7255F8023A; Mon, 19 Sep 2022 10:31:02 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 151C4F80134 for ; Mon, 19 Sep 2022 10:30:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 151C4F80134 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="0b+AiYfP"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="xkbttTJg" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B9B5022476; Mon, 19 Sep 2022 08:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663576254; 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=Vnw8yV24NrJVgXHUmASg1y16Kkw1PabPzTLxeE4hH7c=; b=0b+AiYfPPzvDf3SzJQAi6E4IIrVvsGQfoQYZuEqS4iqZh8KL+JIOVSDsu3kI4sxA/WlfJz 86NBOW9Gz5FhAz46ZNRWFyHb2BA/tPjelSRzepF8miISNzmmDHm0OpcpEQ9/CPGG3Q2HjT nG4kdZkwVIHTteTec27nBEE8koMqKas= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663576254; 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=Vnw8yV24NrJVgXHUmASg1y16Kkw1PabPzTLxeE4hH7c=; b=xkbttTJg2wH1k788pI1dTzlxpyuKr5jlIeNxc9XVpa6qx0m1sdzW9GUR6NmtDT9LVG62mB ZAz4KQ54erC/KPBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 960DA13A96; Mon, 19 Sep 2022 08:30:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id U9DEI74oKGPtOwAAMHmgww (envelope-from ); Mon, 19 Sep 2022 08:30:54 +0000 Date: Mon, 19 Sep 2022 10:30:54 +0200 Message-ID: <871qs7dav5.wl-tiwai@suse.de> From: Takashi Iwai To: Rondreis Subject: Re: KASAN: invalid-free in snd_card_new In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, tiwai@suse.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Sun, 18 Sep 2022 15:01:11 +0200, Rondreis wrote: > > Hello, > > When fuzzing the Linux kernel driver v6.0-rc4, the following crash was > triggered. > > HEAD commit: 7e18e42e4b280c85b76967a9106a13ca61c16179 > git tree: upstream > > kernel config: https://pastebin.com/raw/xtrgsXP3 > C reproducer: https://pastebin.com/raw/w2sdQWYj > console output: https://pastebin.com/raw/Yyf7zw2d > > Basically, in the c reproducer, we use the gadget module to emulate > attaching a USB device(vendor id: 0x1bc7, product id: 0x1206, with the > midi function) and executing some simple sequence of system calls. > To reproduce this crash, we utilize a third-party library to emulate > the attaching process: https://github.com/linux-usb-gadgets/libusbgx. > Just clone this repository, install it, and compile the c > reproducer with ``` gcc crash.c -lusbgx -lconfig -o crash ``` will do > the trick. > > I would appreciate it if you have any idea how to solve this bug. Could you try the patch below? It looks like a simple double-free in the code. thanks, Takashi --- --- a/sound/core/init.c +++ b/sound/core/init.c @@ -178,10 +178,8 @@ int snd_card_new(struct device *parent, int idx, const char *xid, return -ENOMEM; err = snd_card_init(card, parent, idx, xid, module, extra_size); - if (err < 0) { - kfree(card); - return err; - } + if (err < 0) + return err; /* card is freed by error handler */ *card_ret = card; return 0; @@ -233,7 +231,7 @@ int snd_devm_card_new(struct device *parent, int idx, const char *xid, card->managed = true; err = snd_card_init(card, parent, idx, xid, module, extra_size); if (err < 0) { - devres_free(card); + devres_free(card); /* in managed mode, we need to free manually */ return err; } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DEE6C54EE9 for ; Mon, 19 Sep 2022 08:31:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbiISIbA (ORCPT ); Mon, 19 Sep 2022 04:31:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229744AbiISIa7 (ORCPT ); Mon, 19 Sep 2022 04:30:59 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 968CF1A828 for ; Mon, 19 Sep 2022 01:30:56 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B9B5022476; Mon, 19 Sep 2022 08:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663576254; 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=Vnw8yV24NrJVgXHUmASg1y16Kkw1PabPzTLxeE4hH7c=; b=0b+AiYfPPzvDf3SzJQAi6E4IIrVvsGQfoQYZuEqS4iqZh8KL+JIOVSDsu3kI4sxA/WlfJz 86NBOW9Gz5FhAz46ZNRWFyHb2BA/tPjelSRzepF8miISNzmmDHm0OpcpEQ9/CPGG3Q2HjT nG4kdZkwVIHTteTec27nBEE8koMqKas= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663576254; 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=Vnw8yV24NrJVgXHUmASg1y16Kkw1PabPzTLxeE4hH7c=; b=xkbttTJg2wH1k788pI1dTzlxpyuKr5jlIeNxc9XVpa6qx0m1sdzW9GUR6NmtDT9LVG62mB ZAz4KQ54erC/KPBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 960DA13A96; Mon, 19 Sep 2022 08:30:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id U9DEI74oKGPtOwAAMHmgww (envelope-from ); Mon, 19 Sep 2022 08:30:54 +0000 Date: Mon, 19 Sep 2022 10:30:54 +0200 Message-ID: <871qs7dav5.wl-tiwai@suse.de> From: Takashi Iwai To: Rondreis Cc: perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: Re: KASAN: invalid-free in snd_card_new In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 18 Sep 2022 15:01:11 +0200, Rondreis wrote: > > Hello, > > When fuzzing the Linux kernel driver v6.0-rc4, the following crash was > triggered. > > HEAD commit: 7e18e42e4b280c85b76967a9106a13ca61c16179 > git tree: upstream > > kernel config: https://pastebin.com/raw/xtrgsXP3 > C reproducer: https://pastebin.com/raw/w2sdQWYj > console output: https://pastebin.com/raw/Yyf7zw2d > > Basically, in the c reproducer, we use the gadget module to emulate > attaching a USB device(vendor id: 0x1bc7, product id: 0x1206, with the > midi function) and executing some simple sequence of system calls. > To reproduce this crash, we utilize a third-party library to emulate > the attaching process: https://github.com/linux-usb-gadgets/libusbgx. > Just clone this repository, install it, and compile the c > reproducer with ``` gcc crash.c -lusbgx -lconfig -o crash ``` will do > the trick. > > I would appreciate it if you have any idea how to solve this bug. Could you try the patch below? It looks like a simple double-free in the code. thanks, Takashi --- --- a/sound/core/init.c +++ b/sound/core/init.c @@ -178,10 +178,8 @@ int snd_card_new(struct device *parent, int idx, const char *xid, return -ENOMEM; err = snd_card_init(card, parent, idx, xid, module, extra_size); - if (err < 0) { - kfree(card); - return err; - } + if (err < 0) + return err; /* card is freed by error handler */ *card_ret = card; return 0; @@ -233,7 +231,7 @@ int snd_devm_card_new(struct device *parent, int idx, const char *xid, card->managed = true; err = snd_card_init(card, parent, idx, xid, module, extra_size); if (err < 0) { - devres_free(card); + devres_free(card); /* in managed mode, we need to free manually */ return err; }