]> granicus.if.org Git - strace/commitdiff
Convert parser of seccomp filter program to new mpers infrastructure
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 19 Sep 2015 21:28:23 +0000 (21:28 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 20 Sep 2015 00:02:26 +0000 (00:02 +0000)
* 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.

Makefile.am
fetch_seccomp_fprog.c [new file with mode: 0644]
seccomp.c
seccomp_fprog.h [new file with mode: 0644]

index d40823f78a286610f1cdd183163adb9b8a9e6112..241703f17e0f04f78eda904868d1cb9a443cfd4b 100644 (file)
@@ -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 (file)
index 0000000..e32366a
--- /dev/null
@@ -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;
+}
index 71c90c0deeeb8c4edd27636f3ae4729c455c4a9e..71cda7d654334ee2cb4ab449aeac00137cec5731 100644 (file)
--- 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 (file)
index 0000000..6b1f77f
--- /dev/null
@@ -0,0 +1,4 @@
+struct seccomp_fprog {
+       unsigned short len;
+       unsigned long filter;
+};