Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6264852rwb; Tue, 9 Aug 2022 12:02:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR4HslDqpMe/j3xf4owhZOcAySyYKDyNCZtfJGPzvxshM83X7H9ENjqz+iTIqCgdtT5OyFql X-Received: by 2002:a63:2dc6:0:b0:419:f2d0:4777 with SMTP id t189-20020a632dc6000000b00419f2d04777mr20208986pgt.203.1660071771072; Tue, 09 Aug 2022 12:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660071771; cv=none; d=google.com; s=arc-20160816; b=jLsl+EmkKXFuhbVnhcbVUiFQzDWxBB8rv6VvMN75HpAIY+OrC+y9DN2JJXFqEVOqpb MIzFyhvDkKbhpISCvlHiozQKlDc5shK/oETM4D7fVVKcIOcf4LayHZGe+a1lnOoqcfRN rZ0gptBJYP4K+5seR/rQqAy30CFsIxp6rwd15EImbMvCz03ZrarKRqynE6TUjWi2p5e4 5EmffLy1RgHHeO1R8Bx8a6MLnHeYZdPim3SIXbEjMYJWZt6+VihcCEcRWaQnsvhFw0wL d4XSCKbLC3MvWffq6zcQC1sC4tfMp9J1s3fnfUG6lJ0zXnkJmxOIpPjE2mf7Gd2TcO0V Hw6Q== 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=vRiL3QKeWsWNGEI30x0/hDYSm7hWz87omACs5Ad8uyE=; b=BoJQDmLM3Nd4LZiobGYVuqMx1FTzwCpnO1wKTj5rLWHsDY/63OfE+gflhPodISG+qu QLlyNUf3BMone8uheBK5vw0sOTlHgMBFqz7S13y4vpPMhQyMzHncRaOUBGKhAaLLg6nu cNBX2CfkdqDN5Q5GR23z/BOWQzok4u87kdYG/BHr4+Mr5/JG+qrpIGVYkER5FurrFTND xnJN7M8jQ8+d/a+0Dy4YKBlYpDV7k8eRZr2JkzxSb7R+2sODpELhOKGOZ2k0hvVCiOYh aWExDsWXPlFYgKV+TWKFE4/zHizK3Xn7zYr3iI+r9AfwtpxICo2Bu5bNfb7X9N3VVbR0 1tlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OU5rZvbV; 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 q18-20020a170902eb9200b0016bea769903si693462plg.134.2022.08.09.12.02.29; Tue, 09 Aug 2022 12:02:51 -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=OU5rZvbV; 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 S1345109AbiHISJp (ORCPT + 99 others); Tue, 9 Aug 2022 14:09:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345098AbiHISJO (ORCPT ); Tue, 9 Aug 2022 14:09:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE8EB29C84; Tue, 9 Aug 2022 11:03:48 -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 DD1BFB816A0; Tue, 9 Aug 2022 18:03:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E6E2C433C1; Tue, 9 Aug 2022 18:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660068225; bh=6Iq+Z0pM/bwhCLt1zkLUMRSwsXngpQToOfQLO9hCOX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OU5rZvbVZNrZNMEdDEP4gGaWoXOJOXBtbFZA23Z0nfnWWa8ytuBBopJUsgTruC+4w EVvlNovBPvWVWupsnxBaUyz97O11bkk/yBp6cpPdfgSXi01IdmFHI9Y2jNlXBJznHc Y9VSQ7Oaa3mMueGhjAlp5bXmpKXSO9MF76vLst4E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , Kalle Valo , Fedor Pchelkin Subject: [PATCH 5.10 02/23] ath9k_htc: fix NULL pointer dereference at ath9k_htc_rxep() Date: Tue, 9 Aug 2022 20:00:20 +0200 Message-Id: <20220809175512.952214630@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809175512.853274191@linuxfoundation.org> References: <20220809175512.853274191@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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: Tetsuo Handa commit b0ec7e55fce65f125bd1d7f02e2dc4de62abee34 upstream. 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: Fedor Pchelkin Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireless/ath/ath9k/htc.h | 1 + drivers/net/wireless/ath/ath9k/htc_drv_txrx.c | 8 ++++++++ 2 files changed, 9 insertions(+) --- 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 */ --- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c @@ -1133,6 +1133,10 @@ void ath9k_htc_rxep(void *drv_priv, stru 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) { @@ -1188,6 +1192,10 @@ int ath9k_rx_init(struct ath9k_htc_priv list_add_tail(&rxbuf->list, &priv->rx.rxbuf); } + /* Allow ath9k_htc_rxep() to operate. */ + smp_wmb(); + priv->rx.initialized = true; + return 0; err: