Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion aya/src/programs/cgroup_sock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ impl CgroupSock {
path: P,
attach_type: CgroupSockAttachType,
) -> Result<Self, ProgramError> {
let data = ProgramData::from_pinned_path(path, VerifierLogLevel::default())?;
let mut data = ProgramData::from_pinned_path(path, VerifierLogLevel::default())?;
data.expected_attach_type = Some(attach_type.into());
Ok(Self { data, attach_type })
}
}
Expand Down
3 changes: 2 additions & 1 deletion aya/src/programs/cgroup_sock_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ impl CgroupSockAddr {
path: P,
attach_type: CgroupSockAddrAttachType,
) -> Result<Self, ProgramError> {
let data = ProgramData::from_pinned_path(path, VerifierLogLevel::default())?;
let mut data = ProgramData::from_pinned_path(path, VerifierLogLevel::default())?;
data.expected_attach_type = Some(attach_type.into());
Ok(Self { data, attach_type })
}
}
Expand Down
3 changes: 2 additions & 1 deletion aya/src/programs/cgroup_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ impl CgroupSockopt {
path: P,
attach_type: CgroupSockoptAttachType,
) -> Result<Self, ProgramError> {
let data = ProgramData::from_pinned_path(path, VerifierLogLevel::default())?;
let mut data = ProgramData::from_pinned_path(path, VerifierLogLevel::default())?;
data.expected_attach_type = Some(attach_type.into());
Ok(Self { data, attach_type })
}
}
Expand Down
1 change: 1 addition & 0 deletions test/integration-test/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod bloom_filter;
mod bpf_probe_read;
mod btf_maps;
mod btf_relocations;
mod cgroup_sock_pinned;
mod elf;
mod feature_probe;
mod info;
Expand Down
50 changes: 50 additions & 0 deletions test/integration-test/src/tests/cgroup_sock_pinned.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::fs::remove_file;

use aya::{
maps::SkStorage,
programs::{CgroupAttachMode, CgroupSockAddr, CgroupSockAddrAttachType},
};
use test_log::test;

use crate::utils::Cgroup;

#[test]
fn cgroup_sock_addr_from_pin_attach() {
// Test that CgroupSockAddr::from_pin() correctly sets expected_attach_type,
// so that attach() does not panic.
let mut ebpf = aya::EbpfLoader::new().load(crate::SK_STORAGE).unwrap();

let storage = ebpf.take_map("SOCKET_STORAGE").unwrap();
let _storage =
SkStorage::<_, integration_common::sk_storage::Value>::try_from(storage).unwrap();

let prog = ebpf
.program_mut("sk_storage_connect4")
.unwrap()
.try_into()
.unwrap();

let prog: &mut CgroupSockAddr = prog;
prog.load().unwrap();

// Pin the program to bpffs
let pin_path = "/sys/fs/bpf/aya-test-cgroup-sock-addr-from-pin";
remove_file(pin_path).ok();
prog.pin(pin_path).unwrap();

// Reload from pinned path via from_pin() - this is the critical path.
// Before the fix, expected_attach_type was not set in from_pin(),
// causing attach() to panic with unwrap on None.
let mut prog = CgroupSockAddr::from_pin(pin_path, CgroupSockAddrAttachType::Connect4).unwrap();

let root = Cgroup::root();
let cgroup = root.create_child("aya-test-cgroup-sock-addr-from-pin");
let cgroup_fd = cgroup.fd();

// This attach() would panic if expected_attach_type was not set by from_pin().
let _link_id = prog.attach(cgroup_fd, CgroupAttachMode::Single).unwrap();

// Clean up
drop(cgroup);
remove_file(pin_path).ok();
}
Loading