Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3599381imw; Thu, 7 Jul 2022 04:40:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uyjI5AsI9jg4tGaw9jG10M4xIOMDa5Nx4YkKgRv97IPMzgJut7t8QEqYcl17RouA3HyRj1 X-Received: by 2002:a17:907:a427:b0:71b:6f0b:8beb with SMTP id sg39-20020a170907a42700b0071b6f0b8bebmr43739400ejc.496.1657194044561; Thu, 07 Jul 2022 04:40:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657194044; cv=pass; d=google.com; s=arc-20160816; b=EZoG/SYliz2Hpop8OZPxFq81fin0n6Ag7ogDa0t9nEmL5KnO2tLLsJyu5H8Zsew5Vh CvCjvvUnuQncvvSlcmcndTbcvCMzmCrF1NTyGhQ6GGvkAu6bk7LZ+6HWKL41FF13RfBF OLloFL3B5uuFMjhTMlJzqW2zru9qxLyvL0tj0FdC+yF71qVklctsSbjcoBC2xHuV3Ea6 uoNhIFIz3uPqfqgnePsxR66vM9S2i75jEsY67xG6uclp7ezz/wL3BqTytZlkNB+YW7va 2LDMXilvBq53OfGgi1dQvcE8DGAvbphazrsMG1Al6iQYU9PM+XBeoJACPrfAydJ2Ur3O Cm3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:importance:content-transfer-encoding :mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:dkim-signature; bh=gTKkhe7yy9xe35WDqN7DEWERl5MpDgjwE9MI2CF5JxY=; b=UYMm9PFik5OzfNNu6T9XLlCkdWgA3TTfgbRx2RwtlzvpEmzTc+evKbxxDAjJZZ0/Wh zbnbT28JYmpnDyb/OYS4DRw6WJ2SdY1RFVKPrYd2MnHlJpWJ9qt4Xaf+tF0jH9akyOz9 u40gm15QjiuYJEZzS+Xur5gPD58nMbQPqq1qAEjD5RfLPtGrqtt1eIU5OD1t7UyHveIM Dfmhj4PHwfs2ycF46DKTD2qG4LegY45WcnpH+8/tFxkSZSU2Yg7OOYzBDgRhT+0r4PgO KSnkbqZrKrcW7QiM5UynZGLcfTpkyiFu2NNYQ7jpmlWLVNoqxNkzrYL18tZWQ/Rr8ACo NNlQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=GzEjLOsK; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb34-20020a170907962200b007121b9fc6fbsi23720553ejc.956.2022.07.07.04.40.16; Thu, 07 Jul 2022 04:40:44 -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=@siddh.me header.s=zmail header.b=GzEjLOsK; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235034AbiGGLhf (ORCPT + 99 others); Thu, 7 Jul 2022 07:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232086AbiGGLhe (ORCPT ); Thu, 7 Jul 2022 07:37:34 -0400 Received: from sender-of-o53.zoho.in (sender-of-o53.zoho.in [103.117.158.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADAEB3207B; Thu, 7 Jul 2022 04:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657193806; cv=none; d=zohomail.in; s=zohoarc; b=I5W1IdvoD2nGBr7cTy4zLxcjT4gnMlRtD3AqrqbTzvvbhez+vjGAwX4xj0GilRpUDRiuDkxBNX8mhjf9gK+/UEXhP0WYqQqxp1I4I7LEuYhxU0CpiOEqmWqbqYfH+H81ddpLBbzsXe/oe66t3z0j2L/vpswji0KWN70Hy5k9LPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1657193806; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=gTKkhe7yy9xe35WDqN7DEWERl5MpDgjwE9MI2CF5JxY=; b=dxWcutimoHYKOL8oATc3wlMqftMo5koKmJLvdc8pkJnZnGq53Nn3p1Qa1n769/iRxUjc6Tvk/erlLRRsfk7oFIzdtZdIPbAFXE6lgzorc3X3mZYrjN8MEGPWbYZDuEfS5tcyCXon9Zv+6mcG7TaCxIkY1lfPecMxxyYD30Rq4Qw= ARC-Authentication-Results: i=1; mx.zohomail.in; dkim=pass header.i=siddh.me; spf=pass smtp.mailfrom=code@siddh.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1657193806; s=zmail; d=siddh.me; i=code@siddh.me; h=Date:Date:From:From:To:To:Cc:Cc:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=gTKkhe7yy9xe35WDqN7DEWERl5MpDgjwE9MI2CF5JxY=; b=GzEjLOsKKpnpUCP+N2Nc85k5+lB8zJSPsSjXmAJLhx7Yksihz/9adhMHH0QIcq0r nwxi4Ag7lVlaItZyo+oajMmJQkjxS6eQk/NbnakNPCGvA7MpEsms0svYumhjXEHJGSj 2AqmeW5HcvwkpR5s1/2iJuVJfbQEdWfuk9b5dGJo= Received: from mail.zoho.in by mx.zoho.in with SMTP id 1657193795628794.4286758139061; Thu, 7 Jul 2022 17:06:35 +0530 (IST) Date: Thu, 07 Jul 2022 17:06:35 +0530 From: Siddh Raman Pant To: "Johannes Berg" , "David S . Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" Cc: "linux-wireless" , "netdev" , "linux-kernel" , "linux-kernel-mentees" Message-ID: <181d8729017.4900485b8578.8329491601163367716@siddh.me> In-Reply-To: <20220701145423.53208-1-code@siddh.me> References: <20220701145423.53208-1-code@siddh.me> Subject: Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx() MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_RED 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 Ping? On Fri, 01 Jul 2022 20:24:23 +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 5043 of mac80211/rx.c). > > Thus, add an rcu_head to the scan_req struct so as to use kfree_rcu() > instead of kfree() so that we don't free during the critical section. > > 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 > --- > 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 6d02e12e4702..ba4a49884de8 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..638b2805222c 100644 > --- a/net/wireless/scan.c > +++ b/net/wireless/scan.c > @@ -988,7 +988,7 @@ void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, > kfree(rdev->int_scan_req); > rdev->int_scan_req = NULL; > > - kfree(rdev->scan_req); > + kfree_rcu(rdev->scan_req, rcu_head); > rdev->scan_req = NULL; > > if (!send_message) > -- > 2.35.1 >