Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: lxc: fix L4 offset in RevNAT path for IPv6 extension headers #27312

Merged

Conversation

julianwiedmann
Copy link
Member

@julianwiedmann julianwiedmann commented Aug 7, 2023

The typical pattern to determine the L4 offset of an IPv6 packet is

tuple->nexthdr = ip6->nexthdr;
hdrlen = ipv6_hdrlen(ctx, &tuple->nexthdr);
if (hdrlen < 0)
	return hdrlen;
l4_off = ETH_HLEN + hdrlen;

ipv6_hdrlen() then walks the extension headers and adds up their length, until it reaches the TCP/UDP/... header.

For bpf_lxc, 38b4a61 ("bpf: Split CT lookup to its own tail call") split off the CT lookup into a separate tail-call. Subsequent code retrieves the lookup result and a fully populated CT tuple from the CT_TAIL_CALL_BUFFER6.

For the IPv6 paths this means that tuple->nexthdr already contains the L4 proto. When ipv6_hdrlen() is called a second time with this value, it believes that the packet has no extension headers and returns a wrong L4 offset.

Go for the minimal fix and re-initialize tuple->nexthdr in the affected paths.

Fix a bug that affected the RevDNAT translation of IPv6 packets with extension headers.

The typical pattern to determine the L4 offset of an IPv6 packet is

	tuple->nexthdr = ip6->nexthdr;
	hdrlen = ipv6_hdrlen(ctx, &tuple->nexthdr);
	if (hdrlen < 0)
		return hdrlen;
	l4_off = ETH_HLEN + hdrlen;

ipv6_hdrlen() then walks the extension headers and adds up their length,
until it reaches the TCP/UDP/... header.

For bpf_lxc, 38b4a61 ("bpf: Split CT lookup to its own tail call")
split off the CT lookup into a separate tail-call. Subsequent code
retrieves the lookup result and a fully populated CT tuple from the
CT_TAIL_CALL_BUFFER6.

For the IPv6 paths this means that tuple->nexthdr already contains the
L4 proto. When ipv6_hdrlen() is called a second time with this value, it
believes that the packet has no extension headers and returns a wrong
L4 offset.

Go for the minimal fix and re-initialize tuple->nexthdr in the affected
paths.

Fixes: 38b4a61 ("bpf: Split CT lookup to its own tail call")
Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
@julianwiedmann julianwiedmann added kind/bug This is a bug in the Cilium logic. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/bug This PR fixes an issue in a previous release of Cilium. feature/ipv6 Relates to IPv6 protocol support area/loadbalancing Impacts load-balancing and Kubernetes service implementations needs-backport/1.12 needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch needs-backport/1.14 This PR / issue needs backporting to the v1.14 branch labels Aug 7, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.14.1 Aug 7, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.13.6 Aug 7, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.12.13 Aug 7, 2023
@julianwiedmann
Copy link
Member Author

/test

@julianwiedmann julianwiedmann marked this pull request as ready for review August 7, 2023 07:49
@julianwiedmann julianwiedmann requested a review from a team as a code owner August 7, 2023 07:49
Copy link
Member

@jschwinger233 jschwinger233 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Aug 8, 2023
@julianwiedmann julianwiedmann merged commit 1a92459 into cilium:main Aug 8, 2023
60 checks passed
@julianwiedmann julianwiedmann deleted the 1.15-bpf-lxc-ipv6-hdrlen branch August 8, 2023 04:53
@joamaki joamaki mentioned this pull request Aug 8, 2023
9 tasks
@joamaki joamaki added backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. and removed needs-backport/1.14 This PR / issue needs backporting to the v1.14 branch backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. labels Aug 8, 2023
@joamaki joamaki mentioned this pull request Aug 9, 2023
9 tasks
@joamaki joamaki added backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. and removed needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch labels Aug 9, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport done to v1.14 in 1.14.1 Aug 9, 2023
@joamaki joamaki mentioned this pull request Aug 9, 2023
7 tasks
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport pending to v1.13 in 1.13.6 Aug 9, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport pending to v1.12 in 1.12.13 Aug 9, 2023
@nebril nebril removed this from Backport pending to v1.13 in 1.13.6 Aug 10, 2023
@nebril nebril added this to Backport pending to v1.13 in 1.13.7 Aug 10, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.12 to Needs backport from main in 1.12.13 Aug 13, 2023
@asauber asauber added this to Needs backport from main in 1.12.14 Aug 13, 2023
@asauber asauber removed this from Needs backport from main in 1.12.13 Aug 13, 2023
@YutaroHayakawa YutaroHayakawa added backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. backport-done/1.12 The backport for Cilium 1.12.x for this PR is done. and removed backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. needs-backport/1.12 labels Aug 17, 2023
@joestringer joestringer moved this from Needs backport from main to Backport done to v1.12 in 1.12.14 Aug 25, 2023
@joestringer joestringer moved this from Backport pending to v1.13 to Backport done to v1.13 in 1.13.7 Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/loadbalancing Impacts load-balancing and Kubernetes service implementations backport-done/1.12 The backport for Cilium 1.12.x for this PR is done. backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. feature/ipv6 Relates to IPv6 protocol support kind/bug This is a bug in the Cilium logic. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/bug This PR fixes an issue in a previous release of Cilium. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages.
Projects
No open projects
1.12.14
Backport done to v1.12
1.13.7
Backport done to v1.13
1.14.1
Backport done to v1.14
Development

Successfully merging this pull request may close these issues.

None yet

5 participants