Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3654466pxb; Mon, 24 Jan 2022 14:32:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1O+ySMQRtzDxSSeZKpY6vDUB/eMuumwE9DuKEHdObZLVfDPT3flV92EJd1+KNuvY0Apib X-Received: by 2002:a62:cd89:0:b0:4c9:b1f4:e68e with SMTP id o131-20020a62cd89000000b004c9b1f4e68emr5185048pfg.8.1643063471721; Mon, 24 Jan 2022 14:31:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063471; cv=none; d=google.com; s=arc-20160816; b=ClaIu4PPnPGOaFhvpPakwDBvc+k+Xt1XWKeGtUW2h/hrltmZCILYu8cXH9fNvsfXBV 9xMTyfJxWYT5Fz9hWZq7D4vhaPFSP1LEhO3Eo15lENkpqsyM9qKSxHldtH6Q2CIdPorW JSrxWG+BTcGPvbgA27qe7dwD5eF0osXUSZx2sCMrFlDmZHdagRDv0DWhSL56czKw4EYI UWYUeLUPDzE+jnLc79URyt8qQzZNlAfpp2f56tapvacoYcG84Da01bd/y7wGbzuiB9th QgXjMzwX2wcgZjMlMFPoCDt36ZFpkdS3oQ9MdtL6wNXulME9SlTKfH2wKP+TeD6Ui146 FopQ== 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=bJVSluyJVD2s2DxwgDrw1VDNc0dsMkGzcUqL/HtYciA=; b=Fo9G9Ai8VXvRO5sBcR2T57q/6sokmDN+V/sO/zMJ8a9po0qJp7J4cymaXOioROmNCH 0DNG7CiVKhXp9Mtg7+zyj1ZoZku1Ii169CO0mjideqyMq+vpnJ7qRony+83f+GpZTJsc OUSjl7rFb4IRium77IpOvAYXTf2nbnFzoJXFva6wxxIs6PohayBJ6Y70S0MTKP+bplGC a6dO0KV88WvpUqfrUelpcjUcgWJn5k1XDoJBOHwW5tR4gRhDiRA05LHPw538HufMTuu1 OH6YcuF4k3AaYwt7EYZ4stXy/Rhyr0Rz3OqUXyzQ4s22oyiFJgIFBeOjuA+Mdb3zy7Kb muEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YlN9bp9o; 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 z6si13140927pfb.209.2022.01.24.14.30.59; Mon, 24 Jan 2022 14:31:11 -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=YlN9bp9o; 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 S1586396AbiAXW0W (ORCPT + 99 others); Mon, 24 Jan 2022 17:26:22 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:41100 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359700AbiAXV07 (ORCPT ); Mon, 24 Jan 2022 16:26:59 -0500 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 7F024B811A2; Mon, 24 Jan 2022 21:26:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B74DFC340E4; Mon, 24 Jan 2022 21:26:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059616; bh=0NPR2GEkXmlKshR2DCdw5F1yXLjr3XEZ5JAnE8LMcEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YlN9bp9oMRbjuGrcQktLgo20UfiOkYFRw0fqE8ITFyF+EaG4/8W2xIu7s5H4LdtKm mPCW/6NP1pmzF5fmoOOt0dtuuFR+Qm2sVZKUFsZpaAelv9InkIH2rxfpZPyRy9El+m aimCXK+ZweAMvKqnGkgEYYIfRiqhBymCLtX2IkUw= 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 0675/1039] ath9k_htc: fix NULL pointer dereference at ath9k_htc_rxep() Date: Mon, 24 Jan 2022 19:41:04 +0100 Message-Id: <20220124184148.057636054@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 b0ec7e55fce65f125bd1d7f02e2dc4de62abee34 ] syzbot is reporting lockdep warning followed by kernel panic at ath9k_htc_rxep() [1], for ath9k_htc_rxep() depends on ath9k_rx_init() being already completed. Since ath9k_htc_rxep() is set by ath9k_htc_connect_svc(WMI_BEACON_SVC) from ath9k_init_htc_services(), it is possible that ath9k_htc_rxep() is called via timer interrupt before ath9k_rx_init() from ath9k_init_device() is called. Since we can't call ath9k_init_device() before ath9k_init_htc_services(), let's hold ath9k_htc_rxep() no-op until ath9k_rx_init() completes. Link: https://syzkaller.appspot.com/bug?extid=4d2d56175b934b9a7bf9 [1] Reported-by: syzbot Signed-off-by: Tetsuo Handa Tested-by: syzbot Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/2b88f416-b2cb-7a18-d688-951e6dc3fe92@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 | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h index 0a1634238e673..4f71e962279af 100644 --- a/drivers/net/wireless/ath/ath9k/htc.h +++ b/drivers/net/wireless/ath/ath9k/htc.h @@ -281,6 +281,7 @@ struct ath9k_htc_rxbuf { struct ath9k_htc_rx { struct list_head rxbuf; spinlock_t rxbuflock; + bool initialized; }; #define ATH9K_HTC_TX_CLEANUP_INTERVAL 50 /* ms */ diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c index 8e69e8989f6d3..e7a21eaf3a68d 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c @@ -1130,6 +1130,10 @@ void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb, struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL; unsigned long flags; + /* Check if ath9k_rx_init() completed. */ + if (!data_race(priv->rx.initialized)) + goto err; + spin_lock_irqsave(&priv->rx.rxbuflock, flags); list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) { if (!tmp_buf->in_process) { @@ -1185,6 +1189,10 @@ int ath9k_rx_init(struct ath9k_htc_priv *priv) list_add_tail(&rxbuf->list, &priv->rx.rxbuf); } + /* Allow ath9k_htc_rxep() to operate. */ + smp_wmb(); + priv->rx.initialized = true; + return 0; err: -- 2.34.1