-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add Seccomp bits for linux #10717
Add Seccomp bits for linux #10717
Conversation
This library contains: - The global constants as used by C code. - An Insn struct that implements can generate all the BPF instructions. - A simple BPF virtual machine implementation that can be used for testing programs. This has complete code-coverage and has been extensively fuzzed.
Also adds the _CSKY and _FRV ELF machines that are defined in `<linux/elf-em.h>`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a nit on comments. otherwise looking good, though I did not test this yet.
do you have a plan how and when to test this in CI to track upstream Kernel?
Side question: Are there other OSes with bpf support? Otherwise bpf.zig
belongs into os/linux
.
BPF is supported on many different OSs and all implementations - besides Linux - share code. This is the problem with OS testing. For example, here's how to attach a filter to an interface on OpenBSD:
On Linux, the process is:
On top of the OS-level differences, network packet capturing requires root privilege on the *BSDs and the Note, this is from a surface-level reading of tcpdump/libpcap. There are most likely errors. Seccomp testing shouldn't be too hard, I left it out because it requires a bit of work:
|
I've tweaked and added to the seccomp documentation. |
I've just touched up the docs one last time. @matu3ba, do you require any changes or is it good to merge as is? |
I like the tests and the documentation is very nice to read. |
@The-King-of-Toasters I was wrong on sockets on Linux (in
|
I'm open to writing proper tests, however I feel writing a new style of test is out of scope for this addition, and should be worked on in its own PR. I've also removed the few remaining references to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch. I found a couple issues, but nothing so problematic as to deserve a revert.
const _64BIT = 0x80000000; | ||
const _LE = 0x40000000; | ||
|
||
pub const current = switch (native_arch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing type annotation (should have type ARCH
)
.powerpc => .PPC, | ||
.powerpc64 => .PPC64, | ||
.powerpc64le => .PPC64LE, | ||
else => undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be else => @compileError("unsupported architecture")
Thanks for the feedback, will follow up with a commit soon. |
- Add type annotation for AUDIT.current. - Make unsupported archs a compile error.
- Add type annotation for AUDIT.current. - Make unsupported archs a compile error.
Full functionality necessitates a classic BPF implementation, so I did that too. Included is a simulator for debugging/testing purposes. It's been fuzzed for a couple days and I haven't found any errors. It may be worth de-duplicating the shared constants in
std.os.linux.BPF
andstd.x.net.bpf
later on.Most of the effort was spent writing the documentation for the bpf/seccomp bits, so I hope that everything is clear and understandable.
There's a small issue relating to
@offsetOf
that I'll open a new issue for: #10718.