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

Fix seccomp always denying local sockets #39

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/linux/seccomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl NetworkFilter {
SeccompCmpOp::Eq,
libc::AF_UNIX as u64,
)?;
let unix_rule = SeccompRule::new(vec![allow_unix])?;

// Allow local IPC AF_NETLINK sockets.
let allow_netlink = SeccompCondition::new(
Expand All @@ -64,8 +65,9 @@ impl NetworkFilter {
SeccompCmpOp::Eq,
libc::AF_NETLINK as u64,
)?;
let netlink_rule = SeccompRule::new(vec![allow_netlink])?;

let socket_rule = vec![SeccompRule::new(vec![allow_unix, allow_netlink])?];
let socket_rule = vec![unix_rule, netlink_rule];

// Restrict socket creation to allowed socket domain types.
rules.insert(libc::SYS_socketpair, socket_rule.clone());
Expand Down
14 changes: 14 additions & 0 deletions tests/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ fn block_io_uring() {
assert_eq!(IoError::last_os_error().kind(), IoErrorKind::PermissionDenied);
}

#[cfg(target_os = "linux")]
#[test]
fn allow_local_sockets() {
let birdcage = Birdcage::new().unwrap();
birdcage.lock().unwrap();

let fd = unsafe { libc::socket(libc::AF_UNIX, libc::SOCK_STREAM, 0) };
if fd < 0 {
panic!("AF_UNIX socket creation failed: {}", IoError::last_os_error());
}

unsafe { libc::close(fd) };
}

#[repr(C)]
#[derive(Default)]
struct IoUringParams {
Expand Down
Loading