Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp792834rwb; Mon, 26 Sep 2022 06:03:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/L518crgLC0sTE9aF5PShpHhabxZma5tsK+rnlMsZlrZRoWm23P6eXDXx59pK8+HTQajt X-Received: by 2002:a05:6a00:e8f:b0:536:c98e:8307 with SMTP id bo15-20020a056a000e8f00b00536c98e8307mr23505121pfb.73.1664197404519; Mon, 26 Sep 2022 06:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197404; cv=none; d=google.com; s=arc-20160816; b=EiVeCCVhgatJYWzJ8ymBwyFEAQ1ioy9r7c+i6vxzsr5yqzHSCU16EJ//HkyJG/ojSh 1RbTvpZpBA1UJhI7Xljq7lBzBWf58/bve7gFczOjRR1j47gpy12TjaWCT58KV4O3ySAs b4r+MFn++MW+UMnbcy9QLbGtoILyeg06e4UXiGb/Yzp1zDxPw46vSzB0zLV7l/qDlMrh rSQcHT9NHkfqzXv3Hs8kyEZvYR+T8rEXL92yXTiYOxTQOL/McyNOirQFEOJOVahh/sD2 xqh1sPLsHcDYUmN63K56CgC14CTx2+FSTp0frRc4m7F6gHvYOO5gTHK00luqAausWB16 EO5w== 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=KVfDFXFuvCQrMaHmXBylVBxrF6do4brtRUPOK3IR06g=; b=qObGQ958amk7/gJmjfjTfl4/xI0oXzINdWnmFl8JpGU0pnJrWiiuhNW01lN0T+AYaX k/P7eYyxVqV9nJkCEUZO9VkfqcxBkKfFjHXN4C2L18Am3MBM5HlbjAOSTHmUv4m8KK6Q nVc98I/eJTF1CJ/KY7gHV4Os5Im1CXfgqlxcm0fsRFpP5UwEsLjP4Q6JThEExrz9LziM WVEuWIhm00hGtbXlo1L9Th8p4tYxzm72JfA6SnkbceCsUIykYT/DKrM5HcyjM/N8uv3q 7vrhDqEm4tidflOIDLKpZgY0Sna2zz609Oq5eNnHL5ffC4WXSMkbHA90N9g9obPh+SFw xfIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d08FGmpm; 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 w4-20020a656944000000b0043a1c0c5b0csi20020492pgq.704.2022.09.26.06.03.10; Mon, 26 Sep 2022 06:03:24 -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=d08FGmpm; 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 S235781AbiIZKaj (ORCPT + 99 others); Mon, 26 Sep 2022 06:30:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235640AbiIZK2n (ORCPT ); Mon, 26 Sep 2022 06:28:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12BF44E61E; Mon, 26 Sep 2022 03:19:00 -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 EAFF4B80915; Mon, 26 Sep 2022 10:18:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49862C433C1; Mon, 26 Sep 2022 10:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187488; bh=Gws39Zod51pQ7ojLk/9ZwRkZ9aRl9dDPPARiAQhVGa4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d08FGmpmPjgSIjd5QwvSnCOKriSKGa0aLl0CSjCqEuTgAhDNtxV7+2c4K0WzXJk9d /nLmfCye7TeiwYqbhZykBZg3stmXYgg8rdf6GZI9EoDfIkoceC8BOjjDjpK8SCZIlt /PvlJnGWkBIFZqyZNiOxi1eKgQb1RGDzYbfgAHwY= 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.19 24/58] wifi: mac80211: Fix UAF in ieee80211_scan_rx() Date: Mon, 26 Sep 2022 12:11:43 +0200 Message-Id: <20220926100742.330172253@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100741.430882406@linuxfoundation.org> References: <20220926100741.430882406@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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 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: 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=f9acff9bf08a845f225d 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 de42bcfeda9c..e3d8be4feea5 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -412,10 +412,6 @@ static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) scan_req = rcu_dereference_protected(local->scan_req, lockdep_is_held(&local->mtx)); - if (scan_req != local->int_scan_req) { - local->scan_info.aborted = aborted; - cfg80211_scan_done(scan_req, &local->scan_info); - } RCU_INIT_POINTER(local->scan_req, NULL); scan_sdata = rcu_dereference_protected(local->scan_sdata, @@ -425,6 +421,13 @@ static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) local->scanning = 0; local->scan_chandef.chan = NULL; + synchronize_rcu(); + + if (scan_req != local->int_scan_req) { + local->scan_info.aborted = aborted; + cfg80211_scan_done(scan_req, &local->scan_info); + } + /* Set power back to normal operating levels. */ ieee80211_hw_config(local, 0); -- 2.35.1