All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: Fix UAF in ieee80211_scan_rx()
@ 2022-07-01 14:54 ` Siddh Raman Pant
  0 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant @ 2022-07-01 14:54 UTC (permalink / raw)
  To: Johannes Berg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: linux-wireless, netdev, linux-kernel, linux-kernel-mentees

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 <code@siddh.me>
---
 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



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH] net: Fix UAF in ieee80211_scan_rx()
@ 2022-07-01 14:54 ` Siddh Raman Pant
  0 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant @ 2022-07-01 14:54 UTC (permalink / raw)
  To: Johannes Berg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-wireless, linux-kernel, linux-kernel-mentees

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 <code@siddh.me>
---
 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


_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx()
  2022-07-01 14:54 ` Siddh Raman Pant
@ 2022-07-07 11:36   ` Siddh Raman Pant
  -1 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant via Linux-kernel-mentees @ 2022-07-07 11:36 UTC (permalink / raw)
  To: Johannes Berg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-wireless, linux-kernel, linux-kernel-mentees

Ping?

On Fri, 01 Jul 2022 20:24:23 +0530  Siddh Raman Pant <code@siddh.me> 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 <code@siddh.me>
> ---
>  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
>

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx()
@ 2022-07-07 11:36   ` Siddh Raman Pant
  0 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant @ 2022-07-07 11:36 UTC (permalink / raw)
  To: Johannes Berg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: linux-wireless, netdev, linux-kernel, linux-kernel-mentees

Ping?

On Fri, 01 Jul 2022 20:24:23 +0530  Siddh Raman Pant <code@siddh.me> 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 <code@siddh.me>
> ---
>  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
>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx()
  2022-07-07 11:36   ` Siddh Raman Pant
@ 2022-07-07 11:50     ` Greg KH
  -1 siblings, 0 replies; 16+ messages in thread
From: Greg KH @ 2022-07-07 11:50 UTC (permalink / raw)
  To: Siddh Raman Pant
  Cc: Johannes Berg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-wireless, linux-kernel,
	linux-kernel-mentees

On Thu, Jul 07, 2022 at 05:06:35PM +0530, Siddh Raman Pant via Linux-kernel-mentees wrote:
> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx()
@ 2022-07-07 11:50     ` Greg KH
  0 siblings, 0 replies; 16+ messages in thread
From: Greg KH @ 2022-07-07 11:50 UTC (permalink / raw)
  To: Siddh Raman Pant
  Cc: netdev, linux-wireless, linux-kernel, Eric Dumazet,
	Jakub Kicinski, Johannes Berg, Paolo Abeni, linux-kernel-mentees,
	David S . Miller

On Thu, Jul 07, 2022 at 05:06:35PM +0530, Siddh Raman Pant via Linux-kernel-mentees wrote:
> 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
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx()
  2022-07-07 11:50     ` Greg KH
@ 2022-07-07 11:59       ` Siddh Raman Pant
  -1 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant via Linux-kernel-mentees @ 2022-07-07 11:59 UTC (permalink / raw)
  To: Greg KH
  Cc: netdev, linux-wireless, linux-kernel, Eric Dumazet,
	Jakub Kicinski, Johannes Berg, Paolo Abeni, linux-kernel-mentees,
	David S . Miller

On Thu, 07 Jul 2022 17:20:56 +0530  Greg KH <gregkh@linuxfoundation.org> wrote
> On Thu, Jul 07, 2022 at 05:06:35PM +0530, Siddh Raman Pant via Linux-kernel-mentees wrote:
> > 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
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Ping: [PATCH] net: Fix UAF in ieee80211_scan_rx()
@ 2022-07-07 11:59       ` Siddh Raman Pant
  0 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant @ 2022-07-07 11:59 UTC (permalink / raw)
  To: Greg KH
  Cc: Johannes Berg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-wireless, linux-kernel,
	linux-kernel-mentees

On Thu, 07 Jul 2022 17:20:56 +0530  Greg KH <gregkh@linuxfoundation.org> wrote
> On Thu, Jul 07, 2022 at 05:06:35PM +0530, Siddh Raman Pant via Linux-kernel-mentees wrote:
> > 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] net: Fix UAF in ieee80211_scan_rx()
  2022-07-01 14:54 ` Siddh Raman Pant
@ 2022-07-26  9:55   ` Kalle Valo
  -1 siblings, 0 replies; 16+ messages in thread
From: Kalle Valo @ 2022-07-26  9:55 UTC (permalink / raw)
  To: Siddh Raman Pant
  Cc: netdev, linux-wireless, linux-kernel, Eric Dumazet,
	Jakub Kicinski, Johannes Berg, Paolo Abeni, linux-kernel-mentees,
	David S . Miller

Siddh Raman Pant <code@siddh.me> writes:

> 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 <code@siddh.me>
> ---
>  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()

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] net: Fix UAF in ieee80211_scan_rx()
@ 2022-07-26  9:55   ` Kalle Valo
  0 siblings, 0 replies; 16+ messages in thread
From: Kalle Valo @ 2022-07-26  9:55 UTC (permalink / raw)
  To: Siddh Raman Pant
  Cc: Johannes Berg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-wireless, netdev, linux-kernel,
	linux-kernel-mentees

Siddh Raman Pant <code@siddh.me> writes:

> 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 <code@siddh.me>
> ---
>  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()

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] net: Fix UAF in ieee80211_scan_rx()
  2022-07-01 14:54 ` Siddh Raman Pant
@ 2022-07-26 10:07   ` Eric Dumazet via Linux-kernel-mentees
  -1 siblings, 0 replies; 16+ messages in thread
From: Eric Dumazet @ 2022-07-26 10:07 UTC (permalink / raw)
  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

On Fri, Jul 1, 2022 at 4:55 PM Siddh Raman Pant <code@siddh.me> 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 <code@siddh.me>
> ---
>  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
>
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] net: Fix UAF in ieee80211_scan_rx()
@ 2022-07-26 10:07   ` Eric Dumazet via Linux-kernel-mentees
  0 siblings, 0 replies; 16+ messages in thread
From: Eric Dumazet via Linux-kernel-mentees @ 2022-07-26 10:07 UTC (permalink / raw)
  To: Siddh Raman Pant
  Cc: Paul E. McKenney, netdev, linux-wireless, linux-kernel,
	Jakub Kicinski, Johannes Berg, Paolo Abeni, linux-kernel-mentees,
	David S . Miller

On Fri, Jul 1, 2022 at 4:55 PM Siddh Raman Pant <code@siddh.me> 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 <code@siddh.me>
> ---
>  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
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] net: Fix UAF in ieee80211_scan_rx()
  2022-07-26  9:55   ` Kalle Valo
@ 2022-07-26 11:50     ` Siddh Raman Pant via Linux-kernel-mentees
  -1 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant @ 2022-07-26 11:50 UTC (permalink / raw)
  To: Kalle Valo
  Cc: Johannes Berg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-wireless, netdev, linux-kernel,
	linux-kernel-mentees

On Tue, 26 Jul 2022 15:25:06 +0530  Kalle Valo <kvalo@kernel.org> wrote --- 
> The title should be:
> 
> wifi: cfg80211: Fix UAF in ieee80211_scan_rx()
> 
> -- 
> https://patchwork.kernel.org/project/linux-wireless/list/
> 
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
> 

Noted. Will fix.

Thanks,
Siddh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] net: Fix UAF in ieee80211_scan_rx()
@ 2022-07-26 11:50     ` Siddh Raman Pant via Linux-kernel-mentees
  0 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant via Linux-kernel-mentees @ 2022-07-26 11:50 UTC (permalink / raw)
  To: Kalle Valo
  Cc: netdev, linux-wireless, linux-kernel, Eric Dumazet,
	Jakub Kicinski, Johannes Berg, Paolo Abeni, linux-kernel-mentees,
	David S . Miller

On Tue, 26 Jul 2022 15:25:06 +0530  Kalle Valo <kvalo@kernel.org> wrote --- 
> The title should be:
> 
> wifi: cfg80211: Fix UAF in ieee80211_scan_rx()
> 
> -- 
> 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
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] net: Fix UAF in ieee80211_scan_rx()
  2022-07-26 10:07   ` Eric Dumazet via Linux-kernel-mentees
@ 2022-07-26 12:16     ` Siddh Raman Pant
  -1 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant via Linux-kernel-mentees @ 2022-07-26 12:16 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Paul E. McKenney, netdev, linux-wireless, linux-kernel,
	Jakub Kicinski, Johannes Berg, Paolo Abeni, linux-kernel-mentees,
	David S . Miller

On Tue, 26 Jul 2022 15:37:16 +0530  Eric Dumazet <edumazet@google.com> 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
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] net: Fix UAF in ieee80211_scan_rx()
@ 2022-07-26 12:16     ` Siddh Raman Pant
  0 siblings, 0 replies; 16+ messages in thread
From: Siddh Raman Pant @ 2022-07-26 12:16 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Johannes Berg, David S . Miller, Jakub Kicinski, Paolo Abeni,
	linux-wireless, netdev, linux-kernel, linux-kernel-mentees,
	Paul E. McKenney

On Tue, 26 Jul 2022 15:37:16 +0530  Eric Dumazet <edumazet@google.com> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-07-26 12:17 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01 14:54 [PATCH] net: Fix UAF in ieee80211_scan_rx() Siddh Raman Pant
2022-07-01 14:54 ` Siddh Raman Pant
2022-07-07 11:36 ` Ping: " Siddh Raman Pant via Linux-kernel-mentees
2022-07-07 11:36   ` Siddh Raman Pant
2022-07-07 11:50   ` Greg KH
2022-07-07 11:50     ` Greg KH
2022-07-07 11:59     ` Siddh Raman Pant via Linux-kernel-mentees
2022-07-07 11:59       ` Siddh Raman Pant
2022-07-26  9:55 ` Kalle Valo
2022-07-26  9:55   ` Kalle Valo
2022-07-26 11:50   ` Siddh Raman Pant
2022-07-26 11:50     ` Siddh Raman Pant via Linux-kernel-mentees
2022-07-26 10:07 ` Eric Dumazet
2022-07-26 10:07   ` Eric Dumazet via Linux-kernel-mentees
2022-07-26 12:16   ` Siddh Raman Pant via Linux-kernel-mentees
2022-07-26 12:16     ` Siddh Raman Pant

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.