Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1905233rdf; Sun, 5 Nov 2023 20:41:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEokoaSREvLNfD1Ttmi6K81kRshPBzR6lSlc0RTVpHpLkdwKD8y6ynuyZWYodsoawzANGQQ X-Received: by 2002:a17:903:84b:b0:1c1:dbd6:9bf6 with SMTP id ks11-20020a170903084b00b001c1dbd69bf6mr12644788plb.41.1699245714463; Sun, 05 Nov 2023 20:41:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699245714; cv=none; d=google.com; s=arc-20160816; b=hTq3C3dIvZZekcOKI/j852NPhLhdVXGMB5ZhDX4teTt10gwZx+wUFoIAfrM7r0d4Wr EIZ91Q9iN0qbwzrh/S9u1IRwaIDt9GMSI6UGcleC5q/lBnWD3ZLqxaTzFcKCvtH0qGXl JwS+g8Z8lXX6XvQEDlm5rvGq8L3woeXxmjT1WoB4GCwD2KM3Dtk7It9Rc0aA9W8cVtT8 fitlXkQ90juXSTB5vu3ZsyCPPPlqjMiYilRC+cq7RH4ARqswOpNWA/Dk/56ohB1P1rER AdcP/jHY5xi3f2i+FhSHyoRRVpeFW1adGsZUbeyetG50cgPTwDQr8PEZ32/cNGM9vXhN pJKg== 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=931T/6DdzEtu7J5vjCv+j5JxprplICFG6FVSLvc1peA=; fh=Tn6y7+OCh8fxSFSicSZYxaqjR/wrDs1aDTQgTx7ywJ4=; b=drLNudJTqAbQV6LQW1LKTJE6Mht0XD3SL6OrHkfqJMHX1MNVbusrcrKvJxgA5WfbVL uFvzGijngDQvltfJisXK1mr4dOofqO9pq2sEaqC9OKoexSDmHXAD6evApM/OQ4W6M83d 6VlBYyCF+gw0zBTdBvUYR+NAUy5174amf8r4ifJhYxCBagMrl40/5gDtHDZGwxdyrY7q b06xGfTdJPBOlt/QB8z2VXxwtZ9f9NndUcrzQKjwx4BgqZLWO3+2+nXSTVagWeu/W+kn BzeNw1OSHDb5V9CSSY2LhRbrBZ6eg/gJ7LBw7+6JzdnJaSFcZgAXscblAohn46IaPoWV 56tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=aiHxTHtf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-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 c17-20020a170902d49100b001cc550c83d5si7789249plg.515.2023.11.05.20.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 20:41:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=aiHxTHtf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-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 648858056983; Sun, 5 Nov 2023 20:41:53 -0800 (PST) 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 S230324AbjKFElv (ORCPT + 99 others); Sun, 5 Nov 2023 23:41:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbjKFElt (ORCPT ); Sun, 5 Nov 2023 23:41:49 -0500 Received: from m15.mail.163.com (m15.mail.163.com [45.254.50.219]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2ED97F2; Sun, 5 Nov 2023 20:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=931T/ 6DdzEtu7J5vjCv+j5JxprplICFG6FVSLvc1peA=; b=aiHxTHtfGCNQpz5cylBvq vi/cIMTE2IDqlLJ0lhlyGqCF1QpgwzOJqu28L1FqT4N3sFC9MlvGiO9LP6Rq85Pe eDWIvdIdar0aBuCMTqYclNu/ufE7fI+rA9iM0qSsdtpghtRyXeXwXkcG7LfXX07u p7R7bJHdz4DN4g2kW+6Nqs= Received: from leanderwang-LC4.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wBnL1s6bkhlVWPGCQ--.11062S2; Mon, 06 Nov 2023 12:40: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 v3] brcmfmac: Fix use-after-free bug in brcmf_cfg80211_detach Date: Mon, 6 Nov 2023 12:39:57 +0800 Message-Id: <20231106043957.815407-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wBnL1s6bkhlVWPGCQ--.11062S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxJr45GryUGF4rGr4fXF4UCFg_yoW8Cry3pF WfWa4qyryUWrW3Kr4F9FnrXFyrtw4DKwnYkr4UZ3Z3uFn8ur1rJrWjgFya93WDGrs2y3y7 Ar4vqr17GrZ7Ga7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR1rWrUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/xtbBzh0gU2I0bNvKggAAsJ 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_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 05 Nov 2023 20:41:53 -0800 (PST) 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 --- v3: - rename the subject as Johannes suggested 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