LCOV - code coverage report
Current view: top level - app/shared/commands/run/generated - pidns_seccomp.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 30 0.0 %
Date: 2025-12-07 04:58:33 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
       2             : #ifndef HEADER_fd_src_app_shared_commands_run_generated_pidns_seccomp_h
       3             : #define HEADER_fd_src_app_shared_commands_run_generated_pidns_seccomp_h
       4             : 
       5             : #if defined(__linux__)
       6             : 
       7             : #include "../../../../../../src/util/fd_util_base.h"
       8             : #include <linux/audit.h>
       9             : #include <linux/capability.h>
      10             : #include <linux/filter.h>
      11             : #include <linux/seccomp.h>
      12             : #include <linux/bpf.h>
      13             : #include <linux/unistd.h>
      14             : #include <sys/syscall.h>
      15             : #include <signal.h>
      16             : #include <stddef.h>
      17             : 
      18             : #if defined(__i386__)
      19             : # define ARCH_NR  AUDIT_ARCH_I386
      20             : #elif defined(__x86_64__)
      21             : # define ARCH_NR  AUDIT_ARCH_X86_64
      22             : #elif defined(__aarch64__)
      23             : # define ARCH_NR AUDIT_ARCH_AARCH64
      24             : #else
      25             : # error "Target architecture is unsupported by seccomp."
      26             : #endif
      27             : static const unsigned int sock_filter_policy_pidns_instr_cnt = 25;
      28             : 
      29           0 : static void populate_sock_filter_policy_pidns( ulong out_cnt, struct sock_filter * out, unsigned int logfile_fd ) {
      30           0 :   FD_TEST( out_cnt >= 25 );
      31           0 :   struct sock_filter filter[25] = {
      32             :     /* Check: Jump to RET_KILL_PROCESS if the script's arch != the runtime arch */
      33           0 :     BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, arch ) ) ),
      34           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ARCH_NR, 0, /* RET_KILL_PROCESS */ 21 ),
      35             :     /* loading syscall number in accumulator */
      36           0 :     BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) ) ),
      37             :     /* allow write based on expression */
      38           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 5, 0 ),
      39             :     /* allow fsync based on expression */
      40           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 8, 0 ),
      41             :     /* allow poll based on expression */
      42           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_poll, /* check_poll */ 9, 0 ),
      43             :     /* allow wait4 based on expression */
      44           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_wait4, /* check_wait4 */ 10, 0 ),
      45             :     /* simply allow exit_group */
      46           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_exit_group, /* RET_ALLOW */ 16, 0 ),
      47             :     /* none of the syscalls matched */
      48           0 :     { BPF_JMP | BPF_JA, 0, 0, /* RET_KILL_PROCESS */ 14 },
      49             : //  check_write:
      50             :     /* load syscall argument 0 in accumulator */
      51           0 :     BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
      52           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 2, /* RET_ALLOW */ 13, /* lbl_1 */ 0 ),
      53             : //  lbl_1:
      54             :     /* load syscall argument 0 in accumulator */
      55           0 :     BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
      56           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_ALLOW */ 11, /* RET_KILL_PROCESS */ 10 ),
      57             : //  check_fsync:
      58             :     /* load syscall argument 0 in accumulator */
      59           0 :     BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
      60           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_ALLOW */ 9, /* RET_KILL_PROCESS */ 8 ),
      61             : //  check_poll:
      62             :     /* load syscall argument 2 in accumulator */
      63           0 :     BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
      64           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, (unsigned int)-1, /* RET_ALLOW */ 7, /* RET_KILL_PROCESS */ 6 ),
      65             : //  check_wait4:
      66             :     /* load syscall argument 2 in accumulator */
      67           0 :     BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
      68           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, (int)__WALL | (int)WNOHANG, /* lbl_2 */ 2, /* lbl_3 */ 0 ),
      69             : //  lbl_3:
      70             :     /* load syscall argument 2 in accumulator */
      71           0 :     BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
      72           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, (int)__WALL, /* lbl_2 */ 0, /* RET_KILL_PROCESS */ 2 ),
      73             : //  lbl_2:
      74             :     /* load syscall argument 3 in accumulator */
      75           0 :     BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[3])),
      76           0 :     BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* RET_ALLOW */ 1, /* RET_KILL_PROCESS */ 0 ),
      77             : //  RET_KILL_PROCESS:
      78             :     /* KILL_PROCESS is placed before ALLOW since it's the fallthrough case. */
      79           0 :     BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
      80             : //  RET_ALLOW:
      81             :     /* ALLOW has to be reached by jumping */
      82             :     BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
      83           0 :   };
      84           0 :   fd_memcpy( out, filter, sizeof( filter ) );
      85           0 : }
      86             : 
      87             : #endif /* defined(__linux__) */
      88             : 
      89             : #endif /* HEADER_fd_src_app_shared_commands_run_generated_pidns_seccomp_h */

Generated by: LCOV version 1.14