Skip to content

Commit

Permalink
main: Give a friendly message when we get a seccomp violation
Browse files Browse the repository at this point in the history
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 <robert.bradford@intel.com>
  • Loading branch information
rbradford committed Jan 11, 2021
1 parent ba7864e commit b55f227
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ log = { version = "0.4.13", features = ["std"] }
option_parser = { path = "option_parser" }
seccomp = { git = "https://github.com/firecracker-microvm/firecracker", tag = "v0.22.0" }
serde_json = "1.0.61"
signal-hook = "0.3.3"
thiserror = "1.0"
vmm = { path = "vmm" }
vmm-sys-util = "0.7.0"
wait-timeout = "0.2.0"
vm-memory = "0.4.0"
wait-timeout = "0.2.0"

[build-dependencies]
clap = { version = "2.33.3", features = ["wrap_help"] }
Expand Down
31 changes: 31 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

extern crate anyhow;
extern crate signal_hook;
extern crate vmm;
extern crate vmm_sys_util;

Expand All @@ -14,9 +15,14 @@ use clap::{App, Arg, ArgGroup, ArgMatches};
use libc::EFD_NONBLOCK;
use log::LevelFilter;
use seccomp::SeccompAction;
use signal_hook::{
consts::SIGSYS,
iterator::{exfiltrator::WithRawSiginfo, SignalsInfo},
};
use std::env;
use std::sync::mpsc::channel;
use std::sync::{Arc, Mutex};
use std::thread;
use thiserror::Error;
use vmm::config;
use vmm_sys_util::eventfd::EventFd;
Expand Down Expand Up @@ -355,6 +361,31 @@ fn start_vmm(cmd_arguments: ArgMatches, api_socket_path: &str) -> Result<(), Err
} else {
SeccompAction::Trap
};

// See https://github.com/rust-lang/libc/issues/716 why we can't get the details from siginfo_t
if seccomp_action == SeccompAction::Trap {
thread::Builder::new()
.name("seccomp_signal_handler".to_string())
.spawn(move || {
for si in SignalsInfo::<WithRawSiginfo>::new(&[SIGSYS])
.unwrap()
.forever()
{
/* SYS_SECCOMP */
if si.si_code == 1 {
eprint!(
"\n==== seccomp violation ====\n\
Try running with `strace -ff` to identify the cause and open an issue: \
https://github.com/cloud-hypervisor/cloud-hypervisor/issues/new\n"
);

signal_hook::low_level::emulate_default_handler(SIGSYS).unwrap();
}
}
})
.unwrap();
}

let hypervisor = hypervisor::new().map_err(Error::CreateHypervisor)?;
let vmm_thread = vmm::start_vmm_thread(
env!("CARGO_PKG_VERSION").to_string(),
Expand Down

0 comments on commit b55f227

Please sign in to comment.