diff mbox series

[net] ipv4: ip_do_fragment: Preserve skb_iif during fragmentation

Message ID 20190429133930.6287-1-shmulik.ladkani@gmail.com
State Accepted
Delegated to: David Miller
Headers show
Series [net] ipv4: ip_do_fragment: Preserve skb_iif during fragmentation | expand

Commit Message

Shmulik Ladkani April 29, 2019, 1:39 p.m. UTC
Previously, during fragmentation after forwarding, skb->skb_iif isn't
preserved, i.e. 'ip_copy_metadata' does not copy skb_iif from given
'from' skb.

As a result, ip_do_fragment's creates fragments with zero skb_iif,
leading to inconsistent behavior.

Assume for example an eBPF program attached at tc egress (post
forwarding) that examines __sk_buff->ingress_ifindex:
 - the correct iif is observed if forwarding path does not involve
   fragmentation/refragmentation
 - a bogus iif is observed if forwarding path involves
   fragmentation/refragmentatiom

Fix, by preserving skb_iif during 'ip_copy_metadata'.

Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
---
 net/ipv4/ip_output.c | 1 +
 1 file changed, 1 insertion(+)

Comments

David Miller May 1, 2019, 5:29 p.m. UTC | #1
From: Shmulik Ladkani <shmulik@metanetworks.com>
Date: Mon, 29 Apr 2019 16:39:30 +0300

> Previously, during fragmentation after forwarding, skb->skb_iif isn't
> preserved, i.e. 'ip_copy_metadata' does not copy skb_iif from given
> 'from' skb.
> 
> As a result, ip_do_fragment's creates fragments with zero skb_iif,
> leading to inconsistent behavior.
> 
> Assume for example an eBPF program attached at tc egress (post
> forwarding) that examines __sk_buff->ingress_ifindex:
>  - the correct iif is observed if forwarding path does not involve
>    fragmentation/refragmentation
>  - a bogus iif is observed if forwarding path involves
>    fragmentation/refragmentatiom
> 
> Fix, by preserving skb_iif during 'ip_copy_metadata'.
> 
> Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>

Applied and queued up for -stable.
diff mbox series

Patch

diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 4e42c1974ba2..ac880beda8a7 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -516,6 +516,7 @@  static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from)
 	to->pkt_type = from->pkt_type;
 	to->priority = from->priority;
 	to->protocol = from->protocol;
+	to->skb_iif = from->skb_iif;
 	skb_dst_drop(to);
 	skb_dst_copy(to, from);
 	to->dev = from->dev;