wifi: p54: fix incorrect frame length check in p54_find_ie()
PATCH 1/1 wifi: p54: fix incorrect frame length check in p54_find_ie()
In p54_find_ie(), mgmt is a pointer to struct ieee80211_mgmt, so sizeof(mgmt) evaluates to the size of the pointer rather than the size of the management frame header.
Use sizeof(*mgmt) instead so that the skb length is compared against the actual size of the management frame header.
--- drivers/net/wireless/intersil/p54/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/intersil/p54/main.c +1 -1
@@ -76,7 +76,7 @@ u8 *p54_find_ie(struct sk_buff *skb, u8 ie)struct ieee80211_mgmt *mgmt = (void *)skb->data;u8 *pos, *end; -if (skb->len <=sizeof (mgmt)) +if (skb->len <=sizeof (*mgmt))return NULL ; pos = (u8 *)mgmt->u.beacon.variable;
Signature · 1 line
2.25.1
Quoted 8 lines · Wang Yan
In
p54_find_ie(), mgmt is a pointer to structieee80211_mgmt, so sizeof(mgmt) evaluates to the size of the pointer rather than the size of the management frame header.Use
sizeof(*mgmt)instead so that the skb length is compared against the actual size of the management frame header.Fixes 0ac0d6cedf61 ("p54: Move mac80211 glue code")
It's older than that. I traced it back to:
Quoted 10 lines
Signed-off-by Wang Yan <[email protected]>--- drivers/net/wireless/intersil/p54/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/wireless/intersil/p54/main.c +0
-0
drivers/net/wireless/intersil/p54/main.c u8 *p54_find_ie(struct sk_buff *skb, u8 ie) · line 80
Quoted 6 lines
drivers/net/wireless/intersil/p54/main.c +1
-1@@ -76,7 +76,7 @@ u8 *p54_find_ie(struct sk_buff *skb, u8 ie)struct ieee80211_mgmt *mgmt = (void *)skb->data;u8 *pos, *end; -if (skb->len <=sizeof (mgmt)) +if (skb->len <=sizeof (*mgmt))return NULL ;
In theory this check is actually superfluous. Reason being the rest of the code of this function:
| pos = (u8 *)mgmt->u.beacon.variable;
| end = skb->data + skb->len;
| while (pos < end) {
| if (pos + 2 + pos[1] > end)
| return NULL;
|
| if (pos[0] == ie)
| return pos;
|
| pos += 2 + pos[1];
| }
| return NULL;The check in the while loop and the checks within the while loop make sure that no "pos" is returned unless the IE is still within skb->len.
But true, it should have been *mgmt and not mgmt.
So:
That said, if you want to respin and remove this check, I would also ack it.
Quoted 10 lines · Christian Lamparter
Quoted 10 lines
pos = (u8 *)mgmt->u.beacon.variable; end = skb->data + skb->len; while (pos < end) { if (pos + 2 + pos[1] > end) return NULL; if (pos[0] == ie) return pos;
Quoted 8 lines
Quoted 3 lines
pos += 2 + pos[1]; } return NULL;The check in the while loop and the checks within the while loop make sure that no "pos" is returned unless the IE is still within
skb->len.But true, it should have been *mgmt and not mgmt.
FWIW, I dropped it because it really shouldn't have been there this way since 'mgmt' can be far bigger than needed since it contains the union for all kinds of action frames etc.
I'm not even sure it's needed regardless of the next check since the beacon is built by mac80211.
Just blindly patching one mistake for another doesn't help anyone.
johannes
Quoted 20 lines · Johannes Berg
Quoted 10 lines · Christian Lamparter
Quoted 10 lines
pos = (u8 *)mgmt->u.beacon.variable; end = skb->data + skb->len; while (pos < end) { if (pos + 2 + pos[1] > end) return NULL; if (pos[0] == ie) return pos;Quoted 8 lines
Quoted 3 lines
pos += 2 + pos[1]; } return NULL;The check in the while loop and the checks within the while loop make sure that no "pos" is returned unless the IE is still within
skb->len.But true, it should have been *mgmt and not mgmt.
Quoted 8 lines
FWIW, I dropped it because it really shouldn't have been there this way since 'mgmt' can be far bigger than needed since it contains the union for all kinds of action frames etc.
I'm not even sure it's needed regardless of the next check since the beacon is built by mac80211.
Just blindly patching one mistake for another doesn't help anyone.
Ok, alright? I just looked in both:
https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git/
https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless.git/
Was there a patch already? Or did I missread the first sentence that hinted this was "dropped"?
Or do you want that Mr/Ms Yan (Sorry, but from what I was told, the name can be used for both male and female) just post a new patch that removes the superfluous check.
About *mgmt vs mgmt: Yes, you are right. That said, that check came from sometime between ~2006-2008 ;). I don't think the struct back then already contained action frames with sounding/beamforming/timing feedback. Still, I'm totally fine with it being "dropped" too. If there was such a patch posted, please feel free to add a
"Acked-by: Christian Lamparter <[email protected]>" if you merge it.
Cheers,
Christian
Quoted 8 lines · Christian Lamparter
Quoted 8 lines
FWIW, I dropped it because it really shouldn't have been there this way since 'mgmt' can be far bigger than needed since it contains the union for all kinds of action frames etc.
I'm not even sure it's needed regardless of the next check since the beacon is built by mac80211.
Quoted 7 lines
Quoted 1 line
Just blindly patching one mistake for another doesn't help anyone.
Ok, alright? I just looked in both:
https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git/
https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless.git/Was there a patch already? Or did I missread the first sentence that hinted this was "dropped"?
Oh, I didn't phrase that well - I dropped the patch from my queue.
johannes
PATCH v2 1/1 wifi: p54: remove redundant length check in p54_find_ie()
In reply to Christian LamparterThe check in the while loop condition and the bounds check within the loop body guarantee that "pos" is never returned unless the IE is still within skb->len.
Additionally, sizeof(mgmt) evaluates to the pointer size rather than the actual management frame header size, making the check incorrect as well.
Therefore, removing the redundant check is the right fix.
--- drivers/net/wireless/intersil/p54/main.c | 3 --- 1 file changed, 3 deletions(-)
drivers/net/wireless/intersil/p54/main.c +0 -3
@@ -76,9 +76,6 @@ u8 *p54_find_ie(struct sk_buff *skb, u8 ie)struct ieee80211_mgmt *mgmt = (void *)skb->data;u8 *pos, *end; -if (skb->len <=sizeof (mgmt)) -return NULL ; - pos = (u8 *)mgmt->u.beacon.variable; end = skb->data + skb->len;while (pos < end) {
Signature · 1 line
2.25.1
Re: [PATCH v2] wifi: p54: remove redundant length check in p54_find_ie()
Quoted 4 lines · Wang Yan
The check in the while loop condition and the bounds check within the loop body guarantee that "pos" is never returned unless the IE is still within
skb->len.
Quoted 8 lines
Additionally, sizeof(mgmt) evaluates to the pointer size rather than the actual management frame header size, making the check incorrect as well.
Therefore, removing the redundant check is the right fix.
Fixes e5ea92a7528d ("p54: AP & Ad-hoc testing")Signed-off-by Wang Yan <[email protected]>
Quoted 18 lines
--- drivers/net/wireless/intersil/p54/main.c | 3 --- 1 file changed, 3 deletions(-)drivers/net/wireless/intersil/p54/main.c +0
-3@@ -76,9 +76,6 @@ u8 *p54_find_ie(struct sk_buff *skb, u8 ie)struct ieee80211_mgmt *mgmt = (void *)skb->data;u8 *pos, *end; -if (skb->len <=sizeof (mgmt)) -return NULL ; - pos = (u8 *)mgmt->u.beacon.variable; end = skb->data + skb->len;while (pos < end) {
Re: [PATCH] wifi: p54: fix incorrect length check in p54_find_ie()
In reply to Christian LamparterHi Christian,
Thank you for the thorough review and for tracing the issue back to the original commit.
I agree with your analysis. The while loop together with the bounds check inside the loop body already ensures that no IE pointer is returned unless it lies within skb->len, making the initial length check redundant. As you also pointed out, the check itself is incorrect because sizeof(mgmt) evaluates to the pointer size rather than the size of struct ieee80211_mgmt.
I have posted a new patch that removes the superfluous check and updates the Fixes tag to e5ea92a7528d ("p54: AP & Ad‑hoc testing") as you suggested.
Thanks again for the review.
Regards,
Wang Yan