Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4454698rwb; Tue, 6 Sep 2022 07:46:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR6t4DHcNCI6ctQGwVvYAGgpDHrP1I0+fRAR4eI2DafSaD2MsQlEc9UqUGwAWXHZYAT/HZWr X-Received: by 2002:aa7:d3d6:0:b0:44e:98b9:3d7b with SMTP id o22-20020aa7d3d6000000b0044e98b93d7bmr7343037edr.259.1662475617135; Tue, 06 Sep 2022 07:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662475617; cv=none; d=google.com; s=arc-20160816; b=woeBt0JlG+2OtrKeylY03RZlD2p9gVMVvhOaZJAB/wjPASvPGVUIAsdzu3jFeVeJTA J7zCb7MgddY2tjcgxRCyfVhgIYYOeG/q9NOCzqd3OJZuWbUAp8zWAB0qetAxpsRswf5m iSiuUdpnJraCucdxzEB1+uoSNhN6ddVlbX4rj9rcLety6jI5LUSqg68DHSSBn5R88Vp1 1kVZtGBingFq9Kz2RyQAamdGxLtQX9Ee8+M1GCNjcR+sOLBjyN8HwUS3txoXr3VjPdiZ Vtsg6R32bn1bNbXSXqPzuTZ0A9NSy1wzZgK9Nhv93XYq9DCv0dURosoxvGl3C7iRtBsD hLug== 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=tpZtFB6Wqn5FeTTkBFk6WNXLs5D/eH8/H0GPll2vKN0=; b=u9r8KWKbsg+k7O0rkSVr8l6BseHGqcn+A0+m4jQUNP/Y/KzU79O82sWt6pUMaedXPD Iko7eXOt7DY8+NhnQBp/uY5oHdBPcmpZ3V3RNoYQlBfAD1mzCxXw4oeZ0JI0Opd0/gN9 zy0pRtfEwolPY71OYejJuSlmyVQn6CDo+onZt8+TGA1u40KdfTG1PqOwVg92B8cQ7GeA Ym4GtIvOSl5uRbRuEr+Snzw9d6c+oD80slLYGK64qNXIxf9xZSmNxmmO/vAqYf6LRbp+ RbM7asCTQomVpG5ysewzUkn5pYqsxijmhY9xdW9GTV5Mv2qLH9jjAkvOxgYnqLDGOcma rVSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HRIZhMwW; 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 l12-20020a056402254c00b0044874cf4c88si11086541edb.430.2022.09.06.07.46.29; Tue, 06 Sep 2022 07:46:57 -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=HRIZhMwW; 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 S233089AbiIFNlu (ORCPT + 99 others); Tue, 6 Sep 2022 09:41:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232733AbiIFNjf (ORCPT ); Tue, 6 Sep 2022 09:39:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BBE87D1F0; Tue, 6 Sep 2022 06:36:39 -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 0BBD061555; Tue, 6 Sep 2022 13:35:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D1A6C433D6; Tue, 6 Sep 2022 13:35:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471308; bh=ncR27amRLgoeFbOMFz/zV4jrHbdgghFuP1I4mukXaL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRIZhMwWirZ3GLFR8gpK282IdoGuf+vNzR4M9gLM32kcLMesMwvLVGdfF/OFWqE15 x5qL/0rsXOYW5n0D21KksCcSCJRtRFr1vW7nRq2pe0xUkFzffRwA7y/OG9QOYcQLG/ x1eqJTYyZN040wy/ifYyyTvfHPt8x9B0ARxjfGZ4= 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 Subject: [PATCH 5.10 66/80] wifi: mac80211: Fix UAF in ieee80211_scan_rx() Date: Tue, 6 Sep 2022 15:31:03 +0200 Message-Id: <20220906132819.834452293@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132816.936069583@linuxfoundation.org> References: <20220906132816.936069583@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.1 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,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 From: Siddh Raman Pant commit 60deb9f10eec5c6a20252ed36238b55d8b614a2c upstream. 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: Greg Kroah-Hartman --- net/mac80211/scan.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -461,16 +461,19 @@ static void __ieee80211_scan_completed(s 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); RCU_INIT_POINTER(local->scan_sdata, NULL); 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);