| 1 |
# seccomp ____________________________________________________ |
| 2 |
# long sys_seccomp(unsigned int op, unsigned int flags, const char __user* uargs) |
| 3 |
|
| 4 |
@define _SYSCALL_SECCOMP_NAME |
| 5 |
%( |
| 6 |
name = "seccomp" |
| 7 |
%) |
| 8 |
|
| 9 |
@define _SYSCALL_SECCOMP_ARGSTR |
| 10 |
%( |
| 11 |
argstr = sprintf("%s, %s, %p", op_str, flags_str, uargs_uaddr) |
| 12 |
%) |
| 13 |
|
| 14 |
@define _SYSCALL_SECCOMP_REGARGS |
| 15 |
%( |
| 16 |
op = uint_arg(1) |
| 17 |
op_str = _seccomp_op_str(op) |
| 18 |
flags = uint_arg(2) |
| 19 |
flags_str = _seccomp_flags_str(flags) |
| 20 |
%( systemtap_v <= "2.9" %? |
| 21 |
uargs = user_string_quoted(pointer_arg(3)) |
| 22 |
uargs_unquoted = user_string_nofault(pointer_arg(3)) |
| 23 |
%) |
| 24 |
uargs_uaddr = pointer_arg(3) |
| 25 |
%) |
| 26 |
|
| 27 |
@define _SYSCALL_SECCOMP_REGARGS_STORE |
| 28 |
%( |
| 29 |
if (@probewrite(op)) |
| 30 |
set_uint_arg(1, op) |
| 31 |
|
| 32 |
if (@probewrite(flags)) |
| 33 |
set_uint_arg(2, flags) |
| 34 |
|
| 35 |
if (@probewrite(uargs_uaddr)) |
| 36 |
set_pointer_arg(3, uargs_uaddr) |
| 37 |
|
| 38 |
%( systemtap_v <= "2.9" %? |
| 39 |
if (@probewrite(uargs_unquoted)) |
| 40 |
set_user_string_arg(pointer_arg(3), uargs_unquoted) |
| 41 |
%) |
| 42 |
%) |
| 43 |
|
| 44 |
probe syscall.seccomp = dw_syscall.seccomp !, nd_syscall.seccomp ? {} |
| 45 |
probe syscall.seccomp.return = dw_syscall.seccomp.return !, |
| 46 |
nd_syscall.seccomp.return ? {} |
| 47 |
|
| 48 |
# dw_seccomp _____________________________________________________ |
| 49 |
|
| 50 |
probe dw_syscall.seccomp = kernel.function("sys_seccomp").call ? |
| 51 |
{ |
| 52 |
@_SYSCALL_SECCOMP_NAME |
| 53 |
op = $op |
| 54 |
op_str = _seccomp_op_str(op) |
| 55 |
flags = $flags |
| 56 |
flags_str = _seccomp_flags_str(flags) |
| 57 |
%( systemtap_v <= "2.9" %? |
| 58 |
uargs = user_string_quoted($uargs) |
| 59 |
%) |
| 60 |
uargs_uaddr = $uargs |
| 61 |
@_SYSCALL_SECCOMP_ARGSTR |
| 62 |
} |
| 63 |
probe dw_syscall.seccomp.return = kernel.function("sys_seccomp").return ? |
| 64 |
{ |
| 65 |
@_SYSCALL_SECCOMP_NAME |
| 66 |
@SYSC_RETVALSTR($return) |
| 67 |
} |
| 68 |
|
| 69 |
# nd_seccomp _____________________________________________________ |
| 70 |
|
| 71 |
probe nd_syscall.seccomp = nd1_syscall.seccomp!, nd2_syscall.seccomp!, tp_syscall.seccomp |
| 72 |
{ } |
| 73 |
|
| 74 |
probe nd1_syscall.seccomp = kprobe.function("sys_seccomp") ? |
| 75 |
{ |
| 76 |
@_SYSCALL_SECCOMP_NAME |
| 77 |
asmlinkage() |
| 78 |
@_SYSCALL_SECCOMP_REGARGS |
| 79 |
@_SYSCALL_SECCOMP_ARGSTR |
| 80 |
} |
| 81 |
|
| 82 |
/* kernel 4.17+ */ |
| 83 |
probe nd2_syscall.seccomp = kprobe.function(@arch_syscall_prefix "sys_seccomp") ? |
| 84 |
{ |
| 85 |
__set_syscall_pt_regs(pointer_arg(1)) |
| 86 |
@_SYSCALL_SECCOMP_NAME |
| 87 |
@_SYSCALL_SECCOMP_REGARGS |
| 88 |
@_SYSCALL_SECCOMP_ARGSTR |
| 89 |
}, |
| 90 |
{ |
| 91 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SECCOMP_REGARGS_STORE %) |
| 92 |
} |
| 93 |
|
| 94 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 95 |
probe tp_syscall.seccomp = kernel.trace("sys_enter") |
| 96 |
{ |
| 97 |
__set_syscall_pt_regs($regs) |
| 98 |
@__syscall_compat_gate(@const("__NR_seccomp"), @const("__NR_compat_seccomp")) |
| 99 |
@_SYSCALL_SECCOMP_NAME |
| 100 |
@_SYSCALL_SECCOMP_REGARGS |
| 101 |
@_SYSCALL_SECCOMP_ARGSTR |
| 102 |
}, |
| 103 |
{ |
| 104 |
%( @_IS_SREG_KERNEL %? @_SYSCALL_SECCOMP_REGARGS_STORE %) |
| 105 |
} |
| 106 |
|
| 107 |
probe nd_syscall.seccomp.return = nd1_syscall.seccomp.return!, nd2_syscall.seccomp.return!, tp_syscall.seccomp.return |
| 108 |
{ } |
| 109 |
|
| 110 |
probe nd1_syscall.seccomp.return = kprobe.function("sys_seccomp").return ? |
| 111 |
{ |
| 112 |
@_SYSCALL_SECCOMP_NAME |
| 113 |
@SYSC_RETVALSTR(returnval()) |
| 114 |
} |
| 115 |
|
| 116 |
/* kernel 4.17+ */ |
| 117 |
probe nd2_syscall.seccomp.return = kprobe.function(@arch_syscall_prefix "sys_seccomp").return ? |
| 118 |
{ |
| 119 |
@_SYSCALL_SECCOMP_NAME |
| 120 |
@SYSC_RETVALSTR(returnval()) |
| 121 |
} |
| 122 |
|
| 123 |
/* kernel 3.5+, but undesirable because it affects all syscalls */ |
| 124 |
probe tp_syscall.seccomp.return = kernel.trace("sys_exit") |
| 125 |
{ |
| 126 |
__set_syscall_pt_regs($regs) |
| 127 |
@__syscall_compat_gate(@const("__NR_seccomp"), @const("__NR_compat_seccomp")) |
| 128 |
@_SYSCALL_SECCOMP_NAME |
| 129 |
@SYSC_RETVALSTR($ret) |
| 130 |
} |