aboutsummaryrefslogtreecommitdiffstats
path: root/executor/android/android_seccomp.h
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-03-11 12:09:17 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-03-11 12:09:17 +0100
commite7caca8e1ed4acd5ba185b96aea8a400cf1717b4 (patch)
tree7072ecbe90099543e5c792a993fdc043e4e1edb1 /executor/android/android_seccomp.h
parent3d010fa6c38290eb00db1c9916d113b84d65dbc4 (diff)
executor: minor cleanup of android sandbox
Fix code formatting, clang-tidy warnings, minor style nits.
Diffstat (limited to 'executor/android/android_seccomp.h')
-rw-r--r--executor/android/android_seccomp.h35
1 files changed, 14 insertions, 21 deletions
diff --git a/executor/android/android_seccomp.h b/executor/android/android_seccomp.h
index 21fd723e3..d8df52792 100644
--- a/executor/android/android_seccomp.h
+++ b/executor/android/android_seccomp.h
@@ -1,4 +1,4 @@
-// Copyright 2016 syzkaller project authors. All rights reserved.
+// Copyright 2020 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// These headers are generated by the Android build system and need to be updated periodically.
@@ -36,23 +36,21 @@ static const size_t primary_app_filter_size = x86_app_filter_size;
#endif
#define syscall_nr (offsetof(struct seccomp_data, nr))
-#define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]))
#define arch_nr (offsetof(struct seccomp_data, arch))
-
typedef struct Filter_t {
struct sock_filter data[kFilterMaxSize];
size_t count;
} Filter;
-inline void push_back(Filter* filter_array, struct sock_filter filter)
+static void push_back(Filter* filter_array, struct sock_filter filter)
{
if (filter_array->count == kFilterMaxSize)
- fail("Can't add another syscall to seccomp filter: count %zu.", filter_array->count);
+ fail("can't add another syscall to seccomp filter: count %zu", filter_array->count);
filter_array->data[filter_array->count++] = filter;
}
-inline void Disallow(Filter* f)
+static void Disallow(Filter* f)
{
struct sock_filter filter = BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_TRAP);
push_back(f, filter);
@@ -60,14 +58,14 @@ inline void Disallow(Filter* f)
static void ExamineSyscall(Filter* f)
{
- struct sock_filter filter = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, syscall_nr);
+ struct sock_filter filter = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, syscall_nr);
push_back(f, filter);
}
static void ValidateArchitecture(Filter* f)
{
- struct sock_filter filter1 = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, arch_nr);
- struct sock_filter filter2 = BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, PRIMARY_ARCH, 1, 0);
+ struct sock_filter filter1 = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, arch_nr);
+ struct sock_filter filter2 = BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, PRIMARY_ARCH, 1, 0);
push_back(f, filter1);
push_back(f, filter2);
Disallow(f);
@@ -77,8 +75,8 @@ static void ValidateArchitecture(Filter* f)
static void install_filter(const Filter* f)
{
struct sock_fprog prog = {
- (unsigned short)f->count,
- (struct sock_filter*)&f->data[0],
+ (unsigned short)f->count,
+ (struct sock_filter*)&f->data[0],
};
// This assumes either the current process has CAP_SYS_ADMIN, or PR_SET_NO_NEW_PRIVS bit is set.
if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog) < 0) {
@@ -87,23 +85,18 @@ static void install_filter(const Filter* f)
}
// Modified from the orignal Android code as we don't need dual arch support
-void set_app_seccomp_filter()
+static void set_app_seccomp_filter()
{
- const struct sock_filter *p;
- size_t p_size;
+ const struct sock_filter* p = primary_app_filter;
+ size_t p_size = primary_app_filter_size;
+
Filter f;
f.count = 0;
-
- p = primary_app_filter;
- p_size = primary_app_filter_size;
-
ValidateArchitecture(&f);
-
ExamineSyscall(&f);
- for (size_t i = 0; i < p_size; ++i) {
+ for (size_t i = 0; i < p_size; ++i)
push_back(&f, p[i]);
- }
Disallow(&f);
// Will fail() if anything fails.