Skip to contentSkip to conversation

net: test tailroom before appending to linear skb

PATCH Superseded Willem de Bruijn 2 participants 4 messages May 17, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: test tailroom before appending to linear skb

From: Willem de Bruijn <[email protected]>

Device features may change during transmission. In particular with corking, a device may toggle scatter-gather in between allocating and writing to an skb.

Do not unconditionally assume that !NETIF_F_SG at write time implies that the same held at alloc time and thus the skb has sufficient tailroom.

This issue predates git history.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/ipv4/ip_output.c  | 3 ++-
 net/ipv6/ip6_output.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/ip_output.c +2 -1
index 83c73bab2c3d..c15204ec2eb0 100644
@@ -1045,7 +1045,8 @@ static int __ip_append_data(struct sock *sk,
 		if (copy > length)
 			copy = length;
 
-		if (!(rt->dst.dev->features&NETIF_F_SG)) {
+		if (!(rt->dst.dev->features&NETIF_F_SG) &&
+		    skb_tailroom(skb) > copy) {
 			unsigned int off;
 
 			off = skb->len;
net/ipv6/ip6_output.c +2 -1
index 2e891d2c30ef..7b6d1689087b 100644
@@ -1503,7 +1503,8 @@ static int __ip6_append_data(struct sock *sk,
 		if (copy > length)
 			copy = length;
 
-		if (!(rt->dst.dev->features&NETIF_F_SG)) {
+		if (!(rt->dst.dev->features&NETIF_F_SG) &&
+		    skb_tailroom(skb) >= copy) {
 			unsigned int off;
 
 			off = skb->len;
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Device features may change during transmission. In particular with corking, a device may toggle scatter-gather in between allocating and writing to an skb.

Do not unconditionally assume that !NETIF_F_SG at write time implies that the same held at alloc time and thus the skb has sufficient tailroom.

Quoted 5 lines

This issue predates git history.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

Excellent, thanks Willem.

#2 lore raw
In reply to Willem de Bruijn
Quoted 25 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Device features may change during transmission. In particular with corking, a device may toggle scatter-gather in between allocating and writing to an skb.

Do not unconditionally assume that !NETIF_F_SG at write time implies that the same held at alloc time and thus the skb has sufficient tailroom.

This issue predates git history.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/ipv4/ip_output.c  | 3 ++-
 net/ipv6/ip6_output.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/ip_output.c +0 -0
index 83c73bab2c3d..c15204ec2eb0 100644

net/ipv4/ip_output.c static int __ip_append_data(struct sock *sk, · line 1049

Quoted 6 lines
net/ipv4/ip_output.c +2 -1
@@ -1045,7 +1045,8 @@ static int __ip_append_data(struct sock *sk,
 		if (copy > length)
 			copy = length;
 
-		if (!(rt->dst.dev->features&NETIF_F_SG)) {
+		if (!(rt->dst.dev->features&NETIF_F_SG) &&
+		    skb_tailroom(skb) > copy) {

On second thought, maybe use >= for the test ?

Quoted 18 lines
net/ipv4/ip_output.c +0 -0
 			unsigned int off;
 
 			off = skb->len;
net/ipv6/ip6_output.c +2 -1
index 2e891d2c30ef..7b6d1689087b 100644
@@ -1503,7 +1503,8 @@ static int __ip6_append_data(struct sock *sk,
 		if (copy > length)
 			copy = length;
 
-		if (!(rt->dst.dev->features&NETIF_F_SG)) {
+		if (!(rt->dst.dev->features&NETIF_F_SG) &&
+		    skb_tailroom(skb) >= copy) {
 			unsigned int off;
 
 			off = skb->len;
#3 lore raw
Quoted 31 lines · Eric Dumazet
Quoted 28 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Device features may change during transmission. In particular with corking, a device may toggle scatter-gather in between allocating and writing to an skb.

Do not unconditionally assume that !NETIF_F_SG at write time implies that the same held at alloc time and thus the skb has sufficient tailroom.

This issue predates git history.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/ipv4/ip_output.c  | 3 ++-
 net/ipv6/ip6_output.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/ip_output.c +0 -0
index 83c73bab2c3d..c15204ec2eb0 100644
@@ -1045,7 +1045,8 @@ static int __ip_append_data(struct sock *sk,
              if (copy > length)
                      copy = length;
 
Quoted 5 lines

net/ipv4/ip_output.c static int __ip_append_data(struct sock *sk, · line 1049

Quoted 3 lines
net/ipv4/ip_output.c +2 -1
-             if (!(rt->dst.dev->features&NETIF_F_SG)) {
+             if (!(rt->dst.dev->features&NETIF_F_SG) &&
+                 skb_tailroom(skb) > copy) {

On second thought, maybe use >= for the test ?

Ai, yes of course. Will send a v2.