Skip to contentSkip to conversation

tcp: ensure skb->dev is NULL before leaving TCP stack

PATCH In review Eric Dumazet 2 participants 2 messages Mar 19, 2020 – Mar 20, 2020

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

PATCH 1/1 tcp: ensure skb->dev is NULL before leaving TCP stack

skb->rbnode is sharing three skb fields : next, prev, dev

When a packet is sent, TCP keeps the original skb (master) in a rtx queue, which was converted to rbtree a while back.

__tcp_transmit_skb() is responsible to clone the master skb, and add the TCP header to the clone before sending it to network layer.

skb_clone() already clears skb->next and skb->prev, but copies the master oskb->dev into the clone.

We need to clear skb->dev, otherwise lower layers could interpret the value as a pointer to a netdev.

This old bug surfaced recently when commit 28f8bfd1ac94 ("netfilter: Support iif matches in POSTROUTING") was merged.

Before this netfilter commit, skb->dev value was ignored and changed before reaching dev_queue_xmit()

Fixes 75c119afe14f ("tcp: implement rb-tree based retransmit queue")
Fixes 28f8bfd1ac94 ("netfilter: Support iif matches in POSTROUTING")
Cc Florian Westphal <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>
---
 net/ipv4/tcp_output.c | 4 ++++
 1 file changed, 4 insertions(+)
net/ipv4/tcp_output.c +4 -0
index 306e25d743e8de1bfe23d6e3b3a9fb0f23664912..e8cf8fde3d37dc3b455224d33d0bde0e585f989e 100644
@@ -1109,6 +1109,10 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,
 
 		if (unlikely(!skb))
 			return -ENOBUFS;
+		/* retransmit skbs might have a non zero value in skb->dev
+		 * because skb->dev is aliased with skb->rbnode.rb_left
+		 */
+		skb->dev = NULL;
 	}
 
 	inet = inet_sk(sk);
Signature · 1 line
2.25.1.696.g5e7596f4ac-goog
maintainer
#1 lore raw

From: Eric Dumazet <[email protected]>
Date: Thu, 19 Mar 2020 12:49:55 -0700

Quoted 18 lines

skb->rbnode is sharing three skb fields : next, prev, dev

When a packet is sent, TCP keeps the original skb (master) in a rtx queue, which was converted to rbtree a while back.

__tcp_transmit_skb() is responsible to clone the master skb, and add the TCP header to the clone before sending it to network layer.

skb_clone() already clears skb->next and skb->prev, but copies the master oskb->dev into the clone.

We need to clear skb->dev, otherwise lower layers could interpret the value as a pointer to a netdev.

This old bug surfaced recently when commit 28f8bfd1ac94 ("netfilter: Support iif matches in POSTROUTING") was merged.

Quoted 7 lines

Before this netfilter commit, skb->dev value was ignored and changed before reaching dev_queue_xmit()

Fixes 75c119afe14f ("tcp: implement rb-tree based retransmit queue")
Fixes 28f8bfd1ac94 ("netfilter: Support iif matches in POSTROUTING")

Applied and queued up for -stable, thanks Eric.