]> git.karo-electronics.de Git - linux-beck.git/commitdiff
samples/seccomp: Enable PR_SET_NO_NEW_PRIVS in dropper
authorRicky Zhou <rickyz@chromium.org>
Thu, 13 Oct 2016 17:34:08 +0000 (10:34 -0700)
committerKees Cook <keescook@chromium.org>
Tue, 1 Nov 2016 15:58:10 +0000 (08:58 -0700)
Either CAP_SYS_ADMIN or PR_SET_NO_NEW_PRIVS is required to enable
seccomp. This allows samples/seccomp/dropper to be run without
CAP_SYS_ADMIN.

Signed-off-by: Ricky Zhou <rickyz@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
samples/seccomp/dropper.c

index c69c347c7011296a477a8ffaff8123b956901556..68325ca5e71c76de39d2cf2d24097d665926a3ea 100644 (file)
@@ -11,7 +11,6 @@
  * When run, returns the specified errno for the specified
  * system call number against the given architecture.
  *
- * Run this one as root as PR_SET_NO_NEW_PRIVS is not called.
  */
 
 #include <errno.h>
@@ -42,8 +41,12 @@ static int install_filter(int nr, int arch, int error)
                .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
                .filter = filter,
        };
+       if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
+               perror("prctl(NO_NEW_PRIVS)");
+               return 1;
+       }
        if (prctl(PR_SET_SECCOMP, 2, &prog)) {
-               perror("prctl");
+               perror("prctl(PR_SET_SECCOMP)");
                return 1;
        }
        return 0;