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: unit tests and fixes for prepend_name function #1902

Merged
merged 4 commits into from
Jan 3, 2024

Conversation

mtardy
Copy link
Member

@mtardy mtardy commented Dec 18, 2023

See commits!

@mtardy mtardy added the release-note/bug This PR fixes an issue in a previous release of Tetragon. label Dec 18, 2023
Copy link

netlify bot commented Dec 18, 2023

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 796a65d
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/658178e27ebfe00008f83e2c
😎 Deploy Preview https://deploy-preview-1902--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mtardy mtardy force-pushed the pr/mtardy/bpf-fix-prend-name branch 14 times, most recently from 1f8b455 to 436aee2 Compare December 19, 2023 20:04
@mtardy mtardy added area/bpf This is related to BPF code area/testing Related to testing labels Dec 19, 2023
@mtardy mtardy marked this pull request as ready for review December 19, 2023 20:05
@mtardy mtardy requested review from willfindlay and a team as code owners December 19, 2023 20:05
Copy link
Contributor

@willfindlay willfindlay left a comment

Choose a reason for hiding this comment

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

Just a couple nits, but LGTM. Might be helpful to have someone else do a pass of the prepend_name changes, but I didn't find any obvious bugs.

bpf/process/bpf_process_event.h Outdated Show resolved Hide resolved
bpf/process/bpf_process_event.h Outdated Show resolved Hide resolved
__type(value, struct test_prepend_name_state_map_value);
} test_prepend_name_state_map SEC(".maps");

__attribute__((section("raw_tracepoint/test"), used)) int
Copy link
Contributor

Choose a reason for hiding this comment

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

This BPF unit testing is extremely valuable and honestly long overdue. Thanks for adding the first of hopefully many to come

In order to make BPF_PROG_RUN work with BPF_PROG_TYPE_RAW_TRACEPOINT in
cilium/ebpf.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
It looked like this particular function presented some bugs:
- It would not return -ENAMETOOLONG when the buffer was filled
  "best-effort" because the name was not fitting.
- It would never fill the first byte of the buffer, thus reducing the
  maximum size written by one.
- It would not fill "best-effort" correctly. E.g, previously in a buffer
  of 4, "pizza" would have been "/piz" (when ignoring previous bug)
  instead of "izza". Now it tries to write the "end" of the name without
  a wrong "/" char.
- It would behave unexpectedly when filled with more data than size of
  buffer.

BPF unit tests were put under bpf/tests, as more can be added there in
the future. The Makefile was updated so that we can share variable
definition between the bpf/Makefile and the bpf/tests/Makefile file.
This separation allows us not compile the test program along the rest of
the BPF progs, and not ship them in the released images/archives.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Unit tests were added in the previous commit for this function,
highlighting some of the issues it presented. This commit introduce a
few changes trying to fix the detected bugs.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
@mtardy mtardy force-pushed the pr/mtardy/bpf-fix-prend-name branch from 436aee2 to d23a34a Compare January 3, 2024 11:21
@mtardy
Copy link
Member Author

mtardy commented Jan 3, 2024

Note that this has a chance of fixing #1707, it can be related.

Copy link
Member

@tpapagian tpapagian left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Having a skeleton to build eBPF unit tests would be really useful!

// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright Authors of Cilium */

//go:build ignore
Copy link
Member

Choose a reason for hiding this comment

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

Question: Why do we need that?

Copy link
Member Author

Choose a reason for hiding this comment

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

So this is a bit weird but you can't have a .c file in the same directory as a go module unless you are using CGO 🤔 most Go commands will return C source files not allowed when not using cgo.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to house the C file with the BPF test harness and the Go file in the same directory so it's needed!

@mtardy mtardy merged commit f08c16f into main Jan 3, 2024
33 checks passed
@mtardy mtardy deleted the pr/mtardy/bpf-fix-prend-name branch January 3, 2024 15:44
@kkourt
Copy link
Contributor

kkourt commented Jan 10, 2024

🚀

@mtardy I feel like we should backport this (or at least the buffix) to 1.0. WDYT?

@mtardy
Copy link
Member Author

mtardy commented Jan 10, 2024

🚀

@mtardy I feel like we should backport this (or at least the buffix) to 1.0. WDYT?

Yes, it would make sense since it might fix a user facing bug. Let me do that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bpf This is related to BPF code area/testing Related to testing release-note/bug This PR fixes an issue in a previous release of Tetragon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants