Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp547275imn; Tue, 26 Jul 2022 03:08:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sAj1us4NlroR0dO4eWygq+sK1XtXsUI4DcDwCKCD3o4u3dxdO0j9cT7KwMt0yB2Fd4MN2Q X-Received: by 2002:a05:6402:3408:b0:43c:2dd3:d86b with SMTP id k8-20020a056402340800b0043c2dd3d86bmr6037303edc.108.1658830123757; Tue, 26 Jul 2022 03:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658830123; cv=none; d=google.com; s=arc-20160816; b=FKvUJShSSjYk+jkSf/NvTDyZPPh2Jl30q85ocQwJZ43nWHhjd4mEXeBm78w6QuHAqw Cwj964LIm156o0mGmAw+G91UE7StciCcr0YeI6ylCcVwkk2nEXlMKjzGEa5Lefyy/6DP G1mndTlgSGHalislbYJuawS9zBgkcSPNqJs6FIi88Z2Llxz26Uz24dmcBkZ+txObFf3l eDjA0XKVb1TZhkh70ICyx2kii+AfaHwmTyk4+5yLd7XDEtZXuY7huEvJAJhJUtDwe0Jh 7iBJYHbcrwzSh1rZJQ8kbSaH8I/sZxqJmAY2Fd+EGoXjc3LPJYeH73p6+GmdtZQXgCOK n6rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=eptp1f76nSR7hEUsePloA5aK8E66pD/xnYvzEDwBNmM=; b=qPUXhM/kTuD05IK2Arn78MAUHyrZnnEjtUoP3yXOnsSKRUIj7S7K8JObAkd/7ljsLJ 14M8zeEUjek1w1wd/9WAQKGooeSIpi4CYLJ7lMc+6RSZiXSa3cg33BKpoJVwAeTUM43v 4O+zD+As4hYjaEuF0csXGEykwAMqheb88e+d4TkXA7lkClQETC/EedC0dO+R2fieiDb0 Jdz6Pp5isSBkbHsBEZTeNL61MU8jrtjLB0vF3yHeRvINow7LFFBm1BjI3S+9cUaj0Run r/KzAYxfbcCh7ztWjAPCSjxkds/f2FHAKe5Aei7NauOJiy2EPkk4uuLDnrVm1RLpTQgn wtKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=kYYITZtL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id es19-20020a056402381300b0042dc61e68d0si12441422edb.137.2022.07.26.03.08.25; Tue, 26 Jul 2022 03:08:43 -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=@google.com header.s=20210112 header.b=kYYITZtL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238436AbiGZKHc (ORCPT + 65 others); Tue, 26 Jul 2022 06:07:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237702AbiGZKHa (ORCPT ); Tue, 26 Jul 2022 06:07:30 -0400 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 449CBCE0E for ; Tue, 26 Jul 2022 03:07:29 -0700 (PDT) Received: by mail-yb1-xb35.google.com with SMTP id f73so24495103yba.10 for ; Tue, 26 Jul 2022 03:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eptp1f76nSR7hEUsePloA5aK8E66pD/xnYvzEDwBNmM=; b=kYYITZtLdjINtcyVlpignWgeGX4iav62tqrI7FVm6/Xt9pZ0dSulgYQK9/aL9XNzeg Dx3KZBuVwHCKvNENqX0oDFJ/KHlBD/ZtkYZOAi8nzAhseZfsPhCffPh1OZMFqtasLVF0 GFPP/JDfDjnDFqbw3vcC541SiTSV5CU8bgJkfQhqPhtg31smFhE1Y3BL8Tr+btd4fYj2 6FbM+ZzgrNAlhlExwG5J2ha4peQEkbO09NncgIVXY2c8+w+oBwn8ErjjZtRxly0UBuYY H2KSxJIacnKVSEwvvGNJ3MN4iBKMilSa6XPHab2qXegjhCUX20MSPmgEGGRE8bxh/n2w Vcpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eptp1f76nSR7hEUsePloA5aK8E66pD/xnYvzEDwBNmM=; b=QpJ25oxYXX1CU5MWuYVFRGTNwD9OM9jbr858o3m+R6hKqfDgCsZAGQzDvceE6G1+3S U38Vz3NV4krIcmwn+0b6yBb/ZfOiX1sWPH/3Aokc94i8N1FJb4IJWCXYQk6eCOLSJeZn ynH+w+PjtmH9xMlkXBJiBdxyfCOUZjThyMINgdU1vOzeEB9vhVwqGV6/+2xMbL/xretb PeDWf6nzw+BW9bQmwHcd00vnFypy15u+KbRuQkh/LZzsb18l1CeNssGKsEpYy0gf/5EW sS9MXhzv2Ggsv30oKwwBzSjDPzNaXhwQkUcREUL2CpwgmIvsoAEhxe0bCtSIvdQfuMp3 P25Q== X-Gm-Message-State: AJIora+RF53BOgJSvK/r6yTf2QhHlP1ByBCMWgpt2buO5uiLWa/gweNh 24/Xq0NjsU+nHz8R1uRF++BnHsSSwYcb2AHHijCRRg== X-Received: by 2002:a05:6902:114b:b0:66f:d0:57c7 with SMTP id p11-20020a056902114b00b0066f00d057c7mr12779019ybu.55.1658830048241; Tue, 26 Jul 2022 03:07:28 -0700 (PDT) MIME-Version: 1.0 References: <20220701145423.53208-1-code@siddh.me> In-Reply-To: <20220701145423.53208-1-code@siddh.me> From: Eric Dumazet Date: Tue, 26 Jul 2022 12:07:16 +0200 Message-ID: Subject: Re: [PATCH] net: Fix UAF in ieee80211_scan_rx() To: Siddh Raman Pant Cc: Johannes Berg , "David S . Miller" , Jakub Kicinski , Paolo Abeni , linux-wireless , netdev , linux-kernel , linux-kernel-mentees , "Paul E. McKenney" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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, Jul 1, 2022 at 4:55 PM 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; Note: this is slightly racy. You are supposed to follow this order in this situation. 1) Clear the pointer Then: 2) wait an rcu grace period (synchronize_rcu()) or use call_rcu()/kfree_rcu(). > > if (!send_message) > -- > 2.35.1 > >