Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp638458imn; Tue, 26 Jul 2022 05:43:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vCOUyrzVBIGaFybz3M04HWZepxUMOrJzpgOXywm7Naa7rgGqqrFMM5/pGwetenIP4H4CAr X-Received: by 2002:a17:906:6a21:b0:72f:2174:16e6 with SMTP id qw33-20020a1709066a2100b0072f217416e6mr13361792ejc.177.1658839387820; Tue, 26 Jul 2022 05:43:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658839387; cv=pass; d=google.com; s=arc-20160816; b=mY0yaTzQsyts8oSUXWLfzaUhUtV3pBAtTBhyPztW0fEPiCzJGHqTUfC0ej2zenk2gd FmFxOdm2Jx0anP1wqahdC5NtWpLS7THwZSaOe3ko7S66aIut01UnE1NywEvqso63FMe8 BZh0t6j+fI3cUadxDZNkamEaVQ3rDi4KPT5ile1xqwmfdfHW6EgxbfrgA3FHz7xtvG6/ 0Ybht05FH5T4IXjI+51EaQnTG1zmo9/OlZvUgSgGWGseziXlIzZozsDYt69p7vPjU5L0 Vn7kgCGhtUhfoJ7+qqLp8MCxg7OnvpMCmzFnv/dD7Eh9s9rzYmoZ9ImkLp3ufNZbXzwK iXMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:date :subject:message-id:cc:to:from:dkim-signature; bh=UWd274VYR1WKzP/YgplPfzV3z+zLp7Z125urE755fUM=; b=rRrfUJbLmm4moo7SzpZ0leybbWrG/4QtTTlwIIy/z3Y5koS0qoAkJqTh0x1WqwiHsN PW6S8/NXT1ZweqliHRl82Mgn04vjAdQ9x4GKYiBXBMGLV6yo7PJFUi5t347bHRrdYYM4 DKWUlohD59en5yvfWbf3FTPrFpIrX3EDN7jOX5BIerVitrUFCXfLVjUbBbx2Z0L+rutc gQzBA8cGMSfQRTg8Eu04P4ZexfW7m95RMUbkghKnTN8LqE4MBG+1qfe8o5s48nZUkbaJ GtUEqr33xGeFbzqdk0xpfGl7T54T/JZLshO7BShpZfM/9AlpbXsakHiCRCSaHCXqscPU QW5A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=LqDgFxJ4; 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-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=siddh.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p11-20020a056402500b00b0043bc865fcc2si2542622eda.184.2022.07.26.05.42.49; Tue, 26 Jul 2022 05:43:07 -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=@siddh.me header.s=zmail header.b=LqDgFxJ4; 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-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=siddh.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233536AbiGZMj6 (ORCPT + 65 others); Tue, 26 Jul 2022 08:39:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbiGZMj5 (ORCPT ); Tue, 26 Jul 2022 08:39:57 -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 119AE2ED4E; Tue, 26 Jul 2022 05:39:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658839167; cv=none; d=zohomail.in; s=zohoarc; b=UkfuxHVLOwO/vn5hQmBft+g6uXh5aUV1+rD/VBC9ql1x2s1rMdkRKWSULiAbebxfR/MSK+qdzn+OnOf7NMUnOHQ57oCU3HX3xhwMVDOQf9vIJGoBfgRxVp8aKGU7AVIpjLOSrw1PbOSXUYaDZSMEXO48ClWDs+Lfl4+WG0RO89c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1658839167; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=UWd274VYR1WKzP/YgplPfzV3z+zLp7Z125urE755fUM=; b=QvZvg9dVjsKln67kWE0aija4i5+ghMJp5YfYaJk2KYHmUrfh8Kg9WksFSajUUOUZZziuDuHwnr8V9guDo3eVd7ycHdr8xbJf/CCp2vy5vnigA1qCU4i1lRuBIUa+h2uwBC7eR4tSl10hgATJPR+pagwAzDzA2CNUa7VA1Y3M+sw= 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=1658839167; s=zmail; d=siddh.me; i=code@siddh.me; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=UWd274VYR1WKzP/YgplPfzV3z+zLp7Z125urE755fUM=; b=LqDgFxJ4AeYBp4bkbR6w70NQ2bdc9fL3GxdkQIHkMTSd9yxCamFTE4AtO1bzE1Zu NX7Tu4CmcOyQ2dTUYqyxAkbTkmY8bgd1ruIHZcOcZRQM/9JDcWw+y746el1eKOLYZry 5rQbUZEEZJv/9CMfr1eYdtCzNHHSusI33CNGf2Ag= Received: from localhost.localdomain (103.240.204.132 [103.240.204.132]) by mx.zoho.in with SMTPS id 1658839166242252.82637890145338; Tue, 26 Jul 2022 18:09:26 +0530 (IST) From: Siddh Raman Pant To: Johannes Berg , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-wireless , netdev , linux-kernel-mentees , syzbot+f9acff9bf08a845f225d@syzkaller.appspotmail.com, syzbot+6cb476b7c69916a0caca@syzkaller.appspotmail.com, syzbot+9250865a55539d384347@syzkaller.appspotmail.com Message-ID: <20220726123921.29664-1-code@siddh.me> Subject: [PATCH v2] wifi: cfg80211: Fix UAF in ieee80211_scan_rx() Date: Tue, 26 Jul 2022 18:09:21 +0530 X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset=utf8 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,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-wireless@vger.kernel.org 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=3Df9acff9bf08a845f2= 25d 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 --- 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 { =09struct cfg80211_ssid *ssids; @@ -2397,6 +2398,7 @@ struct cfg80211_scan_request { =09bool scan_6ghz; =09u32 n_6ghz_params; =09struct cfg80211_scan_6ghz_params *scan_6ghz_params; +=09struct rcu_head rcu_head; =20 =09/* keep last */ =09struct 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_d= evice *rdev, =09kfree(rdev->int_scan_req); =09rdev->int_scan_req =3D NULL; =20 -=09kfree(rdev->scan_req); =09rdev->scan_req =3D NULL; +=09kfree_rcu(rdev_req, rcu_head); =20 =09if (!send_message) =09=09rdev->scan_msg =3D msg; --=20 2.35.1