-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
seccomp: add syscall emulation for safe syscalls, like mknod of /dev/…
…null devices.
- Loading branch information
Showing
12 changed files
with
531 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright © 2022 Arista Networks, Inc. All rights reserved. | ||
* | ||
* Use of this source code is governed by the MIT license that can be found | ||
* in the LICENSE file. | ||
*/ | ||
|
||
#ifndef ARCH_H_ | ||
# define ARCH_H_ | ||
|
||
# include "config.h" | ||
|
||
# define ARCH_STR_(x) #x | ||
# define ARCH_STR(x) ARCH_STR_(x) | ||
|
||
/* *INDENT-OFF* - formatters try to add spaces here */ | ||
# define ARCH_HEADER_BASE arch/ARCH | ||
/* *INDENT-ON* */ | ||
|
||
# include ARCH_STR(ARCH_HEADER_BASE/syscall.h) | ||
|
||
#endif /* !ARCH_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Copyright © 2022 Arista Networks, Inc. All rights reserved. | ||
* | ||
* Use of this source code is governed by the MIT license that can be found | ||
* in the LICENSE file. | ||
*/ | ||
|
||
#include <stddef.h> | ||
#include <linux/audit.h> | ||
|
||
/* The following is the x86-64-specific BPF boilerplate code for checking | ||
that the BPF program is running on the right architecture + ABI. At | ||
completion of these instructions, the accumulator contains the system | ||
call number. */ | ||
|
||
/* For the x32 ABI, all system call numbers have bit 30 set */ | ||
|
||
#define X32_SYSCALL_BIT 0x40000000 | ||
|
||
#define CHECK_ARCH_AND_LOAD_SYSCALL_NR \ | ||
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \ | ||
(offsetof(struct seccomp_data, arch))), \ | ||
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \ | ||
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \ | ||
(offsetof(struct seccomp_data, nr))), \ | ||
BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \ | ||
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x86 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Copyright © 2022 Arista Networks, Inc. All rights reserved. | ||
* | ||
* Use of this source code is governed by the MIT license that can be found | ||
* in the LICENSE file. | ||
*/ | ||
|
||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "proc.h" | ||
|
||
int proc_read_status(int procfd, struct proc_status *out) | ||
{ | ||
memset(out, 0, sizeof (*out)); | ||
|
||
int statusfd = openat(procfd, "status", O_RDONLY | O_CLOEXEC); | ||
if (statusfd == -1) { | ||
return -1; | ||
} | ||
|
||
FILE *f = fdopen(statusfd, "r"); | ||
|
||
char line[4096]; | ||
while (fgets(line, sizeof (line) - 1, f)) { | ||
sscanf(line, "Umask:\t%o\n", &out->umask); | ||
} | ||
|
||
fclose(f); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* Copyright © 2022 Arista Networks, Inc. All rights reserved. | ||
* | ||
* Use of this source code is governed by the MIT license that can be found | ||
* in the LICENSE file. | ||
*/ | ||
|
||
#ifndef PROC_H_ | ||
# define PROC_H_ | ||
|
||
struct proc_status { | ||
mode_t umask; | ||
}; | ||
|
||
int proc_read_status(int procfd, struct proc_status *out); | ||
|
||
#endif /* !PROC_H_ */ |
Oops, something went wrong.