Skip to content
Closed
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
19 changes: 10 additions & 9 deletions crates/openshell-sandbox/src/sandbox/linux/seccomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ pub fn apply(policy: &SandboxPolicy) -> Result<()> {
return Ok(());
}

let allow_inet = matches!(policy.network.mode, NetworkMode::Proxy);
let filter = build_filter(allow_inet)?;
let filter = build_filter()?;

// Required before applying seccomp filters.
let rc = unsafe { libc::prctl(libc::PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) };
Expand All @@ -34,15 +33,17 @@ pub fn apply(policy: &SandboxPolicy) -> Result<()> {
Ok(())
}

fn build_filter(allow_inet: bool) -> Result<seccompiler::BpfProgram> {
fn build_filter() -> Result<seccompiler::BpfProgram> {
let mut rules: BTreeMap<i64, Vec<SeccompRule>> = BTreeMap::new();

let mut blocked_domains = vec![libc::AF_PACKET, libc::AF_BLUETOOTH, libc::AF_VSOCK];
if !allow_inet {
blocked_domains.push(libc::AF_INET);
blocked_domains.push(libc::AF_INET6);
blocked_domains.push(libc::AF_NETLINK);
}
let blocked_domains = vec![
libc::AF_PACKET,
libc::AF_BLUETOOTH,
libc::AF_VSOCK,
libc::AF_INET,
libc::AF_INET6,
libc::AF_NETLINK,
];

for domain in blocked_domains {
debug!(domain, "Blocking socket domain via seccomp");
Expand Down
Loading