All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mac80211: mlme: check for null after calling kmemdup
@ 2021-12-31 10:03 Jiasheng Jiang
  2022-01-04 14:00 ` Johannes Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2021-12-31 10:03 UTC (permalink / raw)
  To: johannes, davem, kuba
  Cc: linux-wireless, netdev, linux-kernel, Jiasheng Jiang

As the possible failure of the alloc, the ifmgd->assoc_req_ies might be
NULL pointer and will be used by cfg80211_rx_assoc_resp() with the wrong
length.
Therefore it might be better to set length to 0 if fails as same as
ieee80211_mgd_stop().

Fixes: 4d9ec73d2b78 ("cfg80211: Report Association Request frame IEs in association events")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 net/mac80211/mlme.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 9bed6464c5bd..258b492c699c 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -1058,7 +1058,10 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
 	pos = skb_tail_pointer(skb);
 	kfree(ifmgd->assoc_req_ies);
 	ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
-	ifmgd->assoc_req_ies_len = pos - ie_start;
+	if (!ifmgd->assoc_req_ies)
+		ifmgd->assoc_req_ies_len = 0;
+	else
+		ifmgd->assoc_req_ies_len = pos - ie_start;
 
 	drv_mgd_prepare_tx(local, sdata, 0);
 
-- 
2.25.1


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

* Re: [PATCH] mac80211: mlme: check for null after calling kmemdup
  2021-12-31 10:03 [PATCH] mac80211: mlme: check for null after calling kmemdup Jiasheng Jiang
@ 2022-01-04 14:00 ` Johannes Berg
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Berg @ 2022-01-04 14:00 UTC (permalink / raw)
  To: Jiasheng Jiang, davem, kuba; +Cc: linux-wireless, netdev, linux-kernel

On Fri, 2021-12-31 at 18:03 +0800, Jiasheng Jiang wrote:
> As the possible failure of the alloc, the ifmgd->assoc_req_ies might be
> NULL pointer and will be used by cfg80211_rx_assoc_resp() with the wrong
> length.
> Therefore it might be better to set length to 0 if fails as same as
> ieee80211_mgd_stop().
> 

That feels a bit vague, and indeed I cannot find any place that would
actually dereference the pointer if it's NULL?

Still maybe a good as a cleanup.

> Fixes: 4d9ec73d2b78 ("cfg80211: Report Association Request frame IEs in association events")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  net/mac80211/mlme.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
> index 9bed6464c5bd..258b492c699c 100644
> --- a/net/mac80211/mlme.c
> +++ b/net/mac80211/mlme.c
> @@ -1058,7 +1058,10 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
>  	pos = skb_tail_pointer(skb);
>  	kfree(ifmgd->assoc_req_ies);
>  	ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
> -	ifmgd->assoc_req_ies_len = pos - ie_start;
> +	if (!ifmgd->assoc_req_ies)
> +		ifmgd->assoc_req_ies_len = 0;
> +	else
> +		ifmgd->assoc_req_ies_len = pos - ie_start;
> 

But it seems it would be better to actually fail the association in this
case? There's a reason we're reporting this, so that we can see
HT/VHT/..., and I'm sure that will be necessary in many cases.

johannes

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

end of thread, other threads:[~2022-01-04 14:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31 10:03 [PATCH] mac80211: mlme: check for null after calling kmemdup Jiasheng Jiang
2022-01-04 14:00 ` Johannes Berg

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.