Skip to content

Conversation

msune
Copy link
Member

@msune msune commented Aug 4, 2025

Add two new coccinelle rules that check:

  • the usage of hexdump*() and HEXDUMP*() family of functions and MACROs.
  • the inclusion of hexdump.h

in BPF production code.

Fixes #40929

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Aug 4, 2025
@github-actions github-actions bot added the kind/community-contribution This was a contribution made by a community member. label Aug 4, 2025
Copy link
Contributor

@smagnani96 smagnani96 left a comment

Choose a reason for hiding this comment

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

I'd add a check to ignore all bpf/tests files, and the hexdump.h library itself.
In all the other cases, the cocci script must point out the error (and fail PRs).
See the comment I've left.

@msune msune force-pushed the hexdump_coccinelle branch 3 times, most recently from e09b101 to 8208cdc Compare August 6, 2025 06:05
@msune msune marked this pull request as ready for review August 6, 2025 06:05
@msune msune requested a review from a team as a code owner August 6, 2025 06:05
@msune msune requested review from aspsk and smagnani96 August 6, 2025 06:05
@msune
Copy link
Member Author

msune commented Aug 6, 2025

cc @qmonnet

@msune msune changed the title contrib/cocci: add hexdump coccinelle rule contrib/cocci: add hexdump() and hexdump.h include coccinelle rules Aug 6, 2025
@msune msune force-pushed the hexdump_coccinelle branch from 8208cdc to 35adb9a Compare August 6, 2025 06:08
@msune
Copy link
Member Author

msune commented Aug 6, 2025

Failure coccicheck output with the To be removed commit:

Copy link
Contributor

@smagnani96 smagnani96 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀
Left a couple of thoughts, but nothing to compromise the PR.

Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

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

I haven't played with 🐞 in a while, and I don't remember enough of the semantics to provide meaningful feedback. But from far above, this looks good, thanks for adding this!

@qmonnet qmonnet added area/CI-improvement Topic or proposal to improve the Continuous Integration workflow release-note/ci This PR makes changes to the CI. labels Aug 6, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Aug 6, 2025
@msune msune force-pushed the hexdump_coccinelle branch 2 times, most recently from 3746b32 to c819486 Compare August 6, 2025 15:25
@msune
Copy link
Member Author

msune commented Aug 6, 2025

Asking for a rereview, @smagnani96 since I cleaned them up quite a bit. A singing CI run:

https://github.com/cilium/cilium/actions/runs/16781233206/job/47520160835?pr=40930

@msune msune requested a review from smagnani96 August 6, 2025 15:25
Copy link
Contributor

@smagnani96 smagnani96 left a comment

Choose a reason for hiding this comment

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

Scripts look amazing, would simply merge them in 1.
See review comment.

@msune msune force-pushed the hexdump_coccinelle branch 2 times, most recently from abadf4a to c86d460 Compare August 6, 2025 15:57
Add coccinelle rule that checks for the usage of hexdump*() functions,
HEXDUMP*() MACROs and the inclusion of `hexdump.h`. Given that these
use printk(), they should be avoided on any production code (so all
code other than `hexdump.h` itself and tests/).

Fixes cilium#40929

Signed-off-by: Marc Suñé <marc.sune@isovalent.com>
Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
@msune msune force-pushed the hexdump_coccinelle branch from c86d460 to c99c67d Compare August 6, 2025 15:57
@msune
Copy link
Member Author

msune commented Aug 7, 2025

Can we merge?

@smagnani96
Copy link
Contributor

smagnani96 commented Aug 7, 2025

/test

(hoped it was smart enough to skip)
(you still need a committer for adding this to the merge queue, even if all tests pass)

@qmonnet qmonnet enabled auto-merge August 8, 2025 10:08
@qmonnet qmonnet added this pull request to the merge queue Aug 8, 2025
@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, 2025
Merged via the queue into cilium:main with commit 75af0d0 Aug 8, 2025
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/CI-improvement Topic or proposal to improve the Continuous Integration workflow kind/community-contribution This was a contribution made by a community member. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/ci This PR makes changes to the CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bpf: add coccinelle rule to avoid hexdump.h usage in production code
4 participants