]> granicus.if.org Git - strace/blob - bpf_seccomp_filter.c
xlat: add BPF_F_TEST_STATE_FREQ to bpf_prog_flags
[strace] / bpf_seccomp_filter.c
1 /*
2  * Decoder of seccomp filter programs.
3  *
4  * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: LGPL-2.1-or-later
8  */
9
10 #include "defs.h"
11
12 #include "bpf_filter.h"
13
14 #include <linux/filter.h>
15 #ifdef HAVE_LINUX_SECCOMP_H
16 # include <linux/seccomp.h>
17 #endif
18 #ifndef SECCOMP_RET_ACTION_FULL
19 # define SECCOMP_RET_ACTION_FULL 0xffff0000U
20 #endif
21 #include "xlat/seccomp_ret_action.h"
22
23 static bool
24 print_seccomp_filter_k(const struct bpf_filter_block *const fp)
25 {
26         if (BPF_CLASS(fp->code) == BPF_RET) {
27                 unsigned int action = SECCOMP_RET_ACTION_FULL & fp->k;
28                 unsigned int data = fp->k & ~action;
29
30                 printxval(seccomp_ret_action, action, "SECCOMP_RET_???");
31                 if (data)
32                         tprintf("|%#x", data);
33
34                 return true;
35         }
36
37         return false;
38 }
39
40 void
41 print_seccomp_fprog(struct tcb *const tcp, const kernel_ulong_t addr,
42                     const unsigned short len)
43 {
44         print_bpf_fprog(tcp, addr, len, print_seccomp_filter_k);
45 }
46
47 void
48 decode_seccomp_fprog(struct tcb *const tcp, const kernel_ulong_t addr)
49 {
50         decode_bpf_fprog(tcp, addr, print_seccomp_filter_k);
51 }