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: fix missing "break" in nat46 switch, and minor cleanup #11410

Merged
merged 2 commits into from
May 8, 2020

Conversation

qmonnet
Copy link
Member

@qmonnet qmonnet commented May 7, 2020

While the work on checkers/static analysers for BPF code is still in progress, here are a few fixes for issues already reported by some of the tools I've been trying.

The first commit adds missing break keywords in a switch statement in NAT46. The bug is present since version 0.8.0, but it only concerns ICMPv6 handling and probably has a low impact. In doubt, I'm marking this commit for backport on 1.7.

The second patch is trivial fixes at various places in the BPF code. This second commit does not need to be backported.

@qmonnet qmonnet 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. needs-backport/1.5 labels May 7, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot added this to In progress in 1.8.0 May 7, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.7.4 May 7, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.5.14 May 7, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.6.9 May 7, 2020
@qmonnet
Copy link
Member Author

qmonnet commented May 7, 2020

test-me-please

@qmonnet
Copy link
Member Author

qmonnet commented May 7, 2020

restart-ginkgo
Previous run failed to download quay.io image

@coveralls
Copy link

coveralls commented May 7, 2020

Coverage Status

Coverage increased (+0.008%) to 37.872% when pulling 03a1755 on pr/qmonnet/bpf_fixes into 2459b49 on master.

@joestringer
Copy link
Member

Just given that BPF backports are a bit painful (particularly due to bpf.sha update and other areas), and that no user is reporting any issue, I wonder if we should just restrict this to v1.7.

For reference, here's the criteria for backports:
https://docs.cilium.io/en/v1.7/contributing/release/backports/#backport-criteria

@qmonnet
Copy link
Member Author

qmonnet commented May 7, 2020

Looks like I broke cilium-map-migrate, likely with the scanf() change.

@qmonnet
Copy link
Member Author

qmonnet commented May 7, 2020

Just given that BPF backports are a bit painful (particularly due to bpf.sha update and other areas), and that no user is reporting any issue, I wonder if we should just restrict this to v1.7.

Thanks for the pointer to the criteria. Ok, agreed, I'll remove the labels for older versions.

@maintainer-s-little-helper maintainer-s-little-helper bot removed this from Needs backport from master in 1.6.9 May 7, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot removed this from Needs backport from master in 1.5.14 May 7, 2020
There are missing "break" keywords in the switch statement to process
the different ICMPv6 message types. Let's add them.

Indirectly reported by cppcheck which would complain that icmp4.code
would be overwritten before being read (which happens indeed if we fall
through).

Fixes: f7396ba ("Add support for nat46 icmp translation.")
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Fix minor issues in the BPF code. Namely:

- Use "void" to tell functions take no argument in their declaration,
  instead of non-ANSI empty parenthesis.
- Remove an unused "ret" variable.
- Fix format specifiers for sscanf() and fprintf().
- Remove a useless variable increment.
- Compile out some code in bpf_sockops.c if ENABLE_IPV4 is not defined.

These issues were reported by various code analyzers.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
@qmonnet
Copy link
Member Author

qmonnet commented May 7, 2020

test-me-please

Incremental diff
diff --git a/bpf/cilium-map-migrate.c b/bpf/cilium-map-migrate.c
index ded8eef9b33a..f47259684d40 100644
--- a/bpf/cilium-map-migrate.c
+++ b/bpf/cilium-map-migrate.c
@@ -278,7 +278,7 @@ static int bpf_derive_elf_map_from_fdinfo(int fd, struct bpf_elf_map *map)
 			map->size_value = val;
 		else if (sscanf(buff, "max_entries:\t%u", &val) == 1)
 			map->max_elem = val;
-		else if (sscanf(buff, "map_flags:\t%u", &val) == 1)
+		else if (sscanf(buff, "map_flags:\t%x", &val) == 1)
 			map->flags = val;
 	}
 

@qmonnet
Copy link
Member Author

qmonnet commented May 7, 2020

21:36:26  Vagrant can't use the requested machine because it is locked! This
21:36:26  means that another Vagrant process is currently reading or modifying
21:36:26  the machine. Please wait for that Vagrant process to end and try
21:36:26  again.

... then timeout.

restart-ginkgo

@qmonnet
Copy link
Member Author

qmonnet commented May 7, 2020

00:19:32      k8s1-1.18: E: Version '0.8.5*' for 'kubernetes-cni' was not found

restart-ginkgo

@qmonnet qmonnet marked this pull request as ready for review May 8, 2020 11:35
@qmonnet qmonnet requested a review from a team May 8, 2020 11:35
@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 May 8, 2020
Copy link
Member

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

LGTM!

@qmonnet Please note that the commit you refer as first is the second one in GitHub's API. I haven't checked the actual git order, but it's possible GitHub gets confused because you reordered commits at some point.

EDIT: Out of curiosity: which tool found the missing breaks?

@borkmann borkmann merged commit c23e9c2 into master May 8, 2020
1.8.0 automation moved this from In progress to Merged May 8, 2020
@borkmann borkmann deleted the pr/qmonnet/bpf_fixes branch May 8, 2020 12:53
@qmonnet
Copy link
Member Author

qmonnet commented May 8, 2020

@qmonnet Please note that the commit you refer as first is the second one in GitHub's API. I haven't checked the actual git order, but it's possible GitHub gets confused because you reordered commits at some point.

Git history has it first, and indeed I reordered them before pushing and GitHub seems to use commit creation date. I try to reset the date before pushing, but forgot this time. Thanks for the note!

EDIT: Out of curiosity: which tool found the missing breaks?

From commit log 😛:

Indirectly reported by cppcheck which would complain that icmp4.code
would be overwritten before being read (which happens indeed if we fall
through).

@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.7 in 1.7.4 May 11, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.7 in 1.7.4 May 11, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.7 to Backport done to v1.7 in 1.7.4 May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.7.4
Backport done to v1.7
1.8.0
  
Merged
Development

Successfully merging this pull request may close these issues.

None yet

8 participants