Skip to content

Commit 2d02799

Browse files
committed
util: Make sure syscall numbers used in profile are defined
Define the following syscall numbers for x86_64, so that the profile will be the same no matter what kernel is built against, including kernels that don't have `__NR_statx`: ```c++ #define __NR_statx 332 #define __NR_getrandom 318 #define __NR_membarrier 324 ```
1 parent 8289d19 commit 2d02799

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/util/syscall_sandbox.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ bool g_syscall_sandbox_log_violation_before_terminating{false};
4444
#define SECCOMP_RET_KILL_PROCESS 0x80000000U
4545
#endif
4646

47+
// Define system call numbers for x86_64 that are referenced in the system call profile
48+
// but not provided by the kernel headers used in the GUIX build.
49+
#ifndef __NR_statx
50+
#define __NR_statx 332
51+
#endif
52+
53+
#ifndef __NR_getrandom
54+
#define __NR_getrandom 318
55+
#endif
56+
57+
#ifndef __NR_membarrier
58+
#define __NR_membarrier 324
59+
#endif
60+
4761
// This list of syscalls in LINUX_SYSCALLS is only used to map syscall numbers to syscall names in
4862
// order to be able to print user friendly error messages which include the syscall name in addition
4963
// to the syscall number.
@@ -162,9 +176,7 @@ const std::map<uint32_t, std::string> LINUX_SYSCALLS{
162176
{__NR_getpmsg, "getpmsg"},
163177
{__NR_getppid, "getppid"},
164178
{__NR_getpriority, "getpriority"},
165-
#if defined(__NR_getrandom)
166179
{__NR_getrandom, "getrandom"},
167-
#endif // defined(__NR_getrandom)
168180
{__NR_getresgid, "getresgid"},
169181
{__NR_getresuid, "getresuid"},
170182
{__NR_getrlimit, "getrlimit"},
@@ -212,9 +224,7 @@ const std::map<uint32_t, std::string> LINUX_SYSCALLS{
212224
{__NR_lstat, "lstat"},
213225
{__NR_madvise, "madvise"},
214226
{__NR_mbind, "mbind"},
215-
#if defined(__NR_membarrier)
216227
{__NR_membarrier, "membarrier"},
217-
#endif // defined(__NR_membarrier)
218228
{__NR_memfd_create, "memfd_create"},
219229
{__NR_migrate_pages, "migrate_pages"},
220230
{__NR_mincore, "mincore"},
@@ -515,9 +525,7 @@ class SeccompPolicyBuilder
515525
{
516526
allowed_syscalls.insert(__NR_brk); // change data segment size
517527
allowed_syscalls.insert(__NR_madvise); // give advice about use of memory
518-
#if defined(__NR_membarrier)
519528
allowed_syscalls.insert(__NR_membarrier); // issue memory barriers on a set of threads
520-
#endif // defined(__NR_membarrier)
521529
allowed_syscalls.insert(__NR_mlock); // lock memory
522530
allowed_syscalls.insert(__NR_mmap); // map files or devices into memory
523531
allowed_syscalls.insert(__NR_mprotect); // set protection on a region of memory
@@ -595,9 +603,7 @@ class SeccompPolicyBuilder
595603

596604
void AllowGetRandom()
597605
{
598-
#if defined(__NR_getrandom)
599606
allowed_syscalls.insert(__NR_getrandom); // obtain a series of random bytes
600-
#endif // defined(__NR_getrandom)
601607
}
602608

603609
void AllowGetSimpleId()

0 commit comments

Comments
 (0)