From nobody Fri Dec 19 07:16:35 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D002AC07E9D for ; Mon, 26 Sep 2022 10:21:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235248AbiIZKV1 (ORCPT ); Mon, 26 Sep 2022 06:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235279AbiIZKTP (ORCPT ); Mon, 26 Sep 2022 06:19:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 913CA4A82A; Mon, 26 Sep 2022 03:15:38 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 899DE60B5E; Mon, 26 Sep 2022 10:15:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79068C433D6; Mon, 26 Sep 2022 10:15:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187337; bh=2x6zsb67uTFw6Zg5Vv9Mn/ateOWgVoYfDeRhJLjFAvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yPiv6+DCNbI10XY8z8tANe1zzZmM3m4WZHdlV6XgLgskOk4e9zJOBp1pbPqk+gYxA BqAdXSe+DUmdLtylWzClrPB95I8neGNtqhwBat3x/bWX46VNYkNl7PxZPd/bx5ZyW/ bgL/h6Yq/Oq0ilMAv9ZeNeBk60ybHD1Y382CpOFY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f9acff9bf08a845f225d@syzkaller.appspotmail.com, Johannes Berg , Siddh Raman Pant , Johannes Berg , Sasha Levin Subject: [PATCH 4.14 16/40] wifi: mac80211: Fix UAF in ieee80211_scan_rx() Date: Mon, 26 Sep 2022 12:11:44 +0200 Message-Id: <20220926100738.847583156@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100738.148626940@linuxfoundation.org> References: <20220926100738.148626940@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Siddh Raman Pant [ Upstream commit 60deb9f10eec5c6a20252ed36238b55d8b614a2c ] ieee80211_scan_rx() tries to access scan_req->flags after a null check, but a UAF is observed when the scan is completed and __ieee80211_scan_completed() executes, which then calls cfg80211_scan_done() leading to the freeing of scan_req. Since scan_req is rcu_dereference()'d, prevent the racing in __ieee80211_scan_completed() by ensuring that from mac80211's POV it is no longer accessed from an RCU read critical section before we call cfg80211_scan_done(). Cc: stable@vger.kernel.org Link: https://syzkaller.appspot.com/bug?extid=3Df9acff9bf08a845f225d Reported-by: syzbot+f9acff9bf08a845f225d@syzkaller.appspotmail.com Suggested-by: Johannes Berg Signed-off-by: Siddh Raman Pant Link: https://lore.kernel.org/r/20220819200340.34826-1-code@siddh.me Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- net/mac80211/scan.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index dd9d7c4b7f2d..5df8f393c119 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -385,10 +385,6 @@ static void __ieee80211_scan_completed(struct ieee8021= 1_hw *hw, bool aborted) scan_req =3D rcu_dereference_protected(local->scan_req, lockdep_is_held(&local->mtx)); =20 - if (scan_req !=3D local->int_scan_req) { - local->scan_info.aborted =3D aborted; - cfg80211_scan_done(scan_req, &local->scan_info); - } RCU_INIT_POINTER(local->scan_req, NULL); =20 scan_sdata =3D rcu_dereference_protected(local->scan_sdata, @@ -398,6 +394,13 @@ static void __ieee80211_scan_completed(struct ieee8021= 1_hw *hw, bool aborted) local->scanning =3D 0; local->scan_chandef.chan =3D NULL; =20 + synchronize_rcu(); + + if (scan_req !=3D local->int_scan_req) { + local->scan_info.aborted =3D aborted; + cfg80211_scan_done(scan_req, &local->scan_info); + } + /* Set power back to normal operating levels. */ ieee80211_hw_config(local, 0); =20 --=20 2.35.1