From: Dmitry V. Levin Date: Sat, 19 Sep 2015 21:28:23 +0000 (+0000) Subject: Convert parser of seccomp filter program to new mpers infrastructure X-Git-Tag: v4.11~164 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a12974e9537c4ebaecada2a56f97dfa201f03db;p=strace 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. --- diff --git a/Makefile.am b/Makefile.am index d40823f7..241703f1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -59,6 +59,7 @@ strace_SOURCES = \ fallocate.c \ fanotify.c \ fchownat.c \ + fetch_seccomp_fprog.c \ file.c \ futex.c \ get_robust_list.c \ @@ -123,6 +124,7 @@ strace_SOURCES = \ sched.c \ scsi.c \ seccomp.c \ + seccomp_fprog.h \ sendfile.c \ sigaltstack.c \ signal.c \ diff --git a/fetch_seccomp_fprog.c b/fetch_seccomp_fprog.c new file mode 100644 index 00000000..e32366ad --- /dev/null +++ b/fetch_seccomp_fprog.c @@ -0,0 +1,24 @@ +#include "defs.h" + +#include DEF_MPERS_TYPE(seccomp_fprog_t) + +#include "seccomp_fprog.h" +typedef struct seccomp_fprog seccomp_fprog_t; + +#include MPERS_DEFS + +MPERS_PRINTER_DECL(bool, fetch_seccomp_fprog)(struct tcb *tcp, const long addr, void *p) +{ + struct seccomp_fprog *pfp = p; + seccomp_fprog_t mfp; + + if (sizeof(*pfp) == sizeof(mfp)) + return !umove_or_printaddr(tcp, addr, pfp); + + if (umove_or_printaddr(tcp, addr, &mfp)) + return false; + + pfp->len = mfp.len; + pfp->filter = mfp.filter; + return true; +} diff --git a/seccomp.c b/seccomp.c index 71c90c0d..71cda7d6 100644 --- a/seccomp.c +++ b/seccomp.c @@ -190,30 +190,15 @@ decode_fprog(struct tcb *tcp, unsigned short len, unsigned long addr) } } +#include "seccomp_fprog.h" + void print_seccomp_filter(struct tcb *tcp, unsigned long addr) { -#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 - if (current_wordsize == 4) { - struct { - unsigned short len; - uint32_t filter; - } fprog; - - if (!umove_or_printaddr(tcp, addr, &fprog)) - decode_fprog(tcp, fprog.len, fprog.filter); - } else { -#endif - struct { - unsigned short len; - unsigned long filter; - } fprog; - - if (!umove_or_printaddr(tcp, addr, &fprog)) - decode_fprog(tcp, fprog.len, fprog.filter); -#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 - } -#endif + struct seccomp_fprog fprog; + + if (fetch_seccomp_fprog(tcp, addr, &fprog)) + decode_fprog(tcp, fprog.len, fprog.filter); } static void diff --git a/seccomp_fprog.h b/seccomp_fprog.h new file mode 100644 index 00000000..6b1f77ff --- /dev/null +++ b/seccomp_fprog.h @@ -0,0 +1,4 @@ +struct seccomp_fprog { + unsigned short len; + unsigned long filter; +};