Skip to contentSkip to conversation

net: Assert napi_gro_cb size against skb->cb[]

RFC PATCH In review Florian Fainelli 4 participants 5 messages Jul 31, 2015

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

RFC PATCH 1/1 net: Assert napi_gro_cb size against skb->cb[]

On 64-bits hosts, napi_gro_cb is 48 bytes, which is exactly the size of skb->cb[], while on 32-bits hosts it is 36 bytes, but if it were to grow, we would not be catching a size inflation as we should.

Make sure that we have enough room for a napi_gro_cb to be hosted in skb->cb[], and put this build-time assertion in skb_gro_reset_offset() since this function is invoked by the GRO layers entry points.

---
 net/core/dev.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/dev.c +2 -0
index 4870c3556a5a..20bc82604b75 100644
@@ -4115,6 +4115,8 @@ static void skb_gro_reset_offset(struct sk_buff *skb)
 	const struct skb_shared_info *pinfo = skb_shinfo(skb);
 	const skb_frag_t *frag0 = &pinfo->frags[0];
 
+	BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct napi_gro_cb));
+
 	NAPI_GRO_CB(skb)->data_offset = 0;
 	NAPI_GRO_CB(skb)->frag0 = NULL;
 	NAPI_GRO_CB(skb)->frag0_len = 0;
Signature · 1 line
2.1.0
#1 lore raw
Quoted 18 lines · Florian Fainelli

On 64-bits hosts, napi_gro_cb is 48 bytes, which is exactly the size of skb->cb[], while on 32-bits hosts it is 36 bytes, but if it were to grow, we would not be catching a size inflation as we should.

Make sure that we have enough room for a napi_gro_cb to be hosted in skb->cb[], and put this build-time assertion in skb_gro_reset_offset() since this function is invoked by the GRO layers entry points.

---
 net/core/dev.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/dev.c +0 -0
index 4870c3556a5a..20bc82604b75 100644

net/core/dev.c static void skb_gro_reset_offset(struct sk_buff *skb) · line 4119

Quoted 5 lines
net/core/dev.c +2 -0
@@ -4115,6 +4115,8 @@ static void skb_gro_reset_offset(struct sk_buff *skb)
        const struct skb_shared_info *pinfo = skb_shinfo(skb);
        const skb_frag_t *frag0 = &pinfo->frags[0];
 
+       BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct napi_gro_cb));
+

Maybe sizeof(struct napi_gro_cb) > sizeof(skb->cb) since this about napi_gro_cb being too big, not cb being too small.

Quoted 10 lines
net/core/dev.c +0 -1
        NAPI_GRO_CB(skb)->data_offset = 0;
        NAPI_GRO_CB(skb)->frag0 = NULL;
        NAPI_GRO_CB(skb)->frag0_len = 0;
--

2.1.0

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Florian Fainelli
Quoted 12 lines · Florian Fainelli

On 64-bits hosts, napi_gro_cb is 48 bytes, which is exactly the size of skb->cb[], while on 32-bits hosts it is 36 bytes, but if it were to grow, we would not be catching a size inflation as we should.

---
 net/core/dev.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/dev.c +0 -0
index 4870c3556a5a..20bc82604b75 100644

net/core/dev.c static void skb_gro_reset_offset(struct sk_buff *skb) · line 4118

Quoted 4 lines
net/core/dev.c +1 -0
@@ -4115,6 +4115,8 @@ static void skb_gro_reset_offset(struct sk_buff *skb)
 	const struct skb_shared_info *pinfo = skb_shinfo(skb);
 	const skb_frag_t *frag0 = &pinfo->frags[0];
 
+	BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct napi_gro_cb));

commit c3c7c254b2e8cd99b0adf288c2a1bddacd7ba255
already added a check for this.

maintainer
#3 lore raw

From: Florian Westphal <[email protected]>
Date: Fri, 31 Jul 2015 22:24:03 +0200

Quoted 16 lines
Quoted 15 lines · Florian Fainelli

On 64-bits hosts, napi_gro_cb is 48 bytes, which is exactly the size of skb->cb[], while on 32-bits hosts it is 36 bytes, but if it were to grow, we would not be catching a size inflation as we should.

---
 net/core/dev.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/dev.c +0 -0
index 4870c3556a5a..20bc82604b75 100644
@@ -4115,6 +4115,8 @@ static void skb_gro_reset_offset(struct sk_buff *skb)
 	const struct skb_shared_info *pinfo = skb_shinfo(skb);
 	const skb_frag_t *frag0 = &pinfo->frags[0];
 
Quoted 4 lines

net/core/dev.c static void skb_gro_reset_offset(struct sk_buff *skb) · line 4118

Quoted 1 line
net/core/dev.c +1 -0
+	BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct napi_gro_cb));

commit c3c7c254b2e8cd99b0adf288c2a1bddacd7ba255
already added a check for this.

Indeed.

#4 lore raw
Quoted 19 lines · David Miller

From: Florian Westphal <[email protected]>
Date: Fri, 31 Jul 2015 22:24:03 +0200

Quoted 16 lines
Quoted 15 lines · Florian Fainelli

On 64-bits hosts, napi_gro_cb is 48 bytes, which is exactly the size of skb->cb[], while on 32-bits hosts it is 36 bytes, but if it were to grow, we would not be catching a size inflation as we should.

---
 net/core/dev.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/dev.c +0 -0
index 4870c3556a5a..20bc82604b75 100644
@@ -4115,6 +4115,8 @@ static void skb_gro_reset_offset(struct sk_buff *skb)
 	const struct skb_shared_info *pinfo = skb_shinfo(skb);
 	const skb_frag_t *frag0 = &pinfo->frags[0];
 
Quoted 6 lines
Quoted 4 lines

net/core/dev.c static void skb_gro_reset_offset(struct sk_buff *skb) · line 4118

Quoted 1 line
net/core/dev.c +1 -0
+	BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct napi_gro_cb));

commit c3c7c254b2e8cd99b0adf288c2a1bddacd7ba255
already added a check for this.

Indeed.

Whoops, missed that part, thanks Florian!

Signature · 1 line
Florian