Skip to contentSkip to conversation

brcmfmac: Don't grow SKB by negative size

PATCH Superseded Daniel Stone 4 participants 8 messages Jul 26, 2017 – Jul 27, 2017 Broadcom BRCM80211 IEEE802.11 wireless drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 brcmfmac: Don't grow SKB by negative size

The commit to rework the headroom check in start_xmit() now calls pxskb_expand_head() unconditionally if the header is CoW. Unfortunately, it does so with the delta between the extant headroom and the header length, which may be negative if there is already sufficient headroom.

pskb_expand_head() does allow for size being 0, in which case it just copies, so clamp the header delta to zero.

Opening Chrome (and all my tabs) on a PCIE device was enough to reliably hit this.

Fixes 270a6c1f65fe ("brcmfmac: rework headroom check in .start_xmit()")
Cc Arend Van Spriel <[email protected]>
Cc James Hughes <[email protected]>
Cc Hante Meuleman <[email protected]>
Cc Pieter-Paul Giesberts <[email protected]>
Cc Franky Lin <[email protected]>
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c | 1 +
 1 file changed, 1 insertion(+)

Really sorry, I forgot to re-run format-patch after fixing the initial patch. I've run out of coffee. :(

drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +1 -0
index 2153e8062b4c..42dbd5a8c220 100644
@@ -215,6 +215,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
 	/* Make sure there's enough writeable headroom */
 	if (skb_headroom(skb) < drvr->hdrlen || skb_header_cloned(skb)) {
 		head_delta = drvr->hdrlen - skb_headroom(skb);
+		head_delta = max(head_delta, 0);
 
 		brcmf_dbg(INFO, "%s: insufficient headroom (%d)\n",
 			  brcmf_ifname(ifp), head_delta);
Signature · 1 line
2.13.2
maintainer
#1 lore raw
Quoted 18 lines · Daniel Stone

The commit to rework the headroom check in start_xmit() now calls pxskb_expand_head() unconditionally if the header is CoW. Unfortunately, it does so with the delta between the extant headroom and the header length, which may be negative if there is already sufficient headroom.

pskb_expand_head() does allow for size being 0, in which case it just copies, so clamp the header delta to zero.

Opening Chrome (and all my tabs) on a PCIE device was enough to reliably hit this.

Fixes 270a6c1f65fe ("brcmfmac: rework headroom check in .start_xmit()")
Cc Arend Van Spriel <[email protected]>
Cc James Hughes <[email protected]>
Cc Hante Meuleman <[email protected]>
Cc Pieter-Paul Giesberts <[email protected]>
Cc Franky Lin <[email protected]>
Quoted 6 lines
---
  drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c | 1 +
  1 file changed, 1 insertion(+)

Really sorry, I forgot to re-run format-patch after fixing the initial patch. I've run out of coffee. :(

Sufficient coffee over here so I have no excuse. You are obviously right. Please tag this patch for 4.13, ie.:

[PATCH for-4.13 V3] brcmfmac: ....

drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb, · line 218

Quoted 9 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +1 -0
index 2153e8062b4c..42dbd5a8c220 100644
@@ -215,6 +215,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
  	/* Make sure there's enough writeable headroom */
  	if (skb_headroom(skb) < drvr->hdrlen || skb_header_cloned(skb)) {
  		head_delta = drvr->hdrlen - skb_headroom(skb);
+		head_delta = max(head_delta, 0);

minor nit, but can you make it:
- head_delta = drvr->hdrlen - skb_headroom(skb);
+ head_delta = max(drvr->hdrlen - skb_headroom(skb), 0);

Regards,
Arend

#2 lore raw

PATCH v3 1/1 brcmfmac: Don't grow SKB by negative size

In reply to Daniel Stone

The commit to rework the headroom check in start_xmit() now calls pxskb_expand_head() unconditionally if the header is CoW. Unfortunately, it does so with the delta between the extant headroom and the header length, which may be negative if there is already sufficient headroom.

pskb_expand_head() does allow for size being 0, in which case it just copies, so clamp the header delta to zero.

Opening Chrome (and all my tabs) on a PCIE device was enough to reliably hit this.

Fixes 270a6c1f65fe ("brcmfmac: rework headroom check in .start_xmit()")
Cc Arend Van Spriel <[email protected]>
Cc James Hughes <[email protected]>
Cc Hante Meuleman <[email protected]>
Cc Pieter-Paul Giesberts <[email protected]>
Cc Franky Lin <[email protected]>
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

v2: Correct thinko.
v3: Bring assignment on to one line.

Thanks for the quick response Arend. It's not quite as simple as the form you suggested, since both hdrlen and skb_headroom() are unsigned, so it needs need an explicit cast to signed, which was previously implicit from the head_delta lvalue.

drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +1 -1
index 2153e8062b4c..0b7db8798214 100644
@@ -214,7 +214,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
 
 	/* Make sure there's enough writeable headroom */
 	if (skb_headroom(skb) < drvr->hdrlen || skb_header_cloned(skb)) {
-		head_delta = drvr->hdrlen - skb_headroom(skb);
+		head_delta = max((int) (drvr->hdrlen - skb_headroom(skb)), 0);
 
 		brcmf_dbg(INFO, "%s: insufficient headroom (%d)\n",
 			  brcmf_ifname(ifp), head_delta);
Signature · 1 line
2.13.2
maintainer
#3 lore raw
Quoted 22 lines · Daniel Stone

The commit to rework the headroom check in start_xmit() now calls pxskb_expand_head() unconditionally if the header is CoW. Unfortunately, it does so with the delta between the extant headroom and the header length, which may be negative if there is already sufficient headroom.

pskb_expand_head() does allow for size being 0, in which case it just copies, so clamp the header delta to zero.

Opening Chrome (and all my tabs) on a PCIE device was enough to reliably hit this.

Fixes 270a6c1f65fe ("brcmfmac: rework headroom check in .start_xmit()")
Cc Arend Van Spriel <[email protected]>
Cc James Hughes <[email protected]>
Cc Hante Meuleman <[email protected]>
Cc Pieter-Paul Giesberts <[email protected]>
Cc Franky Lin <[email protected]>
---
  drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines

v2: Correct thinko.
v3: Bring assignment on to one line.

Thanks for the quick response Arend. It's not quite as simple as the form you suggested, since both hdrlen and skb_headroom() are unsigned, so it needs need an explicit cast to signed, which was previously implicit from the head_delta lvalue.

Oops. That makes me realize that use of max_t() is preferred which would take care of it.

Thanks,
Arend

Quoted 14 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +1 -1
index 2153e8062b4c..0b7db8798214 100644
@@ -214,7 +214,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
 
  	/* Make sure there's enough writeable headroom */
  	if (skb_headroom(skb) < drvr->hdrlen || skb_header_cloned(skb)) {
-		head_delta = drvr->hdrlen - skb_headroom(skb);
+		head_delta = max((int) (drvr->hdrlen - skb_headroom(skb)), 0);
 
  		brcmf_dbg(INFO, "%s: insufficient headroom (%d)\n",
  			  brcmf_ifname(ifp), head_delta);
#4 lore raw

PATCH v4 1/1 brcmfmac: Don't grow SKB by negative size

In reply to Daniel Stone

The commit to rework the headroom check in start_xmit() now calls pxskb_expand_head() unconditionally if the header is CoW. Unfortunately, it does so with the delta between the extant headroom and the header length, which may be negative if there is already sufficient headroom.

pskb_expand_head() does allow for size being 0, in which case it just copies, so clamp the header delta to zero.

Opening Chrome (and all my tabs) on a PCIE device was enough to reliably hit this.

Fixes 270a6c1f65fe ("brcmfmac: rework headroom check in .start_xmit()")
Cc Arend Van Spriel <[email protected]>
Cc James Hughes <[email protected]>
Cc Hante Meuleman <[email protected]>
Cc Pieter-Paul Giesberts <[email protected]>
Cc Franky Lin <[email protected]>
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

v2: Correct thinko.
v3: Bring assignment on to one line.
v4: Use max_t rather than max.

drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +1 -1
index 2153e8062b4c..5cc3a07dda9e 100644
@@ -214,7 +214,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
 
 	/* Make sure there's enough writeable headroom */
 	if (skb_headroom(skb) < drvr->hdrlen || skb_header_cloned(skb)) {
-		head_delta = drvr->hdrlen - skb_headroom(skb);
+		head_delta = max_t(int, drvr->hdrlen - skb_headroom(skb), 0);
 
 		brcmf_dbg(INFO, "%s: insufficient headroom (%d)\n",
 			  brcmf_ifname(ifp), head_delta);
Signature · 1 line
2.13.2
Tested-by on v4 1/1
#5 lore raw

Hi,

Quoted 18 lines · Daniel Stone

The commit to rework the headroom check in start_xmit() now calls pxskb_expand_head() unconditionally if the header is CoW. Unfortunately, it does so with the delta between the extant headroom and the header length, which may be negative if there is already sufficient headroom.

pskb_expand_head() does allow for size being 0, in which case it just copies, so clamp the header delta to zero.

Opening Chrome (and all my tabs) on a PCIE device was enough to reliably hit this.

Fixes 270a6c1f65fe ("brcmfmac: rework headroom check in .start_xmit()")
Cc Arend Van Spriel <[email protected]>
Cc James Hughes <[email protected]>
Cc Hante Meuleman <[email protected]>
Cc Pieter-Paul Giesberts <[email protected]>
Cc Franky Lin <[email protected]>
Quoted 7 lines
---
  drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

v2: Correct thinko.
v3: Bring assignment on to one line.
v4: Use max_t rather than max.

I can confirm that this fixes a brcmfmac kernel panic for me:

Regards,

Hans

Quoted 15 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +1 -1
index 2153e8062b4c..5cc3a07dda9e 100644
@@ -214,7 +214,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
 
  	/* Make sure there's enough writeable headroom */
  	if (skb_headroom(skb) < drvr->hdrlen || skb_header_cloned(skb)) {
-		head_delta = drvr->hdrlen - skb_headroom(skb);
+		head_delta = max_t(int, drvr->hdrlen - skb_headroom(skb), 0);
 
  		brcmf_dbg(INFO, "%s: insufficient headroom (%d)\n",
  			  brcmf_ifname(ifp), head_delta);
#6 lore raw
In reply to Daniel Stone
Quoted 11 lines · Daniel Stone

The commit to rework the headroom check in start_xmit() now calls pxskb_expand_head() unconditionally if the header is CoW. Unfortunately, it does so with the delta between the extant headroom and the header length, which may be negative if there is already sufficient headroom.

pskb_expand_head() does allow for size being 0, in which case it just copies, so clamp the header delta to zero.

Opening Chrome (and all my tabs) on a PCIE device was enough to reliably hit this.

Quoted 7 lines
Fixes 270a6c1f65fe ("brcmfmac: rework headroom check in .start_xmit()")
Cc Arend Van Spriel <[email protected]>
Cc James Hughes <[email protected]>
Cc Hante Meuleman <[email protected]>
Cc Pieter-Paul Giesberts <[email protected]>
Cc Franky Lin <[email protected]>

I'll queue this for 4.13.

Signature · 1 line
Kalle Valo
#7 lore raw
In reply to Daniel Stone
Quoted 11 lines · Daniel Stone

The commit to rework the headroom check in start_xmit() now calls pxskb_expand_head() unconditionally if the header is CoW. Unfortunately, it does so with the delta between the extant headroom and the header length, which may be negative if there is already sufficient headroom.

pskb_expand_head() does allow for size being 0, in which case it just copies, so clamp the header delta to zero.

Opening Chrome (and all my tabs) on a PCIE device was enough to reliably hit this.

Quoted 8 lines
Fixes 270a6c1f65fe ("brcmfmac: rework headroom check in .start_xmit()")
Cc Arend Van Spriel <[email protected]>
Cc James Hughes <[email protected]>
Cc Hante Meuleman <[email protected]>
Cc Pieter-Paul Giesberts <[email protected]>
Cc Franky Lin <[email protected]>

Patch applied to wireless-drivers.git, thanks.

58f36b4526ad brcmfmac: Don't grow SKB by negative size

Signature · 3 lines
https://patchwork.kernel.org/patch/9864575/

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