Skip to content

Conversation

@mehnazyunus
Copy link

@mehnazyunus mehnazyunus commented Dec 4, 2025

Fixes #1078

On newer kernels that support bpf_link_create, the call to bpf_link_create will return EINVAL if you pass in any mode other than CgroupAttachMode::Single, because bpf_link_create when used on a cgroup doesn't seem to support flags (see this kernel code). In practice, the kernel defaults to BPF_F_ALLOW_MULTI.

This change sets the flag to 0 in bpf_link_create (used in kernels 5.7+) and adds warning logs if any other attach mode is passed in.


This change is Reviewable

Copilot AI review requested due to automatic review settings December 4, 2025 01:02
@netlify
Copy link

netlify bot commented Dec 4, 2025

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a4fa83b
🔍 Latest deploy log https://app.netlify.com/projects/aya-rs-docs/deploys/6932077cf077d20008772392
😎 Deploy Preview https://deploy-preview-1408--aya-rs-docs.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 project configuration.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes issue #1078 by setting the attach mode flag to 0 when calling bpf_link_create for cgroup programs on kernels 5.7.0+. The kernel's bpf_link_create syscall does not support flags when attaching to cgroups and returns EINVAL for non-zero values, while defaulting to BPF_F_ALLOW_MULTI internally.

Key changes:

  • Added PartialEq derive to CgroupAttachMode enum for comparison operations
  • Updated all cgroup program types to pass 0 instead of mode.into() to bpf_link_create
  • Added runtime warnings when non-default attach modes are specified but cannot be honored

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
aya/src/programs/links.rs Added PartialEq to CgroupAttachMode enum to enable comparison with default
aya/src/programs/sock_ops.rs Updated to pass flag 0 to bpf_link_create with warning when non-default mode is used
aya/src/programs/cgroup_sysctl.rs Updated to pass flag 0 to bpf_link_create with warning when non-default mode is used
aya/src/programs/cgroup_sockopt.rs Updated to pass flag 0 to bpf_link_create with warning when non-default mode is used
aya/src/programs/cgroup_sock_addr.rs Updated to pass flag 0 to bpf_link_create with warning when non-default mode is used
aya/src/programs/cgroup_sock.rs Updated to pass flag 0 to bpf_link_create with warning when non-default mode is used
aya/src/programs/cgroup_skb.rs Updated to pass flag 0 to bpf_link_create with warning when non-default mode is used
aya/src/programs/cgroup_device.rs Updated to pass flag 0 to bpf_link_create with warning when non-default mode is used

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

})?;
if mode != CgroupAttachMode::default() {
warn!(
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "passed on to" should be "passed to" for grammatical correctness.

Suggested change
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
"CgroupAttachMode {:?} will not be passed to bpf_link_create",

Copilot uses AI. Check for mistakes.
})?;
if mode != CgroupAttachMode::default() {
warn!(
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "passed on to" should be "passed to" for grammatical correctness.

Suggested change
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
"CgroupAttachMode {:?} will not be passed to bpf_link_create",

Copilot uses AI. Check for mistakes.
})?;
if mode != CgroupAttachMode::default() {
warn!(
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "passed on to" should be "passed to" for grammatical correctness.

Suggested change
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
"CgroupAttachMode {:?} will not be passed to bpf_link_create",

Copilot uses AI. Check for mistakes.
if KernelVersion::at_least(5, 7, 0) {
if mode != CgroupAttachMode::default() {
warn!(
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "passed on to" should be "passed to" for grammatical correctness.

Suggested change
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
"CgroupAttachMode {:?} will not be passed to bpf_link_create",

Copilot uses AI. Check for mistakes.
})?;
if mode != CgroupAttachMode::default() {
warn!(
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "passed on to" should be "passed to" for grammatical correctness.

Suggested change
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
"CgroupAttachMode {:?} will not be passed to bpf_link_create",

Copilot uses AI. Check for mistakes.
if KernelVersion::at_least(5, 7, 0) {
if mode != CgroupAttachMode::default() {
warn!(
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "passed on to" should be "passed to" for grammatical correctness.

Suggested change
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
"CgroupAttachMode {:?} will not be passed to bpf_link_create",

Copilot uses AI. Check for mistakes.
})?;
if mode != CgroupAttachMode::default() {
warn!(
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "passed on to" should be "passed to" for grammatical correctness.

Suggested change
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
"CgroupAttachMode {:?} will not be passed to bpf_link_create",

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attaching a program to a cgroup via bpf_link_create throws if the caller passes in flags

1 participant