Skip to contentSkip to conversation

seccomp branch queue

GIT PULL Eduardo Otubo 3 participants 7 messages Jul 25, 2018 – Jul 26, 2018

lore
Share & tools
lore
#0 lore raw

The following changes since commit 18a398f6a39df4b08ff86ac0d38384193ca5f4cc:

Update version for v3.0.0-rc2 release (2018-07-24 22:06:31 +0100)

are available in the Git repository at:

https://github.com/otubo/qemu.git tags/pull-seccomp-20180725

for you to fetch changes up to 5b2f59307372bae13a2ff95706646674eccb65e0:

RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available (2018-07-25 16:07:31 +0200)

----------------------------------------------------------------
pull-seccomp-20180725

----------------------------------------------------------------
Marc-André Lureau (2):
seccomp: use SIGSYS signal instead of killing the thread
RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available

 qemu-seccomp.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
#1 lore raw

[Qemu-devel] [PULL 1/2] seccomp: use SIGSYS signal instead of killing the thread

From: Marc-André Lureau <[email protected]>

The seccomp action SCMP_ACT_KILL results in immediate termination of the thread that made the bad system call. However, qemu being multi-threaded, it keeps running. There is no easy way for parent process / management layer (libvirt) to know about that situation.

Instead, the default SIGSYS handler when invoked with SCMP_ACT_TRAP will terminate the program and core dump.

This may not be the most secure solution, but probably better than just killing the offending thread. SCMP_ACT_KILL_PROCESS has been added in Linux 4.14 to improve the situation, which I propose to use by default if available in the next patch.

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=1594456

---
 qemu-seccomp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-seccomp.c +1 -1
index 9cd8eb9499..b117a92559 100644
@@ -125,7 +125,7 @@ static int seccomp_start(uint32_t seccomp_opts)
             continue;
         }
 
-        rc = seccomp_rule_add_array(ctx, SCMP_ACT_KILL, blacklist[i].num,
+        rc = seccomp_rule_add_array(ctx, SCMP_ACT_TRAP, blacklist[i].num,
                                     blacklist[i].narg, blacklist[i].arg_cmp);
         if (rc < 0) {
             goto seccomp_return;
Signature · 1 line
2.17.1
#2 lore raw

[Qemu-devel] [PULL 2/2] RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available

In reply to Eduardo Otubo

From: Marc-André Lureau <[email protected]>

The upcoming libseccomp release should have SCMP_ACT_KILL_PROCESS action (https://github.com/seccomp/libseccomp/issues/96).

SCMP_ACT_KILL_PROCESS is preferable to immediately terminate the offending process, rather than having the SIGSYS handler running.

Use SECCOMP_GET_ACTION_AVAIL to check availability of kernel support, as libseccomp will fallback on SCMP_ACT_KILL otherwise, and we still prefer SCMP_ACT_TRAP.

---
 qemu-seccomp.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
qemu-seccomp.c +29 -1
index b117a92559..505887d5af 100644
@@ -20,6 +20,7 @@
 #include <sys/prctl.h>
 #include <seccomp.h>
 #include "sysemu/seccomp.h"
+#include <linux/seccomp.h>
 
 /* For some architectures (notably ARM) cacheflush is not supported until
  * libseccomp 2.2.3, but configure enforces that we are using a more recent
@@ -107,12 +108,39 @@ static const struct QemuSeccompSyscall blacklist[] = {
     { SCMP_SYS(sched_get_priority_min), QEMU_SECCOMP_SET_RESOURCECTL },
 };
 
+static inline int
+qemu_seccomp(unsigned int operation, unsigned int flags, void *args)
+{
+#ifdef __NR_seccomp
+    return syscall(__NR_seccomp, operation, flags, args);
+#else
+    return -1;
+#endif
+}
+
+static uint32_t qemu_seccomp_get_kill_action(void)
+{
+#if defined(SECCOMP_GET_ACTION_AVAIL) && defined(SCMP_ACT_KILL_PROCESS) && \
+    defined(SECCOMP_RET_KILL_PROCESS)
+    {
+        uint32_t action = SECCOMP_RET_KILL_PROCESS;
+
+        if (qemu_seccomp(SECCOMP_GET_ACTION_AVAIL, 0, &action) == 0) {
+            return SCMP_ACT_KILL_PROCESS;
+        }
+    }
+#endif
+
+    return SCMP_ACT_TRAP;
+}
+
 
 static int seccomp_start(uint32_t seccomp_opts)
 {
     int rc = 0;
     unsigned int i = 0;
     scmp_filter_ctx ctx;
+    uint32_t action = qemu_seccomp_get_kill_action();
 
     ctx = seccomp_init(SCMP_ACT_ALLOW);
     if (ctx == NULL) {
@@ -125,7 +153,7 @@ static int seccomp_start(uint32_t seccomp_opts)
             continue;
         }
 
-        rc = seccomp_rule_add_array(ctx, SCMP_ACT_TRAP, blacklist[i].num,
+        rc = seccomp_rule_add_array(ctx, action, blacklist[i].num,
                                     blacklist[i].narg, blacklist[i].arg_cmp);
         if (rc < 0) {
             goto seccomp_return;
Signature · 1 line
2.17.1
#3 lore raw
In reply to Eduardo Otubo
Quoted 12 lines · Eduardo Otubo

The following changes since commit 18a398f6a39df4b08ff86ac0d38384193ca5f4cc:

Update version for v3.0.0-rc2 release (2018-07-24 22:06:31 +0100)

are available in the Git repository at:

https://github.com/otubo/qemu.git tags/pull-seccomp-20180725

for you to fetch changes up to 5b2f59307372bae13a2ff95706646674eccb65e0:

RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available (2018-07-25 16:07:31 +0200)

Quoted 7 lines

----------------------------------------------------------------
pull-seccomp-20180725

----------------------------------------------------------------
Marc-André Lureau (2):
seccomp: use SIGSYS signal instead of killing the thread
RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available

Hi. This fails to compile with clang:

CC qemu-seccomp.o
qemu-seccomp.c:112:1: error: unused function 'qemu_seccomp' [-Werror,-Wunused-function]
qemu_seccomp(unsigned int operation, unsigned int flags, void *args) ^

This is because clang is stricter about warning about static inline functions defined in .c files but never used and your ifdef guard on the callsite is not matched by one around the function definition.

thanks
-- PMM

#4 lore raw
Quoted 29 lines · Peter Maydell
Quoted 12 lines · Eduardo Otubo

The following changes since commit 18a398f6a39df4b08ff86ac0d38384193ca5f4cc:

Update version for v3.0.0-rc2 release (2018-07-24 22:06:31 +0100)

are available in the Git repository at:

https://github.com/otubo/qemu.git tags/pull-seccomp-20180725

for you to fetch changes up to 5b2f59307372bae13a2ff95706646674eccb65e0:

RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available (2018-07-25 16:07:31 +0200)

Quoted 7 lines

----------------------------------------------------------------
pull-seccomp-20180725

----------------------------------------------------------------
Marc-André Lureau (2):
seccomp: use SIGSYS signal instead of killing the thread
RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available

Hi. This fails to compile with clang:

CC qemu-seccomp.o
qemu-seccomp.c:112:1: error: unused function 'qemu_seccomp' [-Werror,-Wunused-function]
qemu_seccomp(unsigned int operation, unsigned int flags, void *args) ^

Quoted 5 lines

This is because clang is stricter about warning about static inline functions defined in .c files but never used and your ifdef guard on the callsite is not matched by one around the function definition.

Peter, sorry for not catching that before.
Marc, can you fix and resend?

Signature · 1 line
Eduardo Otubo
#5 lore raw

H

Quoted 30 lines · Eduardo Otubo
Quoted 29 lines · Peter Maydell
Quoted 12 lines · Eduardo Otubo

The following changes since commit 18a398f6a39df4b08ff86ac0d38384193ca5f4cc:

Update version for v3.0.0-rc2 release (2018-07-24 22:06:31 +0100)

are available in the Git repository at:

https://github.com/otubo/qemu.git tags/pull-seccomp-20180725

for you to fetch changes up to 5b2f59307372bae13a2ff95706646674eccb65e0:

RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available (2018-07-25 16:07:31 +0200)

Quoted 7 lines

----------------------------------------------------------------
pull-seccomp-20180725

----------------------------------------------------------------
Marc-André Lureau (2):
seccomp: use SIGSYS signal instead of killing the thread
RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available

Hi. This fails to compile with clang:

CC qemu-seccomp.o
qemu-seccomp.c:112:1: error: unused function 'qemu_seccomp' [-Werror,-Wunused-function]
qemu_seccomp(unsigned int operation, unsigned int flags, void *args) ^

Quoted 8 lines
Quoted 5 lines

This is because clang is stricter about warning about static inline functions defined in .c files but never used and your ifdef guard on the callsite is not matched by one around the function definition.

Peter, sorry for not catching that before.
Marc, can you fix and resend?

I suggest to drop that patch from 3.0. Since it will require a newer libseccomp to be actually useful, it can be delayed imho.

Signature · 1 line
Marc-André Lureau
#6 lore raw
In reply to Peter Maydell

Hi

Quoted 29 lines · Peter Maydell
Quoted 12 lines · Eduardo Otubo

The following changes since commit 18a398f6a39df4b08ff86ac0d38384193ca5f4cc:

Update version for v3.0.0-rc2 release (2018-07-24 22:06:31 +0100)

are available in the Git repository at:

https://github.com/otubo/qemu.git tags/pull-seccomp-20180725

for you to fetch changes up to 5b2f59307372bae13a2ff95706646674eccb65e0:

RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available (2018-07-25 16:07:31 +0200)

Quoted 7 lines

----------------------------------------------------------------
pull-seccomp-20180725

----------------------------------------------------------------
Marc-André Lureau (2):
seccomp: use SIGSYS signal instead of killing the thread
RFC: seccomp: prefer SCMP_ACT_KILL_PROCESS if available

Hi. This fails to compile with clang:

CC qemu-seccomp.o
qemu-seccomp.c:112:1: error: unused function 'qemu_seccomp' [-Werror,-Wunused-function]
qemu_seccomp(unsigned int operation, unsigned int flags, void *args) ^

Quoted 5 lines

This is because clang is stricter about warning about static inline functions defined in .c files but never used and your ifdef guard on the callsite is not matched by one around the function definition.

https://lkml.org/lkml/2017/6/6/631 ;)

Signature · 1 line
Marc-André Lureau