Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1680139rwb; Fri, 12 Aug 2022 05:17:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR5tG4Layx6ZSlYcP3jIwUI7xjm6ESKKUl6cHDSXY/ZQCmV8TZThQLkQTuL1XtCPPlwnXgiD X-Received: by 2002:a17:90b:3502:b0:1f3:550:5f6f with SMTP id ls2-20020a17090b350200b001f305505f6fmr3917713pjb.49.1660306631659; Fri, 12 Aug 2022 05:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660306631; cv=none; d=google.com; s=arc-20160816; b=nkq0QxAph6KYCyvakDNYc4UC6cz3aTfnIWTemPodJ6owS4QPnhsn+W9kHOTiFdCYfB slfvjxQAWEyfFTP57HwRGwO4xjGNnvjQQRTeWiOOyxvgwPsTkx5hJnh0pE0pSKyXBOAS C9Is+EpB1Rl4YZaHjB5C/W9qtalDqYIc0rX4j86q556sBD2uu7/t8iUMfyiWUpptGLT2 kC3CluZ8GTZJrisxbaCP9tmvCPyT+VDzjqFQgnmf+UIfQZmpaKWOntP3HneijXtfvmI4 kgMFtfHQD57w7Fnv3bb8IsFy/zjQHfpz2gJPxtkeZf7hJRnHWlGFQNCerH580QhVLsrV vTvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iBeezk9hgPLErdTke1nMJqMS4Rg/EW50QykqCbUNEWo=; b=0rjDLCCsuthnWJ8WYUiG3+ErnZr3MiGpcG1dX+U4hxUs5z6hc73L03BBLOZv25E9go kMGTEecNtSWsWssfg+VuWLvNQm4NkWq+1l9ar0Mc8jt4aQOK003mpdlltEOyMdW0hj0r WoV6BBM4R1SmnKosabAR+qHXrAaom0ZQzwk+PBOamv5ikZ52EfdMoEe2IgBTDvsjWEYY DHM0ruyNTV7KrO3xcNhP70VuiCeLhq4lOUHhXlnA9mDu6cKgyJjXLGVrFHlW8D0PgTM0 IrHVqes8WtzJPA9EbCdUS9Y4Zs3rl+5SIXhCTMbXp3pirsOAsgrDc975/bsqcfgkqcxT jSgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=paLTCH++; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 q18-20020a170902e31200b0016dc106d19dsi1725273plc.527.2022.08.12.05.16.56; Fri, 12 Aug 2022 05:17:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=paLTCH++; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 S238608AbiHLMQK (ORCPT + 65 others); Fri, 12 Aug 2022 08:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237181AbiHLMQJ (ORCPT ); Fri, 12 Aug 2022 08:16:09 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1708F97D46; Fri, 12 Aug 2022 05:16:05 -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 sin.source.kernel.org (Postfix) with ESMTPS id 11F02CE1BA4; Fri, 12 Aug 2022 12:16:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B793FC433D6; Fri, 12 Aug 2022 12:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660306561; bh=cDPXyw+0tZdATJeb97wbb8Q8vKGfySScZQ9VpUoFvk0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=paLTCH++EckJIU4uEojjfTmtYcEz3socVkzqTh4eohsbCA1/+4U1k/vNZQXLA8q6c N7V78szUNV3pGj+bZbfpXYCD6er1jiC8xkZ2H8cmEZoE0xDdyM5d/he57JEHbwQJO8 OyR0Dmf1/TQQ4gy2er5Jav380HFrCA2HDJMOBXw8= Date: Fri, 12 Aug 2022 14:15:58 +0200 From: Greg KH To: Siddh Raman Pant Cc: Johannes Berg , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev , syzbot+6cb476b7c69916a0caca , linux-wireless , linux-kernel , syzbot+f9acff9bf08a845f225d , syzbot+9250865a55539d384347 , linux-kernel-mentees Subject: Re: [PATCH v2] wifi: cfg80211: Fix UAF in ieee80211_scan_rx() Message-ID: References: <20220726123921.29664-1-code@siddh.me> <18291779771.584fa6ab156295.3990923778713440655@siddh.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18291779771.584fa6ab156295.3990923778713440655@siddh.me> X-Spam-Status: No, score=-7.7 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-wireless@vger.kernel.org On Fri, Aug 12, 2022 at 03:21:50PM +0530, Siddh Raman Pant via Linux-kernel-mentees wrote: > On Tue, 26 Jul 2022 18:09:21 +0530 Siddh Raman Pant wrote: > > ieee80211_scan_rx() tries to access scan_req->flags after a null check > > (see line 303 of mac80211/scan.c), but ___cfg80211_scan_done() uses > > kfree() on the scan_req (see line 991 of wireless/scan.c). > > > > This results in a UAF. > > > > ieee80211_scan_rx() is called inside a RCU read-critical section > > initiated by ieee80211_rx_napi() (see line 5044 of mac80211/rx.c). > > > > Thus, add an rcu_head to the scan_req struct, so that we can use > > kfree_rcu() instead of kfree() and thus not free during the critical > > section. > > > > We can clear the pointer before freeing here, since scan_req is > > accessed using rcu_dereference(). > > > > Bug report (3): https://syzkaller.appspot.com/bug?extid=f9acff9bf08a845f225d > > Reported-by: syzbot+f9acff9bf08a845f225d@syzkaller.appspotmail.com > > Reported-by: syzbot+6cb476b7c69916a0caca@syzkaller.appspotmail.com > > Reported-by: syzbot+9250865a55539d384347@syzkaller.appspotmail.com > > > > Signed-off-by: Siddh Raman Pant code@siddh.me> > > --- > > Changes since v1 as requested: > > - Fixed commit heading and better commit message. > > - Clear pointer before freeing. > > > > include/net/cfg80211.h | 2 ++ > > net/wireless/scan.c | 2 +- > > 2 files changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h > > index 80f41446b1f0..7e0b448c4cdb 100644 > > --- a/include/net/cfg80211.h > > +++ b/include/net/cfg80211.h > > @@ -2368,6 +2368,7 @@ struct cfg80211_scan_6ghz_params { > > * @n_6ghz_params: number of 6 GHz params > > * @scan_6ghz_params: 6 GHz params > > * @bssid: BSSID to scan for (most commonly, the wildcard BSSID) > > + * @rcu_head: (internal) RCU head to use for freeing > > */ > > struct cfg80211_scan_request { > > struct cfg80211_ssid *ssids; > > @@ -2397,6 +2398,7 @@ struct cfg80211_scan_request { > > bool scan_6ghz; > > u32 n_6ghz_params; > > struct cfg80211_scan_6ghz_params *scan_6ghz_params; > > + struct rcu_head rcu_head; > > > > /* keep last */ > > struct ieee80211_channel *channels[]; > > diff --git a/net/wireless/scan.c b/net/wireless/scan.c > > index 6d82bd9eaf8c..6cf58fe6dea0 100644 > > --- a/net/wireless/scan.c > > +++ b/net/wireless/scan.c > > @@ -988,8 +988,8 @@ void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, > > kfree(rdev->int_scan_req); > > rdev->int_scan_req = NULL; > > > > - kfree(rdev->scan_req); > > rdev->scan_req = NULL; > > + kfree_rcu(rdev_req, rcu_head); > > > > if (!send_message) > > rdev->scan_msg = msg; > > -- > > 2.35.1 > > > > Hello, > > Probably the above quoted patch was missed, which can be found on > https://lore.kernel.org/linux-wireless/20220726123921.29664-1-code@siddh.me/ > > This patch was posted more than 2 weeks ago, with changes as requested. > > With the merge window almost ending, may I request for another look at > this patch? The merge window is for new features to be added, bugfixes can be merged at any point in time, but most maintainers close their trees until after the merge window is closed before accepting new fixes, like this one. So just relax, wait another week or so, and if there's no response, resend it then. Personally, this patch seems very incorrect, but hey, I'm not the wifi subsystem maintainer :) thanks, greg k-h