Skip to content

Commit 7a12974

Browse files
committed
Convert parser of seccomp filter program to new mpers infrastructure
* seccomp_fprog.h: New file. * fetch_seccomp_fprog.c: New file. * Makefile.am (strace_SOURCES): Add them. * seccomp.c: Include "seccomp_fprog.h". (print_seccomp_filter): Use fetch_seccomp_fprog.
1 parent 3b73194 commit 7a12974

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ strace_SOURCES = \
5959
fallocate.c \
6060
fanotify.c \
6161
fchownat.c \
62+
fetch_seccomp_fprog.c \
6263
file.c \
6364
futex.c \
6465
get_robust_list.c \
@@ -123,6 +124,7 @@ strace_SOURCES = \
123124
sched.c \
124125
scsi.c \
125126
seccomp.c \
127+
seccomp_fprog.h \
126128
sendfile.c \
127129
sigaltstack.c \
128130
signal.c \

fetch_seccomp_fprog.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "defs.h"
2+
3+
#include DEF_MPERS_TYPE(seccomp_fprog_t)
4+
5+
#include "seccomp_fprog.h"
6+
typedef struct seccomp_fprog seccomp_fprog_t;
7+
8+
#include MPERS_DEFS
9+
10+
MPERS_PRINTER_DECL(bool, fetch_seccomp_fprog)(struct tcb *tcp, const long addr, void *p)
11+
{
12+
struct seccomp_fprog *pfp = p;
13+
seccomp_fprog_t mfp;
14+
15+
if (sizeof(*pfp) == sizeof(mfp))
16+
return !umove_or_printaddr(tcp, addr, pfp);
17+
18+
if (umove_or_printaddr(tcp, addr, &mfp))
19+
return false;
20+
21+
pfp->len = mfp.len;
22+
pfp->filter = mfp.filter;
23+
return true;
24+
}

seccomp.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,30 +190,15 @@ decode_fprog(struct tcb *tcp, unsigned short len, unsigned long addr)
190190
}
191191
}
192192

193+
#include "seccomp_fprog.h"
194+
193195
void
194196
print_seccomp_filter(struct tcb *tcp, unsigned long addr)
195197
{
196-
#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
197-
if (current_wordsize == 4) {
198-
struct {
199-
unsigned short len;
200-
uint32_t filter;
201-
} fprog;
202-
203-
if (!umove_or_printaddr(tcp, addr, &fprog))
204-
decode_fprog(tcp, fprog.len, fprog.filter);
205-
} else {
206-
#endif
207-
struct {
208-
unsigned short len;
209-
unsigned long filter;
210-
} fprog;
211-
212-
if (!umove_or_printaddr(tcp, addr, &fprog))
213-
decode_fprog(tcp, fprog.len, fprog.filter);
214-
#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
215-
}
216-
#endif
198+
struct seccomp_fprog fprog;
199+
200+
if (fetch_seccomp_fprog(tcp, addr, &fprog))
201+
decode_fprog(tcp, fprog.len, fprog.filter);
217202
}
218203

219204
static void

seccomp_fprog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
struct seccomp_fprog {
2+
unsigned short len;
3+
unsigned long filter;
4+
};

0 commit comments

Comments
 (0)