Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1959808rdf; Sun, 5 Nov 2023 23:32:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEz5SUxcArpyafddCK0hOT/+UXt9Kwq2vPUMmwXuesS4kafG5nSUQCFN4RWkh1R+kE6uix0 X-Received: by 2002:a05:6a20:da84:b0:17b:1f76:86ee with SMTP id iy4-20020a056a20da8400b0017b1f7686eemr16170581pzb.16.1699255971589; Sun, 05 Nov 2023 23:32:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699255971; cv=none; d=google.com; s=arc-20160816; b=HObwEBnfeP64qmE4bkI/sIJcYlSh7axSZiavdNsl0GrYy9lZ2uuCpnkV/H9eC2i+Ql fgnDivdPp0N7OPden+70KkmJCNiY9d5H9yQy1/bAAPxcK+oTN9RmhLgjBwRzziS3RbT+ Lr4qIlBCKu6cLpfp0O62b7X+DFB5sT2ez15W4Wh6xqAgD/G36g0CinW7Bu9jamZxOAaj /xI8trg4kotd36QFObaS+UC+JluY8U79yXyPaj9myrrDhQgzlHf3qGs6SahLjhmBGxr9 Qc9dmerl+buk7FXNoTf4UBY1dyq48+CjdkR8huYcYY4SIKSfmp2apYHYfGW69fmrJ/Om ZZhA== 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=cIM8ANhkDk4cNFFBOnL4o+hCAPV9B/A22slZhVaSAww=; fh=Tn6y7+OCh8fxSFSicSZYxaqjR/wrDs1aDTQgTx7ywJ4=; b=oIw/M/6Rkji1BKDQtlUTvPAJUpTUgnSVILSNdzx6ZNE8rFqugLAYXU9GsZRP6F2Bqg G5sEC8iBdkXNOIKBVX/mM/Qr0/BtZtwXBKe5ETkzd2vq1aXN4yudlBfsFq19CzyPKQ/j afBPof613OyqxM7V0G3gDGU3j+v3jHE/zspfNhQye8g6pphsRqEzPvxYr78QDdYlhoK8 cFkTyggCNzzXGM1I3Vk3ZwlxFex9BHClFKfWCklOl/9pEuT1C96Sg+1ffhl+2YqcLXyE ADw+uS8qkdqhhfPUR8vDV0VEHdJ55hu/dE3DVbTruajbGjwvH0pZeVirIs0SdZMY3JCg DNIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=NXQYt0ra; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ck16-20020a056a02091000b005b7c45b1f95si8441037pgb.555.2023.11.05.23.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 23:32:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=NXQYt0ra; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 5088C80481A9; Sun, 5 Nov 2023 23:32:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230514AbjKFHcj (ORCPT + 55 others); Mon, 6 Nov 2023 02:32:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbjKFHci (ORCPT ); Mon, 6 Nov 2023 02:32:38 -0500 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C4253FA; Sun, 5 Nov 2023 23:32:29 -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=cIM8A NhkDk4cNFFBOnL4o+hCAPV9B/A22slZhVaSAww=; b=NXQYt0ramU2gEdY2jd3LJ cwdXRElPwhs7LExeTJrCOb++t1VYgpSYTRRZOVmjAXxuSQ+rKqogC3UugcwpmBqb 64IpNI1YgSoVsHdcpY7tht5RF3DkH8r2jYocqZHhQZEufvfyKjdb9Yqv1B9X4u2r YdfxF4CnM3o8WIV4K91h9w= Received: from leanderwang-LC4.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g5-2 (Coremail) with SMTP id _____wD338YelkhlaFLCCQ--.58624S2; Mon, 06 Nov 2023 15:30:38 +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 v4] wifi: brcmfmac: Fix use-after-free bug in brcmf_cfg80211_detach Date: Mon, 6 Nov 2023 15:30:22 +0800 Message-Id: <20231106073022.820661-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wD338YelkhlaFLCCQ--.58624S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr13tw1fAw4UJw1rZFyxKrg_yoW8ZFWUpF WfWa4qyryUWrW3Kr4F9rnrJFyrtw4DKwnYkr4qvas3uFn8ur18JrW8KFya93WDGrs2yay7 Ar4vqrnrGrZ7GFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR1rWrUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/xtbBdgEgU2DkpywCtgAAs- X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Sun, 05 Nov 2023 23:32:42 -0800 (PST) This is the candidate patch of CVE-2023-47233 : https://nvd.nist.gov/vuln/detail/CVE-2023-47233 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 --- v4: - rename the subject and add CVE number as Ping-Ke Shih suggested 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