Skip to content

Commit 9e6e3d1

Browse files
georgepisaltugbionescu
authored andcommitted
added SSBD mitigation for aarch64
Enable the SSBD mitigation for the Firecracker process through the prctl interface. Signed-off-by: George Pisaltu <[email protected]>
1 parent 48ffaee commit 9e6e3d1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/firecracker/src/main.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,38 @@ const DEFAULT_API_SOCK_PATH: &str = "/run/firecracker.socket";
2929
const DEFAULT_INSTANCE_ID: &str = "anonymous-instance";
3030
const FIRECRACKER_VERSION: &str = env!("FIRECRACKER_VERSION");
3131

32+
#[cfg(target_arch = "aarch64")]
33+
/// Enable SSBD mitigation through `prctl`.
34+
pub fn enable_ssbd_mitigation() {
35+
// Parameters for `prctl`
36+
// TODO: generate bindings for these from the kernel sources.
37+
// https://elixir.bootlin.com/linux/v4.17/source/include/uapi/linux/prctl.h#L212
38+
const PR_SET_SPECULATION_CTRL: i32 = 53;
39+
const PR_SPEC_STORE_BYPASS: u64 = 0;
40+
const PR_SPEC_FORCE_DISABLE: u64 = 1u64 << 3;
41+
42+
let ret = unsafe {
43+
libc::prctl(
44+
PR_SET_SPECULATION_CTRL,
45+
PR_SPEC_STORE_BYPASS,
46+
PR_SPEC_FORCE_DISABLE,
47+
0,
48+
0,
49+
)
50+
};
51+
52+
if ret < 0 {
53+
let last_error = std::io::Error::last_os_error().raw_os_error().unwrap();
54+
error!(
55+
"Could not enable SSBD mitigation through prctl, error {}",
56+
last_error
57+
);
58+
if last_error == libc::EINVAL {
59+
error!("The host does not support SSBD mitigation through prctl.");
60+
}
61+
}
62+
}
63+
3264
fn main() {
3365
LOGGER
3466
.configure(Some(DEFAULT_INSTANCE_ID.to_string()))
@@ -38,6 +70,8 @@ fn main() {
3870
error!("Failed to register signal handlers: {}", e);
3971
process::exit(i32::from(vmm::FC_EXIT_CODE_GENERIC_ERROR));
4072
}
73+
#[cfg(target_arch = "aarch64")]
74+
enable_ssbd_mitigation();
4175

4276
// We need this so that we can reset terminal to canonical mode if panic occurs.
4377
let stdin = io::stdin();

0 commit comments

Comments
 (0)