• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #include "host/commands/process_sandboxer/policies.h"
18 
19 #include <errno.h>
20 #include <sys/mman.h>
21 #include <sys/socket.h>
22 #include <sys/syscall.h>
23 
24 #include <sandboxed_api/sandbox2/policybuilder.h>
25 #include <sandboxed_api/sandbox2/util/bpf_helper.h>
26 
27 namespace cuttlefish::process_sandboxer {
28 
GnssGrpcProxyPolicy(const HostInfo & host)29 sandbox2::PolicyBuilder GnssGrpcProxyPolicy(const HostInfo& host) {
30   return BaselinePolicy(host, host.HostToolExe("gnss_grpc_proxy"))
31       .AddDirectory(host.InstanceUdsDir(), /* is_ro= */ false)
32       .AddDirectory(host.log_dir, /* is_ro= */ false)
33       .AddFile("/dev/urandom")  // For gRPC
34       .AddFile(host.cuttlefish_config_path)
35       .AddPolicyOnSyscall(__NR_socket, {ARG_32(0), JEQ32(AF_UNIX, ALLOW),
36                                         JEQ32(AF_INET, ERRNO(EACCES)),
37                                         JEQ32(AF_INET6, ERRNO(EACCES))})
38       .AllowEventFd()
39       .AllowSafeFcntl()
40       .AllowSleep()
41       .AllowSyscall(__NR_bind)
42       .AllowSyscall(__NR_clone)  // multithreading
43       .AllowSyscall(__NR_getpeername)
44       .AllowSyscall(__NR_getsockname)
45       .AllowSyscall(__NR_listen)
46       .AddPolicyOnSyscall(__NR_madvise,
47                           {ARG_32(2), JEQ32(MADV_DONTNEED, ALLOW)})
48       .AllowSyscall(__NR_recvmsg)
49       .AllowSyscall(__NR_sched_getparam)
50       .AllowSyscall(__NR_sched_getscheduler)
51       .AllowSyscall(__NR_sched_yield)
52       .AllowSyscall(__NR_shutdown)
53       .AllowSyscall(__NR_sendmsg)
54       .AllowSyscalls({__NR_accept, __NR_accept4})
55       .AllowTCGETS();
56 }
57 
58 }  // namespace cuttlefish::process_sandboxer
59