1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "host/commands/process_sandboxer/policies.h"
17
18 #include <linux/prctl.h>
19 #include <sys/socket.h>
20 #include <syscall.h>
21
22 #include <string>
23
24 #include <sandboxed_api/sandbox2/policybuilder.h>
25 #include <sandboxed_api/sandbox2/util/bpf_helper.h>
26
27 namespace cuttlefish::process_sandboxer {
28
ProcessRestarterPolicy(const HostInfo & host)29 sandbox2::PolicyBuilder ProcessRestarterPolicy(const HostInfo& host) {
30 std::string sandboxer_proxy = host.HostToolExe("sandboxer_proxy");
31 return BaselinePolicy(host, host.HostToolExe("process_restarter"))
32 .AddDirectory(host.runtime_dir, /* is_ro= */ false)
33 .AddFile(host.cuttlefish_config_path)
34 .AddFileAt(sandboxer_proxy, host.HostToolExe("adb_connector"))
35 .AddFileAt(sandboxer_proxy, host.HostToolExe("casimir"))
36 .AddFileAt(sandboxer_proxy, host.HostToolExe("crosvm"))
37 .AddFileAt(sandboxer_proxy, host.HostToolExe("root-canal"))
38 .AddFileAt(sandboxer_proxy, host.HostToolExe("vhost_device_vsock"))
39 .AddPolicyOnSyscall(__NR_prctl,
40 {ARG_32(0), JEQ32(PR_SET_PDEATHSIG, ALLOW)})
41 .AllowFork()
42 .AllowSafeFcntl()
43 .AllowSyscall(SYS_execve) // To enter sandboxer_proxy
44 .AllowSyscall(SYS_waitid)
45 .AllowTCGETS()
46 // For sandboxer_proxy
47 .AddPolicyOnSyscall(__NR_socket, {ARG_32(0), JEQ32(AF_UNIX, ALLOW)})
48 .AllowExit()
49 .AllowSyscall(SYS_connect)
50 .AllowSyscall(SYS_recvmsg)
51 .AllowSyscall(SYS_sendmsg);
52 }
53
54 } // namespace cuttlefish::process_sandboxer
55