Skip to content
Merged
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
4 changes: 0 additions & 4 deletions .quality/dependency-compatibility.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
"declaration": "1",
"reason": "Retains the existing thiserror 1 derive API until its consumers are migrated together."
},
"src/cortex-linux-sandbox/Cargo.toml:target.cfg(target_os = \"linux\").dependencies:seccompiler": {
"declaration": "0.4",
"reason": "Retains seccompiler 0.4 sandbox filter API; changing sandbox policy needs a dedicated compatibility review."
},
"src/cortex-resume/Cargo.toml:dependencies:thiserror": {
"declaration": "1",
"reason": "Retains the existing thiserror 1 derive API until its consumers are migrated together."
Expand Down
13 changes: 2 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cortex-linux-sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tracing = { workspace = true }
landlock = { workspace = true }

# Seccomp
seccompiler = "0.4"
seccompiler = { workspace = true }

# Linux libc bindings
libc = { workspace = true }
56 changes: 51 additions & 5 deletions src/cortex-linux-sandbox/src/seccomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,58 @@ pub fn apply_network_filter() -> Result<()> {

#[cfg(test)]
mod tests {
// Note: seccomp tests are tricky because they affect the current process
// and are irreversible. Integration tests should be done in a subprocess.
use std::fs::File;
use std::io::{Read, Write};
use std::net::{TcpListener, UdpSocket};
use std::os::fd::OwnedFd;
use std::os::unix::net::UnixStream;
use std::process::Command;

#[test]
fn test_filter_creation() {
// This test just verifies the filter can be created without panic
// Actual application would need to be tested in a subprocess
fn test_network_filter_in_subprocess() {
const CHILD: &str = "CORTEX_SECCOMP_TEST_CHILD";
if std::env::var_os(CHILD).is_none() {
let output = Command::new(std::env::current_exe().unwrap())
.args([
"--exact",
"seccomp::tests::test_network_filter_in_subprocess",
"--nocapture",
])
.env(CHILD, "1")
.output()
.unwrap();
assert!(
output.status.success(),
"seccomp child failed: {}",
String::from_utf8_lossy(&output.stderr)
);
assert!(
String::from_utf8_lossy(&output.stdout).contains("1 passed; 0 failed"),
"the isolated seccomp test must actually run"
);
return;
}

// Prove the denied operations work before installing this filter.
drop(TcpListener::bind("127.0.0.1:0").unwrap());
drop(UdpSocket::bind("127.0.0.1:0").unwrap());
super::apply_network_filter().unwrap();

assert_eq!(
TcpListener::bind("127.0.0.1:0").unwrap_err().raw_os_error(),
Some(libc::EPERM)
);
assert_eq!(
UdpSocket::bind("127.0.0.1:0").unwrap_err().raw_os_error(),
Some(libc::EPERM)
);
let (sender, receiver) = UnixStream::pair().unwrap();
// Use read/write: the filter intentionally denies send/recv syscalls.
let mut sender = File::from(OwnedFd::from(sender));
let mut receiver = File::from(OwnedFd::from(receiver));
sender.write_all(b"local").unwrap();
let mut received = [0; 5];
receiver.read_exact(&mut received).unwrap();
assert_eq!(&received, b"local");
}
}
Loading