Skip to content

Commit ae68d93

Browse files
skorpion17kuba-moo
authored andcommitted
seg6: fix the iif in the IPv6 socket control block
When an IPv4 packet is received, the ip_rcv_core(...) sets the receiving interface index into the IPv4 socket control block (v5.16-rc4, net/ipv4/ip_input.c line 510): IPCB(skb)->iif = skb->skb_iif; If that IPv4 packet is meant to be encapsulated in an outer IPv6+SRH header, the seg6_do_srh_encap(...) performs the required encapsulation. In this case, the seg6_do_srh_encap function clears the IPv6 socket control block (v5.16-rc4 net/ipv6/seg6_iptunnel.c line 163): memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); The memset(...) was introduced in commit ef48974 ("ipv6: sr: clear IP6CB(skb) on SRH ip4ip6 encapsulation") a long time ago (2019-01-29). Since the IPv6 socket control block and the IPv4 socket control block share the same memory area (skb->cb), the receiving interface index info is lost (IP6CB(skb)->iif is set to zero). As a side effect, that condition triggers a NULL pointer dereference if commit 0857d6f ("ipv6: When forwarding count rx stats on the orig netdev") is applied. To fix that issue, we set the IP6CB(skb)->iif with the index of the receiving interface once again. Fixes: ef48974 ("ipv6: sr: clear IP6CB(skb) on SRH ip4ip6 encapsulation") Signed-off-by: Andrea Mayer <[email protected]> Reviewed-by: David Ahern <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c56c963 commit ae68d93

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

net/ipv6/seg6_iptunnel.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
161161
hdr->hop_limit = ip6_dst_hoplimit(skb_dst(skb));
162162

163163
memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
164+
165+
/* the control block has been erased, so we have to set the
166+
* iif once again.
167+
* We read the receiving interface index directly from the
168+
* skb->skb_iif as it is done in the IPv4 receiving path (i.e.:
169+
* ip_rcv_core(...)).
170+
*/
171+
IP6CB(skb)->iif = skb->skb_iif;
164172
}
165173

166174
hdr->nexthdr = NEXTHDR_ROUTING;

0 commit comments

Comments
 (0)