@@ -30,6 +30,38 @@ const DEFAULT_API_SOCK_PATH: &str = "/run/firecracker.socket";
3030const DEFAULT_INSTANCE_ID : & str = "anonymous-instance" ;
3131const FIRECRACKER_VERSION : & str = env ! ( "FIRECRACKER_VERSION" ) ;
3232
33+ #[ cfg( target_arch = "aarch64" ) ]
34+ /// Enable SSBD mitigation through `prctl`.
35+ pub fn enable_ssbd_mitigation ( ) {
36+ // Parameters for `prctl`
37+ // TODO: generate bindings for these from the kernel sources.
38+ // https://elixir.bootlin.com/linux/v4.17/source/include/uapi/linux/prctl.h#L212
39+ const PR_SET_SPECULATION_CTRL : i32 = 53 ;
40+ const PR_SPEC_STORE_BYPASS : u64 = 0 ;
41+ const PR_SPEC_FORCE_DISABLE : u64 = 1u64 << 3 ;
42+
43+ let ret = unsafe {
44+ libc:: prctl (
45+ PR_SET_SPECULATION_CTRL ,
46+ PR_SPEC_STORE_BYPASS ,
47+ PR_SPEC_FORCE_DISABLE ,
48+ 0 ,
49+ 0 ,
50+ )
51+ } ;
52+
53+ if ret < 0 {
54+ let last_error = std:: io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ;
55+ error ! (
56+ "Could not enable SSBD mitigation through prctl, error {}" ,
57+ last_error
58+ ) ;
59+ if last_error == libc:: EINVAL {
60+ error ! ( "The host does not support SSBD mitigation through prctl." ) ;
61+ }
62+ }
63+ }
64+
3365fn main ( ) {
3466 LOGGER
3567 . configure ( Some ( DEFAULT_INSTANCE_ID . to_string ( ) ) )
@@ -39,6 +71,8 @@ fn main() {
3971 error ! ( "Failed to register signal handlers: {}" , e) ;
4072 process:: exit ( i32:: from ( vmm:: FC_EXIT_CODE_GENERIC_ERROR ) ) ;
4173 }
74+ #[ cfg( target_arch = "aarch64" ) ]
75+ enable_ssbd_mitigation ( ) ;
4276
4377 // We need this so that we can reset terminal to canonical mode if panic occurs.
4478 let stdin = io:: stdin ( ) ;
0 commit comments