Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1130669rdf; Sat, 4 Nov 2023 07:35:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEO5ZT1S76E2gEnm3ojBlowhrJIfgnW4O+OJGyD0igSWOXV/lImxhrhuNSbBEsRFJ3mBDS X-Received: by 2002:a05:6a00:14d6:b0:6be:4e6e:2a85 with SMTP id w22-20020a056a0014d600b006be4e6e2a85mr32473774pfu.30.1699108511376; Sat, 04 Nov 2023 07:35:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699108511; cv=none; d=google.com; s=arc-20160816; b=XdOu8lYpJkEtyThVeFYk6kqaEXAYAslso2cdfoiNn4BO3GO/355KtSNJ/VYT/AZV0o neIdkf8q8larP/DXSWd+iq1jbwYQxSZnEK2tdAfM7dyHhk7x7Qd725RTTGlznFfgpyL/ CuwgF+5SuWpA0EiP8sceO9sZUY0R+NIaenjJNY3ZLlOBtWBLh5WgmQ3/hZ93oWUntcdF 4ZWa4oTNYQjIvspdW5zSNXcxjjjbkntFd/xtGINhTFohNXQYPZ5Rer8PdhCbGE/a9L7h 5c2OVeT/mW+eqO8P9T0sNRFWHJRuqED74f8nhwGCqzOnn6xyukwCiWI3OI+j3G+V/HhG cV+g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=3O/ACUjY9iRPgXuqmvo563uZpZP1cuuJTllLXw0vPQQ=; fh=Tn6y7+OCh8fxSFSicSZYxaqjR/wrDs1aDTQgTx7ywJ4=; b=XY1azQCQFOaqGRYMOh4+jvZiyG/QdlcZy35q/skTSwiTIKF4d1YF6IcCzhhVUDnRHc CmraAmtnCsg0p96XuUI5GtX5hL9mKhMC4tNHxAFP1lgVYO6rTAVhilAZnsZq/2cqy5ew ZO5EEyK8R7+qnwpYKxodxl44oHUTMR4pRb6hxDB2uDUly/sJoe7coQpzL0MgXpqrVpxi Ry+XSXFRbq+QQjKbnAENY5LC+TrljGCBRFYv8JCXyj/ArQRaWU7SSK6gL2KED9DTGHqC TLJmtMCaP5FAJVII6aF4PfW5feRU273Wn3fi1dtK3kBZDvHgdaTJXL3knvyBAtvGr6jO rwSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=cxKgrAKG; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s6-20020a056a00178600b006bddca27b44si3917776pfg.233.2023.11.04.07.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 07:35:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=cxKgrAKG; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5E71480417FB; Sat, 4 Nov 2023 07:35:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232182AbjKDOfG (ORCPT + 54 others); Sat, 4 Nov 2023 10:35:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbjKDOfF (ORCPT ); Sat, 4 Nov 2023 10:35:05 -0400 Received: from m15.mail.163.com (m15.mail.163.com [45.254.50.220]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02847191; Sat, 4 Nov 2023 07:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=3O/AC UjY9iRPgXuqmvo563uZpZP1cuuJTllLXw0vPQQ=; b=cxKgrAKGisON755jtqDt0 gb6lWGxaNcnGRO9M/7iBrCYhZcegcjqcEf5hnE4/g5feglUiaYTYgHjRggpDqnAv 19flctvqUUl1WJnk/gDffzXiQ6iwCf/cY7O8Os7ftiofto1VApjqSnDJGy/Av/pN H3bxbzN+cyAKr2+I0GTAvg= Received: from leanderwang-LC4.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g0-0 (Coremail) with SMTP id _____wCnL8r5VUZlfwsnCQ--.24372S2; Sat, 04 Nov 2023 22:32:26 +0800 (CST) From: Zheng Wang To: aspriel@gmail.com Cc: franky.lin@broadcom.com, hante.meuleman@broadcom.com, kvalo@kernel.org, johannes.berg@intel.com, marcan@marcan.st, linus.walleij@linaro.org, jisoo.jang@yonsei.ac.kr, linuxlovemin@yonsei.ac.kr, wataru.gohda@cypress.com, linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com, linux-kernel@vger.kernel.org, security@kernel.org, stable@vger.kernel.org, hackerzheng666@gmail.com, Zheng Wang Subject: [PATCH v2] wifi: cfg80211: Fix use-after-free bug in brcmf_cfg80211_detach Date: Sat, 4 Nov 2023 22:32:09 +0800 Message-Id: <20231104143209.734871-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wCnL8r5VUZlfwsnCQ--.24372S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxJr45GryUGF4rGr4fXF4UCFg_yoW8Aw1fpF WfWa4DAryUWrW3Kr4F9rnrXFyrtw4DGwnYkr4UZ3Z3uFn8ur1rJrWjgFya93WDGrs2y3y7 Ar4vqr17GrZ7Ga7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR1rWrUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/xtbBgxseU1d7gbdSHAAAsB X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 04 Nov 2023 07:35:08 -0700 (PDT) In brcm80211 driver,it starts with the following invoking chain to start init a timeout worker: ->brcmf_usb_probe ->brcmf_usb_probe_cb ->brcmf_attach ->brcmf_bus_started ->brcmf_cfg80211_attach ->wl_init_priv ->brcmf_init_escan ->INIT_WORK(&cfg->escan_timeout_work, brcmf_cfg80211_escan_timeout_worker); If we disconnect the USB by hotplug, it will call brcmf_usb_disconnect to make cleanup. The invoking chain is : brcmf_usb_disconnect ->brcmf_usb_disconnect_cb ->brcmf_detach ->brcmf_cfg80211_detach ->kfree(cfg); While the timeout woker may still be running. This will cause a use-after-free bug on cfg in brcmf_cfg80211_escan_timeout_worker. Fix it by deleting the timer and canceling the worker in brcmf_cfg80211_detach. Fixes: e756af5b30b0 ("brcmfmac: add e-scan support.") Signed-off-by: Zheng Wang Cc: stable@vger.kernel.org --- v2: - fix the error of kernel test bot reported --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 667462369a32..646ec8bdf512 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -8431,6 +8431,9 @@ void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg) if (!cfg) return; + if (timer_pending(&cfg->escan_timeout)) + del_timer_sync(&cfg->escan_timeout); + cancel_work_sync(&cfg->escan_timeout_work); brcmf_pno_detach(cfg); brcmf_btcoex_detach(cfg); wiphy_unregister(cfg->wiphy); -- 2.25.1