Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3714828pxb; Mon, 24 Jan 2022 16:08:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4VyZ45nX179/yhz/fKZqt1jh9yc3eHfrxx5SU2RJthkEL8j+UlwPO3M4qPIfQrZDILeNI X-Received: by 2002:aa7:84cf:0:b0:4c8:7234:e6ca with SMTP id x15-20020aa784cf000000b004c87234e6camr9420284pfn.35.1643069301174; Mon, 24 Jan 2022 16:08:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069301; cv=none; d=google.com; s=arc-20160816; b=SMNxSN6f/b3v7wAL4vT+qJ9IAh8cAz9SubajRVmSNp0ZVlH38vubeI020nqwPpRLQS qoQYfpyYFoFUp9X0DOndfRTfg2NvbRT3NVwR8/JM5dzal6HcknzX3/RlBwMpHr/ppW9Q TG2iPj/ZgGKIKsRNsxl6u6yHNvZPPAoYSD3I6FwYTaIer71E2qLz3yXPd20F3PKQuaSp lChBLpYfJ0aN6kYm3mFCeZE/VvWbfvDtfN96e+AYIJVVPbbaE7zJaMGOu002kk0CGiSb K+g3y5zT8QKh5EU2TqC0RnmgEBROq5AKw+BVUSXqcrnZYGvz8/6xUHDrYJ8yQjeFfJi7 wpHw== 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=TpFkgZs/pnOPqKRtF4h4/0HvMjbLzE1QoMAvqbv9xZA=; b=wx1xU+v+sfXVyW6X5DNFAzU58rmY21Vk/YmygeXtcWAZEjqPHVXmK5YWXmn9rfqHoO Gil81gZN12fYXUXyDkk9bBryIMAvASCMQfjQmXHXdmspxWp29q+wjbMZHEGIf3ylW4DA r2MbSTroePQkpC8UA540uwMfrxjtyfvFSYQKYX18EknfJhBw5AAlu7ugCzVdQbaIWvX3 8J994Cu5Ys1WpOAz0KbC6wCC30tIYTxwDop3ALltUZtCGzr4l+c4BiBN5+uXVVYpUtNm drW0RBikW2znHQylIEfxLNvsbdyLWGWhjKZYk7uAh9JLjz+js02xHTEQrgmYvv+rYFsu purg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aAQw4PKp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y16si14576334pfl.75.2022.01.24.16.08.08; Mon, 24 Jan 2022 16:08:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aAQw4PKp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2369057AbiAYAAv (ORCPT + 99 others); Mon, 24 Jan 2022 19:00:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1847056AbiAXXSY (ORCPT ); Mon, 24 Jan 2022 18:18:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 291DEC06F8E3; Mon, 24 Jan 2022 13:27:00 -0800 (PST) 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 BA542614D8; Mon, 24 Jan 2022 21:26:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D0A0C340E4; Mon, 24 Jan 2022 21:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059619; bh=XOsj6tMeo3byH1VXmZp4CqHcytz5W+S7VP6NCTNikdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aAQw4PKpaRo9L1HWXQ4bAQh8Y9gCzbaelRDt8oAwWfEeTWJmE1gZI8OrJq1/CYYSf 8fFy+CxyF/wFWhXrWXXdGe644EqAb/FzJc68jtB3/qZ9HriWZIMcS5sfz60aPgq84l SiC4zTxpxHiovLPveo/MJan+p0HT/0lZur9L98/I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , Kalle Valo , Sasha Levin Subject: [PATCH 5.16 0676/1039] ath9k_htc: fix NULL pointer dereference at ath9k_htc_tx_get_packet() Date: Mon, 24 Jan 2022 19:41:05 +0100 Message-Id: <20220124184148.088458097@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tetsuo Handa [ Upstream commit 8b3046abc99eefe11438090bcc4ec3a3994b55d0 ] syzbot is reporting lockdep warning at ath9k_wmi_event_tasklet() followed by kernel panic at get_htc_epid_queue() from ath9k_htc_tx_get_packet() from ath9k_htc_txstatus() [1], for ath9k_wmi_event_tasklet(WMI_TXSTATUS_EVENTID) depends on spin_lock_init() from ath9k_init_priv() being already completed. Since ath9k_wmi_event_tasklet() is set by ath9k_init_wmi() from ath9k_htc_probe_device(), it is possible that ath9k_wmi_event_tasklet() is called via tasklet interrupt before spin_lock_init() from ath9k_init_priv() from ath9k_init_device() from ath9k_htc_probe_device() is called. Let's hold ath9k_wmi_event_tasklet(WMI_TXSTATUS_EVENTID) no-op until ath9k_tx_init() completes. Link: https://syzkaller.appspot.com/bug?extid=31d54c60c5b254d6f75b [1] Reported-by: syzbot Signed-off-by: Tetsuo Handa Tested-by: syzbot Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/77b76ac8-2bee-6444-d26c-8c30858b8daa@i-love.sakura.ne.jp Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath9k/htc.h | 1 + drivers/net/wireless/ath/ath9k/htc_drv_txrx.c | 5 +++++ drivers/net/wireless/ath/ath9k/wmi.c | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h index 4f71e962279af..6b45e63fae4ba 100644 --- a/drivers/net/wireless/ath/ath9k/htc.h +++ b/drivers/net/wireless/ath/ath9k/htc.h @@ -306,6 +306,7 @@ struct ath9k_htc_tx { DECLARE_BITMAP(tx_slot, MAX_TX_BUF_NUM); struct timer_list cleanup_timer; spinlock_t tx_lock; + bool initialized; }; struct ath9k_htc_tx_ctl { diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c index e7a21eaf3a68d..6a850a0bfa8ad 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c @@ -813,6 +813,11 @@ int ath9k_tx_init(struct ath9k_htc_priv *priv) skb_queue_head_init(&priv->tx.data_vi_queue); skb_queue_head_init(&priv->tx.data_vo_queue); skb_queue_head_init(&priv->tx.tx_failed); + + /* Allow ath9k_wmi_event_tasklet(WMI_TXSTATUS_EVENTID) to operate. */ + smp_wmb(); + priv->tx.initialized = true; + return 0; } diff --git a/drivers/net/wireless/ath/ath9k/wmi.c b/drivers/net/wireless/ath/ath9k/wmi.c index fe29ad4b9023c..f315c54bd3ac0 100644 --- a/drivers/net/wireless/ath/ath9k/wmi.c +++ b/drivers/net/wireless/ath/ath9k/wmi.c @@ -169,6 +169,10 @@ void ath9k_wmi_event_tasklet(struct tasklet_struct *t) &wmi->drv_priv->fatal_work); break; case WMI_TXSTATUS_EVENTID: + /* Check if ath9k_tx_init() completed. */ + if (!data_race(priv->tx.initialized)) + break; + spin_lock_bh(&priv->tx.tx_lock); if (priv->tx.flags & ATH9K_HTC_OP_TX_DRAIN) { spin_unlock_bh(&priv->tx.tx_lock); -- 2.34.1