virtio-devices: seccomp: Add seccomp filters for balloon thread

This patch enables the seccomp filters for the balloon worker thread.

Partially fixes: #925

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen
2020-08-17 19:58:13 -07:00
committed by Sebastien Boeuf
parent c460178723
commit c82ded8afa
3 changed files with 36 additions and 2 deletions

View File

@@ -16,9 +16,11 @@ use super::{
ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, Queue,
VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, VIRTIO_F_VERSION_1,
};
use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::vm_memory::GuestMemory;
use crate::{VirtioInterrupt, VirtioInterruptType};
use libc::EFD_NONBLOCK;
use seccomp::{SeccompAction, SeccompFilter};
use std::io;
use std::mem::size_of;
use std::os::unix::io::AsRawFd;
@@ -318,11 +320,12 @@ pub struct Balloon {
epoll_threads: Option<Vec<thread::JoinHandle<()>>>,
paused: Arc<AtomicBool>,
paused_sync: Arc<Barrier>,
seccomp_action: SeccompAction,
}
impl Balloon {
// Create a new virtio-balloon.
pub fn new(id: String, size: u64) -> io::Result<Self> {
pub fn new(id: String, size: u64, seccomp_action: SeccompAction) -> io::Result<Self> {
let avail_features = 1u64 << VIRTIO_F_VERSION_1;
let mut config = VirtioBalloonConfig::default();
@@ -341,6 +344,7 @@ impl Balloon {
epoll_threads: None,
paused: Arc::new(AtomicBool::new(false)),
paused_sync: Arc::new(Barrier::new(2)),
seccomp_action,
})
}
@@ -451,10 +455,15 @@ impl VirtioDevice for Balloon {
let paused = self.paused.clone();
let paused_sync = self.paused_sync.clone();
let mut epoll_threads = Vec::new();
let virtio_balloon_seccomp_filter =
get_seccomp_filter(&self.seccomp_action, Thread::VirtioBalloon)
.map_err(ActivateError::CreateSeccompFilter)?;
thread::Builder::new()
.name("virtio_balloon".to_string())
.spawn(move || {
if let Err(e) = handler.run(paused, paused_sync) {
if let Err(e) = SeccompFilter::apply(virtio_balloon_seccomp_filter) {
error!("Error applying seccomp filter: {:?}", e);
} else if let Err(e) = handler.run(paused, paused_sync) {
error!("Error running worker: {:?}", e);
}
})