Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3508766rwa; Tue, 23 Aug 2022 06:02:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR6X9hbiwYG4O+a0Xhx+CqLMq9KbAnxwrhc4UHDtonsy2wOxLeriW1irvtSC6xmCZkihxkzt X-Received: by 2002:a63:1c1c:0:b0:41e:27a7:a6aa with SMTP id c28-20020a631c1c000000b0041e27a7a6aamr20814555pgc.454.1661259765009; Tue, 23 Aug 2022 06:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661259765; cv=none; d=google.com; s=arc-20160816; b=KtYQMtZ1ekNJYOW24sVPFpa+CkSwgrfBHpOXwKwtocZSikIu0H9NmuvvS1l9rw86A7 zyiGQF7K6Tb5dzlc2lHIOYvzcl3DRB4DVODSZDzGdl2NZ+n203XTJITh16JK7PZobkYx LfRKaj3t0hz5LH5r7tjW7bHtpbqQ5aCwpihpJvECaN/TnHMFMFvYrEOOumJedlJGU/is seO+Kl57LoyVH5WWbdEGzkXdxH2T47X34imyOAwIakvpGaYheUnSMYEhYHngMEtFXTTd JNXOt2F1cH6NefHJVyZqgY0eWLZ7SB23TemwMyEPfkkYGoDjdVB8+sz920R+/FQFT2gM T0Pg== 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=bsYUsj103lIU2wl4sKmOUi1NNwGc700ulZyqqUTGgnE=; b=EYhgErsQYCwgUCLxQPc0RSFYSu7JH7gPlo97JlWIGNikbVpFG8ORTIqTMFFgrbqgNA wP7Cx0QK772FbC4ud/FOSECge9hI7/iiC0FeqPolYcbHMu0Pay+xAMgkwfl6VhsHmGiu eQkX5kI366cOe3vP/Y6BJuRUgjfzlG2TQhBnyYYvFLCaDBXDwO0mGvNw+U98a88+jc7r XxKy/4GPzwp2ixgfjv/VesXaIrPbIiaYq99hBLq43bgY9F/3W+EJsE48DdJiNrKxYgqL JZTSvli5DZ3Zdo/WEPLMX9QY0siHZLRVQX6qEgxyXlsTSBZTa4InCcKPgeQjZO2ii2Kw qNRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nq3rtFrS; 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 h15-20020a170902f70f00b00172b87d9775si14495848plo.383.2022.08.23.06.02.28; Tue, 23 Aug 2022 06:02:44 -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=nq3rtFrS; 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 S241442AbiHWLYi (ORCPT + 99 others); Tue, 23 Aug 2022 07:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245064AbiHWLRu (ORCPT ); Tue, 23 Aug 2022 07:17:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98AC789903; Tue, 23 Aug 2022 02:21:56 -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 ams.source.kernel.org (Postfix) with ESMTPS id 00367B8105C; Tue, 23 Aug 2022 09:21:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FB26C433D7; Tue, 23 Aug 2022 09:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246513; bh=u4qBAarg499hHG2LmgoACjWFaqNeBe7D8r/nF0mIBLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nq3rtFrS/Kki4EbJ/FKEVBExnnw9hHUzx3anrhf44V4rT/PpTN0pFpwUDMyMbdf7I 9NlvSEbxGxeO+GiVc7JR2Sok70h3zvP6Ek+mJEVc1ObE8lCZ7feoUG0DtDqQ9riJmB HSl5UNiA/4w1JDNtLC+N67eKfgUivuQHkpYnXucA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Kalle Valo , Sasha Levin , syzbot+03110230a11411024147@syzkaller.appspotmail.com, syzbot+c6dde1f690b60e0b9fbe@syzkaller.appspotmail.com Subject: [PATCH 5.4 103/389] ath9k: fix use-after-free in ath9k_hif_usb_rx_cb Date: Tue, 23 Aug 2022 10:23:01 +0200 Message-Id: <20220823080119.923450554@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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,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 From: Pavel Skripkin [ Upstream commit 0ac4827f78c7ffe8eef074bc010e7e34bc22f533 ] Syzbot reported use-after-free Read in ath9k_hif_usb_rx_cb() [0]. The problem was in incorrect htc_handle->drv_priv initialization. Probable call trace which can trigger use-after-free: ath9k_htc_probe_device() /* htc_handle->drv_priv = priv; */ ath9k_htc_wait_for_target() <--- Failed ieee80211_free_hw() <--- priv pointer is freed ... ath9k_hif_usb_rx_cb() ath9k_hif_usb_rx_stream() RX_STAT_INC() <--- htc_handle->drv_priv access In order to not add fancy protection for drv_priv we can move htc_handle->drv_priv initialization at the end of the ath9k_htc_probe_device() and add helper macro to make all *_STAT_* macros NULL safe, since syzbot has reported related NULL deref in that macros [1] Link: https://syzkaller.appspot.com/bug?id=6ead44e37afb6866ac0c7dd121b4ce07cb665f60 [0] Link: https://syzkaller.appspot.com/bug?id=b8101ffcec107c0567a0cd8acbbacec91e9ee8de [1] Fixes: fb9987d0f748 ("ath9k_htc: Support for AR9271 chipset.") Reported-and-tested-by: syzbot+03110230a11411024147@syzkaller.appspotmail.com Reported-and-tested-by: syzbot+c6dde1f690b60e0b9fbe@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin Acked-by: Toke Høiland-Jørgensen Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/d57bbedc857950659bfacac0ab48790c1eda00c8.1655145743.git.paskripkin@gmail.com Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath9k/htc.h | 10 +++++----- drivers/net/wireless/ath/ath9k/htc_drv_init.c | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h index 9f64e32381f9..81107100e368 100644 --- a/drivers/net/wireless/ath/ath9k/htc.h +++ b/drivers/net/wireless/ath/ath9k/htc.h @@ -325,11 +325,11 @@ static inline struct ath9k_htc_tx_ctl *HTC_SKB_CB(struct sk_buff *skb) } #ifdef CONFIG_ATH9K_HTC_DEBUGFS - -#define TX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.tx_stats.c++) -#define TX_STAT_ADD(c, a) (hif_dev->htc_handle->drv_priv->debug.tx_stats.c += a) -#define RX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.skbrx_stats.c++) -#define RX_STAT_ADD(c, a) (hif_dev->htc_handle->drv_priv->debug.skbrx_stats.c += a) +#define __STAT_SAFE(expr) (hif_dev->htc_handle->drv_priv ? (expr) : 0) +#define TX_STAT_INC(c) __STAT_SAFE(hif_dev->htc_handle->drv_priv->debug.tx_stats.c++) +#define TX_STAT_ADD(c, a) __STAT_SAFE(hif_dev->htc_handle->drv_priv->debug.tx_stats.c += a) +#define RX_STAT_INC(c) __STAT_SAFE(hif_dev->htc_handle->drv_priv->debug.skbrx_stats.c++) +#define RX_STAT_ADD(c, a) __STAT_SAFE(hif_dev->htc_handle->drv_priv->debug.skbrx_stats.c += a) #define CAB_STAT_INC priv->debug.tx_stats.cab_queued++ #define TX_QSTAT_INC(q) (priv->debug.tx_stats.queue_stats[q]++) diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_init.c b/drivers/net/wireless/ath/ath9k/htc_drv_init.c index 11054c17a9b5..eaaafa64a3ee 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c @@ -944,7 +944,6 @@ int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev, priv->hw = hw; priv->htc = htc_handle; priv->dev = dev; - htc_handle->drv_priv = priv; SET_IEEE80211_DEV(hw, priv->dev); ret = ath9k_htc_wait_for_target(priv); @@ -965,6 +964,8 @@ int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev, if (ret) goto err_init; + htc_handle->drv_priv = priv; + return 0; err_init: -- 2.35.1