Skip to contentSkip to conversation

net: Fix UAF in ieee80211_scan_rx()

PATCH Superseded Siddh Raman Pant 4 participants 8 messages Jul 1, 2022 – Jul 26, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: Fix UAF in ieee80211_scan_rx()

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 [email protected]
Reported-by [email protected]
Reported-by [email protected]
---
 include/net/cfg80211.h | 2 ++
 net/wireless/scan.c    | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/net/cfg80211.h +2 -0
index 6d02e12e4702..ba4a49884de8 100644
@@ -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[];
net/wireless/scan.c +1 -1
index 6d82bd9eaf8c..638b2805222c 100644
@@ -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)
Signature · 7 lines
2.35.1


_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw

Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx()

Ping?

On Fri, 01 Jul 2022 20:24:23 +0530 Siddh Raman Pant <[email protected]> wrote

Quoted 59 lines

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 [email protected]
Reported-by [email protected]
Reported-by [email protected]
---
 include/net/cfg80211.h | 2 ++
 net/wireless/scan.c    | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/net/cfg80211.h +2 -0
index 6d02e12e4702..ba4a49884de8 100644
@@ -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[];
net/wireless/scan.c +1 -1
index 6d82bd9eaf8c..638b2805222c 100644
@@ -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)
Signature · 1 line
2.35.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#2 lore raw

Re: Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx()

Quoted 1 line · Siddh Raman Pant via Linux-kernel-mentees

Ping?

context-less pings, on a patch that was sent less than 1 week ago, are usually not a good idea. Normally wait for 2 weeks and then resend if you have not heard anything back.

good luck!

greg k-h

#3 lore raw

Re: Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx()

On Thu, 07 Jul 2022 17:20:56 +0530 Greg KH <[email protected]> wrote

Quoted 10 lines · Siddh Raman Pant via Linux-kernel-mentees
Quoted 1 line

Ping?

context-less pings, on a patch that was sent less than 1 week ago, are usually not a good idea. Normally wait for 2 weeks and then resend if you have not heard anything back.

good luck!

greg k-h

Sorry, I never intended to disturb anyone.

Thanks for informing,
Siddh
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#4 lore raw
In reply to Siddh Raman Pant
Quoted 17 lines · Siddh Raman Pant

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 [email protected]
Reported-by [email protected]
Reported-by [email protected]
Quoted 5 lines
---
 include/net/cfg80211.h | 2 ++
 net/wireless/scan.c    | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

The title should be:

wifi: cfg80211: Fix UAF in ieee80211_scan_rx()

Signature · 7 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#5 lore raw

On Tue, 26 Jul 2022 15:25:06 +0530 Kalle Valo <[email protected]> wrote ---

Quoted 9 lines

The title should be:

wifi: cfg80211: Fix UAF in ieee80211_scan_rx()

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

Noted. Will fix.

Thanks,
Siddh
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#6 lore raw
In reply to Siddh Raman Pant
Quoted 49 lines · Siddh Raman Pant

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 [email protected]
Reported-by [email protected]
Reported-by [email protected]
---
 include/net/cfg80211.h | 2 ++
 net/wireless/scan.c    | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/net/cfg80211.h +2 -0
index 6d02e12e4702..ba4a49884de8 100644
@@ -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[];
net/wireless/scan.c +0 -0
index 6d82bd9eaf8c..638b2805222c 100644

net/wireless/scan.c void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, · line 992

Quoted 6 lines
net/wireless/scan.c +1 -1
@@ -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().

Quoted 6 lines
net/wireless/scan.c +0 -1
        if (!send_message)
--

2.35.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#7 lore raw
Quoted 10 lines · On Tue, 26 Jul 2022 15:37:16 +0530 Eric Dumazet <[email protected]> wrote:

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().

Noted. Due to rcu_dereference() used to get scan_req, null ptr dereference cannot happen. That had completely missed my eyes, sorry for that.

I will send a v2.

Thanks,
Siddh
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees