2 * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifdef HAVE_LINUX_SECCOMP_H
31 # include <linux/seccomp.h>
33 #include "xlat/seccomp_ops.h"
34 #include "xlat/seccomp_filter_flags.h"
36 #ifdef HAVE_LINUX_FILTER_H
37 # include <linux/filter.h>
38 # include "xlat/bpf_class.h"
39 # include "xlat/bpf_miscop.h"
40 # include "xlat/bpf_mode.h"
41 # include "xlat/bpf_op_alu.h"
42 # include "xlat/bpf_op_jmp.h"
43 # include "xlat/bpf_rval.h"
44 # include "xlat/bpf_size.h"
45 # include "xlat/bpf_src.h"
47 # ifndef SECCOMP_RET_ACTION
48 # define SECCOMP_RET_ACTION 0x7fff0000U
50 # include "xlat/seccomp_ret_action.h"
60 #ifdef HAVE_LINUX_FILTER_H
63 decode_bpf_code(uint16_t code)
65 uint16_t i = code & ~BPF_CLASS(code);
67 printxval(bpf_class, BPF_CLASS(code), "BPF_???");
68 switch (BPF_CLASS(code)) {
72 printxval(bpf_size, BPF_SIZE(code), "BPF_???");
74 printxval(bpf_mode, BPF_MODE(code), "BPF_???");
79 tprintf(" | %#x /* %s */", i, "BPF_???");
83 printxval(bpf_src, BPF_SRC(code), "BPF_???");
85 printxval(bpf_op_alu, BPF_OP(code), "BPF_???");
89 printxval(bpf_src, BPF_SRC(code), "BPF_???");
91 printxval(bpf_op_jmp, BPF_OP(code), "BPF_???");
95 printxval(bpf_rval, BPF_RVAL(code), "BPF_???");
98 tprintf(" | %#x /* %s */", i, "BPF_???");
102 printxval(bpf_miscop, BPF_MISCOP(code), "BPF_???");
103 i &= ~BPF_MISCOP(code);
105 tprintf(" | %#x /* %s */", i, "BPF_???");
112 decode_bpf_stmt(const struct bpf_filter *filter)
114 #ifdef HAVE_LINUX_FILTER_H
115 tprints("BPF_STMT(");
116 decode_bpf_code(filter->code);
118 if (BPF_CLASS(filter->code) == BPF_RET) {
119 unsigned int action = SECCOMP_RET_ACTION & filter->k;
120 unsigned int data = filter->k & ~action;
122 printxval(seccomp_ret_action, action, "SECCOMP_RET_???");
124 tprintf(" | %#x)", data);
128 tprintf("%#x)", filter->k);
131 tprintf("BPF_STMT(%#x, %#x)", filter->code, filter->k);
132 #endif /* HAVE_LINUX_FILTER_H */
136 decode_bpf_jump(const struct bpf_filter *filter)
138 #ifdef HAVE_LINUX_FILTER_H
139 tprints("BPF_JUMP(");
140 decode_bpf_code(filter->code);
141 tprintf(", %#x, %#x, %#x)",
142 filter->k, filter->jt, filter->jf);
144 tprintf("BPF_JUMP(%#x, %#x, %#x, %#x)",
145 filter->code, filter->k, filter->jt, filter->jf);
146 #endif /* HAVE_LINUX_FILTER_H */
150 decode_filter(const struct bpf_filter *filter)
152 if (filter->jt || filter->jf)
153 decode_bpf_jump(filter);
155 decode_bpf_stmt(filter);
158 #endif /* HAVE_LINUX_FILTER_H */
161 # define BPF_MAXINSNS 4096
165 decode_fprog(struct tcb *tcp, unsigned short len, unsigned long addr)
167 if (!len || abbrev(tcp)) {
168 tprintf("{len = %u, filter = ", len);
175 while (i < len && i < BPF_MAXINSNS) {
176 struct bpf_filter filter;
178 if (umove(tcp, addr, &filter) < 0)
182 decode_filter(&filter);
184 addr += sizeof(filter);
193 #include "seccomp_fprog.h"
196 print_seccomp_filter(struct tcb *tcp, unsigned long addr)
198 struct seccomp_fprog fprog;
200 if (fetch_seccomp_fprog(tcp, addr, &fprog))
201 decode_fprog(tcp, fprog.len, fprog.filter);
205 decode_seccomp_set_mode_strict(unsigned int flags, unsigned long addr)
207 tprintf("%u, ", flags);
213 unsigned int op = tcp->u_arg[0];
215 printxval(seccomp_ops, op, "SECCOMP_SET_MODE_???");
218 if (op == SECCOMP_SET_MODE_FILTER) {
219 printflags(seccomp_filter_flags, tcp->u_arg[1],
220 "SECCOMP_FILTER_FLAG_???");
222 print_seccomp_filter(tcp, tcp->u_arg[2]);
224 decode_seccomp_set_mode_strict(tcp->u_arg[1],