Skip to content

Commit

Permalink
Fix seccomp always denying local sockets (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
cd-work authored Aug 31, 2023
1 parent 9ed8f53 commit d3d3f99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Fixed

- Local sockets denied by network sandbox on Linux

## [0.3.0] - 2023-08-31

### Changed
Expand Down
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

0 comments on commit d3d3f99

Please sign in to comment.