Skip to main content

sandbox/profiles/
tpm_worker.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! OpenVMM TPM worker policy.
5
6use crate::Builder;
7use crate::Network;
8use crate::Profile;
9use crate::Syscalls;
10
11/// Build the OpenVMM TPM worker policy with an isolated network namespace.
12///
13/// Includes individual loader and OpenSSL configuration files only when
14/// present, without exposing their parent directories or private-key trees.
15/// Nonstandard OpenSSL paths and additional configuration includes require
16/// explicit grants.
17pub fn tpm_worker() -> Builder {
18    let mut profile = Profile::deny_all().name("tpm_worker").read_exec("/usr/lib");
19
20    for path in [
21        "/etc/ld.so.cache",
22        "/etc/ssl/openssl.cnf",
23        "/etc/pki/tls/openssl.cnf",
24        "/usr/local/ssl/openssl.cnf",
25    ] {
26        if std::path::Path::new(path).exists() {
27            profile = profile.read(path);
28        }
29    }
30
31    profile
32        .syscalls(Syscalls::deny([
33            "bpf",
34            "chroot",
35            "clone3",
36            #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
37            "create_module",
38            "delete_module",
39            "execve",
40            "finit_module",
41            #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
42            "fork",
43            "fsconfig",
44            "fsmount",
45            "fsopen",
46            "fspick",
47            "init_module",
48            #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
49            "ioperm",
50            #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
51            "iopl",
52            "kexec_file_load",
53            "kexec_load",
54            "mount",
55            "mount_setattr",
56            "move_mount",
57            "open_tree",
58            "pivot_root",
59            "process_vm_readv",
60            "process_vm_writev",
61            "ptrace",
62            "reboot",
63            "setns",
64            "umount2",
65            "unshare",
66            "userfaultfd",
67            "waitid",
68            "acct",
69            "add_key",
70            "kcmp",
71            "keyctl",
72            "mbind",
73            "request_key",
74        ]))
75        .network(Network::None)
76}
77
78#[cfg(all(test, target_os = "linux"))]
79mod tests {
80    use super::*;
81    use test_with_tracing::test;
82
83    #[test]
84    fn syscall_names_resolve() {
85        let profile = tpm_worker().build();
86        let Syscalls::Deny(names) = profile.inner.syscalls else {
87            panic!("TPM worker must use syscall filtering");
88        };
89        for name in names {
90            assert!(
91                crate::nr_for_name(&name).is_some(),
92                "TPM worker syscall does not resolve: {name}",
93            );
94        }
95    }
96}