From patchwork Mon Mar 8 22:30:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Skripkin X-Patchwork-Id: 396111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D572C433E0 for ; Tue, 9 Mar 2021 07:06:43 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 5BE82652A4 for ; Tue, 9 Mar 2021 07:06:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5BE82652A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 D11F917DA; Tue, 9 Mar 2021 08:05:50 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D11F917DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1615273600; bh=XYd/samGcXEe3kImjos3lFoXUEYLe1K9WW4i1p27cr4=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Xnbpqq5mCZ9bJwmkYrO0v8rRsRjvoQc4PLrl3kxykH3Y5lO9GnTBmYBcMtk9Mrg3H LAxaC0tOgZIiuB7K/I+FNKO8m8V9BBhIjPs5ztUhvQ43LNdtX8VINQDfYDJnvYwSUS FMwtZR9uvtMHaZcHCpf6O8ZTtCP3cQYJEmTignPA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id BA31FF804D1; Tue, 9 Mar 2021 08:02:12 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 40432F801D8; Mon, 8 Mar 2021 23:30:58 +0100 (CET) Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) (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 A7B28F80139 for ; Mon, 8 Mar 2021 23:30:49 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A7B28F80139 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q2RMvGYZ" Received: by mail-lf1-x136.google.com with SMTP id p21so23628535lfu.11 for ; Mon, 08 Mar 2021 14:30:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iW5ng6iEejvRMljMHfkKvj6+YTTzMof7NCYEOCF/AsQ=; b=Q2RMvGYZWGjX429xvgVCL9cuQIc+3cKcAD9TLhoHLcmuIXN2Let0Jbtk3LdbODPNTa NxeK/8zzqLqmf1qVDoT9MN/ocENVPb1ekZ4Gj+Sw3vIB74lolRKGxVQ54yjAaiJN97tT 7iNprzA6v1+yu6EXzCkzSYB4qm+pSA+mKWfgKJ70nFYjgkPLry9BvZuujFXL8P7BXOzt cNhhkw8fO4oXkvWQKt84Ssqe9TlQK7tde3SyruRlvdk9CV5gOI7Omf331lSkOFgdbwOk ngCsz58cGJr76i8xxLSr1ilU95Kd0swhXX00QzpDXO50aqdBTBTP8H7zzyWl4XAGUfSI DTVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iW5ng6iEejvRMljMHfkKvj6+YTTzMof7NCYEOCF/AsQ=; b=qU5adxt878OZdhi4fuQHBsW4u0AcM5fecp3kMfBMeHLgHpPM4UVQcElR5eKWAwEyie FABWvJIvFOgkYQYMvahDllZrR+f2PUiXnt+z8qHCISWziFdWC/WbB4DpdW6N8MQdlIzK aqiBykeyMBWER6p1VNeDPUeT3S4DF/u9KyyCuiO4Xtv4kd9DXh+lOFBgnwzhOi/jn9pv Mj68q8IegQvhAsnP3xnDcUaj/9rW2xcUha+4oCvlU0pYyoCGIB2krfSX3FJByLxYPaFM WVt41t6wmHq0HDw0mzijXKD43L7ag8lio43n0rGIeHsvSD6rj5N6zkqHfDYMFNKWrlHQ df/Q== X-Gm-Message-State: AOAM532SJVkJEH+d7E5O6OBK6hAqQcNZCI8ym/yTd0CYgr3y47lmwaHA 5KUk8vTX32gIvv+UzDXn/YXMmjJownNeZ1cp X-Google-Smtp-Source: ABdhPJxoslaDSSHtgXh6g/iImKFgMLC6pad8pEJWqxQDJorwJEiY3vd+1Oh2zSRB94JhMkf6WShACw== X-Received: by 2002:a05:6512:482:: with SMTP id v2mr15983387lfq.52.1615242648619; Mon, 08 Mar 2021 14:30:48 -0800 (PST) Received: from localhost.localdomain ([94.103.235.167]) by smtp.gmail.com with ESMTPSA id x27sm1496976lfu.151.2021.03.08.14.30.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 14:30:48 -0800 (PST) From: Pavel Skripkin To: perex@perex.cz, tiwai@suse.com, kai.heng.feng@canonical.com Subject: [PATCH next 1/2] sound: usb: fix NULL ptr dereference in usb_audio_probe Date: Tue, 9 Mar 2021 01:30:36 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 09 Mar 2021 08:02:00 +0100 Cc: Pavel Skripkin , alsa-devel@alsa-project.org, syzbot+719da9b149a931f5143f@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org 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" syzbot reported null pointer dereference in usb_audio_probe. The problem was in case, when quirk == NULL. It's not an error condition, so quirk must be checked before dereferencing. Call Trace: usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396 really_probe+0x291/0xe60 drivers/base/dd.c:554 driver_probe_device+0x26b/0x3d0 drivers/base/dd.c:740 __device_attach_driver+0x1d1/0x290 drivers/base/dd.c:846 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:431 __device_attach+0x228/0x4a0 drivers/base/dd.c:914 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:491 device_add+0xbdb/0x1db0 drivers/base/core.c:3242 usb_set_configuration+0x113f/0x1910 drivers/usb/core/message.c:2164 usb_generic_driver_probe+0xba/0x100 drivers/usb/core/generic.c:238 usb_probe_device+0xd9/0x2c0 drivers/usb/core/driver.c:293 really_probe+0x291/0xe60 drivers/base/dd.c:554 driver_probe_device+0x26b/0x3d0 drivers/base/dd.c:740 __device_attach_driver+0x1d1/0x290 drivers/base/dd.c:846 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:431 __device_attach+0x228/0x4a0 drivers/base/dd.c:914 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:491 device_add+0xbdb/0x1db0 drivers/base/core.c:3242 usb_new_device.cold+0x721/0x1058 drivers/usb/core/hub.c:2555 hub_port_connect drivers/usb/core/hub.c:5223 [inline] hub_port_connect_change drivers/usb/core/hub.c:5363 [inline] port_event drivers/usb/core/hub.c:5509 [inline] hub_event+0x2357/0x4320 drivers/usb/core/hub.c:5591 process_one_work+0x98d/0x1600 kernel/workqueue.c:2275 worker_thread+0x64c/0x1120 kernel/workqueue.c:2421 kthread+0x3b1/0x4a0 kernel/kthread.c:292 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294 Reported-by: syzbot+719da9b149a931f5143f@syzkaller.appspotmail.com Fixes: 9799110825db ("ALSA: usb-audio: Disable USB autosuspend properly in setup_disable_autosuspend()") Signed-off-by: Pavel Skripkin --- sound/usb/card.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sound/usb/card.c b/sound/usb/card.c index 08c794883299..3fd1743513b5 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -830,7 +830,8 @@ static int usb_audio_probe(struct usb_interface *intf, snd_media_device_create(chip, intf); } - chip->quirk_type = quirk->type; + if (quirk) + chip->quirk_type = quirk->type; usb_chip[chip->index] = chip; chip->intf[chip->num_interfaces] = intf; From patchwork Mon Mar 8 22:30:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Skripkin X-Patchwork-Id: 396806 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D8DAC433DB for ; Tue, 9 Mar 2021 07:06:58 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 61927652AB for ; Tue, 9 Mar 2021 07:06:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61927652AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 D9BE817F2; Tue, 9 Mar 2021 08:06:05 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D9BE817F2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1615273615; bh=x23yB0wlRmaNOxrEU9vy0NvUtVHCTaKUL5u5Qy0aOUE=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Z5xPbq2pDx4ngSojQk/BxwiPJqBX2eTyoLIWypWFUZz2QxFSn0US1cDqnoVvX2EV2 jPVsnkOe0q6QQSGZKNCOts2j7T5etNoD5YHw09Kl8AU1wtVxv19i09xJ0zoZIqx+iC Cm7mAutavlUXAEUytgHedjAyhz2fc1zv1+VWkWrA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AAD3AF804DF; Tue, 9 Mar 2021 08:02:13 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9E3F2F801D8; Mon, 8 Mar 2021 23:31:13 +0100 (CET) Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) (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 CFB07F800ED for ; Mon, 8 Mar 2021 23:31:08 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz CFB07F800ED Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M+wVnP/K" Received: by mail-lf1-x12b.google.com with SMTP id r3so15506225lfc.13 for ; Mon, 08 Mar 2021 14:31:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mgVtVDJ4J9ZfP2mfzS736WoTsMup5fvgpbnXS5Fe3a8=; b=M+wVnP/KB8I6w466Y9xFPc5hUX+YdtfnLVnYCpM9Kp7Cw6dUrl6pRvJhajm5PjYBxT SfeJj6wvAM0tR+tYPY6aqBtQ9MxgQZHO5ph34MNOveLyXa+aSY2yvVB8XBLGg95SJdmI iVyIZB5ajJ/CNZkE8Pcvcv8bSsk8vtURxkpCGi7DFoKCcB54czUnVA3+sIAKdxQkWjR/ FBewIzUOuhD98dNY9UMPnWC4aCfcIGj+krz6tT7KLwvwsMAnUd1halJIn32yvhAHPRqd UvNETUESRmdktnLcZkEHNZ2SShn+E4gmRb5M/TJ9OEA+FUWmqBG+x+UqoV2q07fcnxVR /UeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mgVtVDJ4J9ZfP2mfzS736WoTsMup5fvgpbnXS5Fe3a8=; b=lEoc4MpdsLwQlSU/XUW08q9AfbsD4XMyMTEsAOyaEqxEJKU2czSa9T2h1xOFAAXAvW roWnhLghiljlOC1kiP2MNFiqWt5sWGayFaqrmkRj075PSRnP5EHHmiDPO94JF0SAL1RY CgQrr8RDZm4VuMMAtkuDYOQO4fRCijI4yKOgdbUzpEotpBf0JfSXQTwnSKipfqyTgohj 13X3BLPmb3ChmhOEeRm8vEEFuXreFuMAW1SrdTHxrlIfsWNIyJaXNA6umDTE34M7ya4x fpd6l/YDw/F+n0ITywtCiZMpRQdUlQ/7r66EPTX+N8GdMLsaZefJwJirFR7224Pqebgi EYOg== X-Gm-Message-State: AOAM533orr4PjDloG9cIVsBYvcKl6cV6F9vUA9YMJPuJrYKj5qE/I/gl b9KkfxR6+/Q6Ka0LUeeT/OQ= X-Google-Smtp-Source: ABdhPJyI2CGVBw+yoGGPeeq2F338VAm8dTNAgH2Rp77EGChXVrzx4AfEj/iTJrw9Uv3K00xIkYVeMA== X-Received: by 2002:a19:ef02:: with SMTP id n2mr14976923lfh.141.1615242666898; Mon, 08 Mar 2021 14:31:06 -0800 (PST) Received: from localhost.localdomain ([94.103.235.167]) by smtp.gmail.com with ESMTPSA id p13sm1653426ljg.116.2021.03.08.14.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 14:31:06 -0800 (PST) From: Pavel Skripkin To: perex@perex.cz, tiwai@suse.com, kai.heng.feng@canonical.com Subject: [PATCH next 2/2] sound: usb: fix use after free in usb_audio_disconnect Date: Tue, 9 Mar 2021 01:30:57 +0300 Message-Id: <16da19126ff461e5e64a9aec648cce28fb8ed73e.1615242183.git.paskripkin@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 09 Mar 2021 08:02:00 +0100 Cc: Pavel Skripkin , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org 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" The problem was in wrong "if" placement. chip->quirk_type is freed in snd_card_free_when_closed(), but inside if statement it's accesed. Fixes: 9799110825db ("ALSA: usb-audio: Disable USB autosuspend properly in setup_disable_autosuspend()" Signed-off-by: Pavel Skripkin --- sound/usb/card.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sound/usb/card.c b/sound/usb/card.c index 3fd1743513b5..b6f4c0848e66 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -907,6 +907,9 @@ static void usb_audio_disconnect(struct usb_interface *intf) } } + if (chip->quirk_type & QUIRK_SETUP_DISABLE_AUTOSUSPEND) + usb_enable_autosuspend(interface_to_usbdev(intf)); + chip->num_interfaces--; if (chip->num_interfaces <= 0) { usb_chip[chip->index] = NULL; @@ -915,9 +918,6 @@ static void usb_audio_disconnect(struct usb_interface *intf) } else { mutex_unlock(®ister_mutex); } - - if (chip->quirk_type & QUIRK_SETUP_DISABLE_AUTOSUSPEND) - usb_enable_autosuspend(interface_to_usbdev(intf)); } /* lock the shutdown (disconnect) task and autoresume */