Skip to content

Commit b55f227

Browse files
committed
main: Give a friendly message when we get a seccomp violation
If we receive SIGSYS and identify it as a seccomp violation then give friendly instructions on how to debug further. We are unable to decode the siginfo_t struct ourselves due to rust-lang/libc#716 Fixes: cloud-hypervisor#2139 Signed-off-by: Rob Bradford <[email protected]>
1 parent ba7864e commit b55f227

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ log = { version = "0.4.13", features = ["std"] }
2323
option_parser = { path = "option_parser" }
2424
seccomp = { git = "https://github.com/firecracker-microvm/firecracker", tag = "v0.22.0" }
2525
serde_json = "1.0.61"
26+
signal-hook = "0.3.3"
2627
thiserror = "1.0"
2728
vmm = { path = "vmm" }
2829
vmm-sys-util = "0.7.0"
29-
wait-timeout = "0.2.0"
3030
vm-memory = "0.4.0"
31+
wait-timeout = "0.2.0"
3132

3233
[build-dependencies]
3334
clap = { version = "2.33.3", features = ["wrap_help"] }

src/main.rs

+31
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//
55

66
extern crate anyhow;
7+
extern crate signal_hook;
78
extern crate vmm;
89
extern crate vmm_sys_util;
910

@@ -14,9 +15,14 @@ use clap::{App, Arg, ArgGroup, ArgMatches};
1415
use libc::EFD_NONBLOCK;
1516
use log::LevelFilter;
1617
use seccomp::SeccompAction;
18+
use signal_hook::{
19+
consts::SIGSYS,
20+
iterator::{exfiltrator::WithRawSiginfo, SignalsInfo},
21+
};
1722
use std::env;
1823
use std::sync::mpsc::channel;
1924
use std::sync::{Arc, Mutex};
25+
use std::thread;
2026
use thiserror::Error;
2127
use vmm::config;
2228
use vmm_sys_util::eventfd::EventFd;
@@ -355,6 +361,31 @@ fn start_vmm(cmd_arguments: ArgMatches, api_socket_path: &str) -> Result<(), Err
355361
} else {
356362
SeccompAction::Trap
357363
};
364+
365+
// See https://github.com/rust-lang/libc/issues/716 why we can't get the details from siginfo_t
366+
if seccomp_action == SeccompAction::Trap {
367+
thread::Builder::new()
368+
.name("seccomp_signal_handler".to_string())
369+
.spawn(move || {
370+
for si in SignalsInfo::<WithRawSiginfo>::new(&[SIGSYS])
371+
.unwrap()
372+
.forever()
373+
{
374+
/* SYS_SECCOMP */
375+
if si.si_code == 1 {
376+
eprint!(
377+
"\n==== seccomp violation ====\n\
378+
Try running with `strace -ff` to identify the cause and open an issue: \
379+
https://github.com/cloud-hypervisor/cloud-hypervisor/issues/new\n"
380+
);
381+
382+
signal_hook::low_level::emulate_default_handler(SIGSYS).unwrap();
383+
}
384+
}
385+
})
386+
.unwrap();
387+
}
388+
358389
let hypervisor = hypervisor::new().map_err(Error::CreateHypervisor)?;
359390
let vmm_thread = vmm::start_vmm_thread(
360391
env!("CARGO_PKG_VERSION").to_string(),

0 commit comments

Comments
 (0)