Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1473647rwb; Fri, 19 Aug 2022 04:28:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR6W9YUUZgXwsZbC3UGa20n77W/QzG97g3rrvm8h/vToLyKLfc2RIrsB/EF3FBUdETx5OWzq X-Received: by 2002:a17:906:8441:b0:730:7bd1:17ca with SMTP id e1-20020a170906844100b007307bd117camr4669006ejy.229.1660908537978; Fri, 19 Aug 2022 04:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660908537; cv=none; d=google.com; s=arc-20160816; b=XNskoQyZZP5//0STIIR8Gt3ACbvAAy98BNZBh4CmpXWTil1//atqSV5G/CrdB13rdB 1+t6HtylAo9rrNaO9lfENmiZ4lwTHmogQVR378lyCzX/wyq2uYu+aZLCrzE81iC5j5O4 DPt6p53OLmGuSuK8w2qDEwCRQeNNpOtQsP/a1dxpWfKnxJkJQl5j+9pd9USY6I2PlJZ4 0WAzacIXkgRxTrdwh0iIZtRLv8BKogk/Sp19bkczK7BqcLzFLXi2BtoMjmazW5FG5kCA OwTvvKkNxCd16p4aC4VYzsl0g+ATztOmu5gxOs6D6ciT4bJXP0FGVRwm7M+s0h6uq4mB wvXg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WMvSFQrNg9jy7ZPJXBanJPEWB3O315IcGwsFcXi5PVM=; b=IVsi85uGo1s91uJm2rHFM5RdE6HxkXtTCW3vwvemHkyziuscbxxBRN9TJk55bMu25L BaR8NQ4/yXXzOzLxfMEzA3+NNcxfPBKESw/drD3aj9hoDJMWEb/pMPenKL3V++nzVVsN H//WROVZoDMB69ObfvrQ2JOI1c4EgDvhKJ/hQOlM44BhvuXJzXsSlBoS22lJ8iJJHJs1 DZJp519MmPfKLENh4pyJhljicoLBCRnwsASZGIbzWvqlH3dv0QqUuM1kpFKuNty9Fcjt m/6jDhvI6dU/ULgtO7+Kwmtpe/xaLw9frpoB7puqQ3dL5wzhEQAzfAlOQnKBKbceaX8M ws8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@windriver.com header.s=PPS06212021 header.b=PvZaiFDJ; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=windriver.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z6-20020a17090665c600b007316171a72fsi2486807ejn.840.2022.08.19.04.28.41; Fri, 19 Aug 2022 04:28:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=@windriver.com header.s=PPS06212021 header.b=PvZaiFDJ; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=windriver.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348816AbiHSLYs (ORCPT + 63 others); Fri, 19 Aug 2022 07:24:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348802AbiHSLYr (ORCPT ); Fri, 19 Aug 2022 07:24:47 -0400 Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43E34D8B0B; Fri, 19 Aug 2022 04:24:46 -0700 (PDT) Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27JBMD5E016045; Fri, 19 Aug 2022 11:22:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=PPS06212021; bh=WMvSFQrNg9jy7ZPJXBanJPEWB3O315IcGwsFcXi5PVM=; b=PvZaiFDJeME4TT23PNN9/0N4DVGZdpmYda67WOh9sRijZS7hwhFpU731FvQMiudCq9Dt J9kkgi1clonruxhNojsp2baLHzNbDy7rjUZZvK86aIf4mvja+qcVID3JqiOwxLoMyKOC c50CbL7UKhY7bQdfBhz7KJ5M4RNcpzv/RYxONiS52NUc7Ik6Ey9b39wYXraFxDPYYKG9 IOf9kZshIKPg/BOGGrSvXQJ9jAhn5VHTxoVSMiBaqgpIKwMRTD2jNQZqwcOhCPsGx8bh CRUPWdrIUIUDu5AJYONXhRPviIiWN7dIfrcZ1Gxjm5F4LCYDlgc7Hb22nTbv4vLUFMcQ ng== Received: from ala-exchng01.corp.ad.wrs.com (unknown-82-252.windriver.com [147.11.82.252]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 3hx2x8n9bq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 19 Aug 2022 11:22:13 +0000 Received: from otp-dpanait-l2.corp.ad.wrs.com (128.224.125.191) by ala-exchng01.corp.ad.wrs.com (147.11.82.252) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Fri, 19 Aug 2022 04:22:09 -0700 From: Dragos-Marian Panait To: CC: Pavel Skripkin , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Kalle Valo , Kalle Valo , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vasanthakumar Thiagarajan , Sujith , Senthil Balasubramanian , "John W . Linville" , , , Subject: [PATCH 4.19 1/1] ath9k: fix use-after-free in ath9k_hif_usb_rx_cb Date: Fri, 19 Aug 2022 14:21:56 +0300 Message-ID: <20220819112156.922376-2-dragos.panait@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220819112156.922376-1-dragos.panait@windriver.com> References: <20220819112156.922376-1-dragos.panait@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [128.224.125.191] X-ClientProxiedBy: ala-exchng01.corp.ad.wrs.com (147.11.82.252) To ala-exchng01.corp.ad.wrs.com (147.11.82.252) X-Proofpoint-ORIG-GUID: of5Jb9G9edqog7KXz1agItmQY9O-C_Vd X-Proofpoint-GUID: of5Jb9G9edqog7KXz1agItmQY9O-C_Vd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-19_06,2022-08-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 malwarescore=0 bulkscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=977 adultscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208190044 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,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-wireless@vger.kernel.org From: Pavel Skripkin commit 0ac4827f78c7ffe8eef074bc010e7e34bc22f533 upstream. 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: Dragos-Marian Panait --- 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 cb136d9d4621..49d587330990 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c @@ -946,7 +946,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); @@ -967,6 +966,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.37.1