Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2929643rwb; Mon, 15 Aug 2022 14:15:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR7oWtOqRwUDOUczOwSfJxxPzxYiNiiH9LKFSkp3yNAXeBzDoD780aL0QI8I5Qi7b2Q9swXu X-Received: by 2002:a17:907:3ea5:b0:730:8b95:dc69 with SMTP id hs37-20020a1709073ea500b007308b95dc69mr11549593ejc.34.1660598123787; Mon, 15 Aug 2022 14:15:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660598123; cv=none; d=google.com; s=arc-20160816; b=xz3mAcpQ7YfPkDVehhTqt7gQIvBr8heocw9ACDtmS0WqTU7C9Lj2fsChVGgJOg4ivk W6GN5xTDD3/ZDhs4jMnVXJiXbQBbPStNqY5TPUUjOXZwKtNLk81PN1AbW1ceVwRtfbmf hMNGa6ExkzvsRNdZxj1ba5iBQ4ILqs4Xqj2trjSzMA6ABG36ck72FFh0k8PThMPtMjdV ZzVotRyAMh3TUo77z0tcGquNhJvzTjerZRiqiNPZiV5B1sko1tsxSXp6/ZeLOZqBZ/KZ Hi1QOg2FBIninKDsWXsC3zYtC2nSVtHzxYk7blB/rAYSYpBXVB/Zti6HprIMPfEub/rw C+GA== 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=KLr09KlZuDA1vewWepwHyN8XPp/RorBawvLcPjQ+Iv4=; b=lzrm4REma3bk05uJ6y1B+89j3ADBl2O5MKdrq/op7yxp2o/S3XkEOjQKI2ycaDZgim OB7AN33YIbwaE2NdCqU0kiOdaQ8MF4OuxKX0E+Ny/UmsLlfBE2O4F8n5uhmE+26ducSa D4k5zJn2jb/BTN7Xy+ALj91hJhhLER8gJGLXW2RKGMgidaiTvMBpSBoSGjYDSuWEH4Oj on/jIZcEUbz9TMjew86oUbOvNdX1idjgN52ZGuL+JdUPRGe1ztjizAQ6Ev4MtLItx8br mhvOMDpVi9mN8+ygyfe/cGa68xQqN/+Zied0w234L+wfc4Gqh8pMGLCTvgtlfulcVHA+ N2pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T21ynF5g; 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 h19-20020a056402281300b0043def0e25c9si9951649ede.20.2022.08.15.14.14.57; Mon, 15 Aug 2022 14:15:23 -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=T21ynF5g; 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 S241292AbiHOVJT (ORCPT + 99 others); Mon, 15 Aug 2022 17:09:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344841AbiHOVDy (ORCPT ); Mon, 15 Aug 2022 17:03:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AF71D3EE1; Mon, 15 Aug 2022 12:14:47 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B267F60F68; Mon, 15 Aug 2022 19:14:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1E12C4314B; Mon, 15 Aug 2022 19:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590886; bh=BokTBTMkZ4346PaQMeY33bF5LXXEd68/+dwp0v89MXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T21ynF5gE8yks6j6TP1DHXg/TgHh/iL+EE/+Ou2dxhJ2Zi7t55HlHtKQF9kPY56a4 ukhrsO7aA8FGc7rayMzqUGoOh2lLY/dwwrq5ynmhm9UcEXkvzHLz7yEk4L663mYD+r 4zgzC0ivNPsCDXyCvtcv/fZj+SIGFNrvfdz6QMCE= 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.18 0361/1095] ath9k: fix use-after-free in ath9k_hif_usb_rx_cb Date: Mon, 15 Aug 2022 19:56:00 +0200 Message-Id: <20220815180444.675958576@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 6b45e63fae4b..e3d546ef71dd 100644 --- a/drivers/net/wireless/ath/ath9k/htc.h +++ b/drivers/net/wireless/ath/ath9k/htc.h @@ -327,11 +327,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 ff61ae34ecdf..07ac88fb1c57 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