Skip to contentSkip to conversation

Bug: Sandbox: libvirt breakdowns qemu guest

PATCH Superseded Yi Min Zhao 6 participants 14 messages May 7, 2018 – May 9, 2018

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Bug: Sandbox: libvirt breakdowns qemu guest

1. Problem Description
======================
If QEMU is built without seccomp support, 'elevatorprivileges' remains compiled. This option of sandbox is treated as an indication for seccomp blacklist support in libvirt. This behavior is introduced by the libvirt commits 31ca6a5 and 3527f9d. It would make libvirt build wrong QEMU cmdline, and then the guest startup would fail.

2. Libvirt Log
==============
qemu-system-s390x: -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
resourcecontrol=deny: seccomp support is disabled

3. Fixup
========
Wrap the options except 'enable' for qemu_sandbox_opts by CONFIG_SECCOMP.

Yi Min Zhao (1):
sandbox: avoid to compile options if CONFIG_SECCOMP undefined

 vl.c | 2 ++
 1 file changed, 2 insertions(+)
Signature · 1 line
2.15.1 (Apple Git-101)
#1 lore raw

PATCH 1/1 sandbox: avoid to compile options if CONFIG_SECCOMP undefined

If CONFIG_SECCOMP is undefined, the option 'elevatorprivileges' remains complied. This would make libvirt set the corresponding capability and then trigger the guest startup fails. So let's wrap the options with CONFIG_SECCOMP.

---
 vl.c | 2 ++
 1 file changed, 2 insertions(+)
vl.c +2 -0
index fce1fd12d8..cb07b19c02 100644
@@ -268,6 +268,7 @@ static QemuOptsList qemu_sandbox_opts = {
             .name = "enable",
             .type = QEMU_OPT_BOOL,
         },
+#ifdef CONFIG_SECCOMP
         {
             .name = "obsolete",
             .type = QEMU_OPT_STRING,
@@ -284,6 +285,7 @@ static QemuOptsList qemu_sandbox_opts = {
             .name = "resourcecontrol",
             .type = QEMU_OPT_STRING,
         },
+#endif
         { /* end of list */ }
     },
 };
Signature · 1 line
2.15.1 (Apple Git-101)
Acked-by on v1 1/1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/1] sandbox: avoid to compile options if CONFIG_SECCOMP undefined

Quoted 33 lines · Yi Min Zhao

If CONFIG_SECCOMP is undefined, the option 'elevatorprivileges' remains complied. This would make libvirt set the corresponding capability and then trigger the guest startup fails. So let's wrap the options with CONFIG_SECCOMP.

---
 vl.c | 2 ++
 1 file changed, 2 insertions(+)
vl.c +2 -0
index fce1fd12d8..cb07b19c02 100644
@@ -268,6 +268,7 @@ static QemuOptsList qemu_sandbox_opts = {
             .name = "enable",
             .type = QEMU_OPT_BOOL,
         },
+#ifdef CONFIG_SECCOMP
         {
             .name = "obsolete",
             .type = QEMU_OPT_STRING,
@@ -284,6 +285,7 @@ static QemuOptsList qemu_sandbox_opts = {
             .name = "resourcecontrol",
             .type = QEMU_OPT_STRING,
         },
+#endif
         { /* end of list */ }
     },
 };
Signature · 1 line
2.15.1 (Apple Git-101)
#3 lore raw

Re: [Qemu-devel] [PATCH 1/1] sandbox: avoid to compile options if CONFIG_SECCOMP undefined

Quoted 27 lines · Eduardo Otubo
Quoted 26 lines · Yi Min Zhao

If CONFIG_SECCOMP is undefined, the option 'elevatorprivileges' remains complied. This would make libvirt set the corresponding capability and then trigger the guest startup fails. So let's wrap the options with CONFIG_SECCOMP.

---
  vl.c | 2 ++
  1 file changed, 2 insertions(+)
vl.c +1 -0
index fce1fd12d8..cb07b19c02 100644
@@ -268,6 +268,7 @@ static QemuOptsList qemu_sandbox_opts = {
              .name = "enable",
              .type = QEMU_OPT_BOOL,
          },
+#ifdef CONFIG_SECCOMP
          {
              .name = "obsolete",
              .type = QEMU_OPT_STRING,
@@ -284,6 +285,7 @@ static QemuOptsList qemu_sandbox_opts = {
              .name = "resourcecontrol",
              .type = QEMU_OPT_STRING,
          },
Quoted 10 lines
Quoted 7 lines
vl.c +1 -0
+#endif
          { /* end of list */ }
      },
  };
Signature · 1 line
2.15.1 (Apple Git-101)

Thanks for your review!

#4 lore raw

Re: [Qemu-devel] [PATCH 1/1] sandbox: avoid to compile options if CONFIG_SECCOMP undefined

In reply to Yi Min Zhao

On 05/06/2018 10:32 PM, Yi Min Zhao wrote:

In the subject line: s/avoid to compile/avoid compiling/

Quoted 1 line

If CONFIG_SECCOMP is undefined, the option 'elevatorprivileges' remains

s/elevator/elevate/

Quoted 1 line

complied. This would make libvirt set the corresponding capability and

s/complied/compiled/

Quoted 21 lines

then trigger the guest startup fails. So let's wrap the options with CONFIG_SECCOMP.

---
  vl.c | 2 ++
  1 file changed, 2 insertions(+)
vl.c +1 -0
index fce1fd12d8..cb07b19c02 100644
@@ -268,6 +268,7 @@ static QemuOptsList qemu_sandbox_opts = {
              .name = "enable",
              .type = QEMU_OPT_BOOL,
          },
+#ifdef CONFIG_SECCOMP
          {
              .name = "obsolete",
              .type = QEMU_OPT_STRING,

vl.c static QemuOptsList qemu_sandbox_opts = { · line 288

Quoted 4 lines
vl.c +1 -0
@@ -284,6 +285,7 @@ static QemuOptsList qemu_sandbox_opts = {
              .name = "resourcecontrol",
              .type = QEMU_OPT_STRING,
          },
+#endif

The commit message mentions only 'elevateprivileges' (once the typo is fixed), but you are also crippling 'obsolete', 'spawn', and 'resourcecontrol'. Perhaps the commit message should call that out better? Or, since libvirt is looking at just 'elevateprivileges', per this line in libvirt's qemu_capabilities.c:

src/qemu/qemu_capabilities.c: { "sandbox", "elevateprivileges", QEMU_CAPS_SECCOMP_BLACKLIST },

is it sufficient to just mask out that one option?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#5 lore raw

Re: [Qemu-devel] [PATCH 1/1] sandbox: avoid to compile options if CONFIG_SECCOMP undefined

Quoted 11 lines · Eric Blake

On 05/06/2018 10:32 PM, Yi Min Zhao wrote:

In the subject line: s/avoid to compile/avoid compiling/

Quoted 1 line

If CONFIG_SECCOMP is undefined, the option 'elevatorprivileges' remains

s/elevator/elevate/

Quoted 1 line

complied. This would make libvirt set the corresponding capability and

s/complied/compiled/

Thanks for your correction.

Quoted 29 lines
Quoted 22 lines

then trigger the guest startup fails. So let's wrap the options with CONFIG_SECCOMP.

---
  vl.c | 2 ++

  1 file changed, 2 insertions(+)
vl.c +1 -0
index fce1fd12d8..cb07b19c02 100644
@@ -268,6 +268,7 @@ static QemuOptsList qemu_sandbox_opts = {
               .name = "enable",
               .type = QEMU_OPT_BOOL,
           },
+#ifdef CONFIG_SECCOMP
           {
               .name = "obsolete",
               .type = QEMU_OPT_STRING,

vl.c static QemuOptsList qemu_sandbox_opts = { · line 288

Quoted 4 lines
vl.c +1 -0
@@ -284,6 +285,7 @@ static QemuOptsList qemu_sandbox_opts = {
               .name = "resourcecontrol",
               .type = QEMU_OPT_STRING,
           },
+#endif

The commit message mentions only 'elevateprivileges' (once the typo is fixed), but you are also crippling 'obsolete', 'spawn', and 'resourcecontrol'.  Perhaps the commit message should call that out better?  Or, since libvirt is looking at just 'elevateprivileges', per this line in libvirt's qemu_capabilities.c:

Quoted 4 lines

src/qemu/qemu_capabilities.c:    { "sandbox", "elevateprivileges", QEMU_CAPS_SECCOMP_BLACKLIST },

is it sufficient to just mask out that one option?

The problem is caused by 'elevateprivileges' ostensibly from Libvirt point of view. But in Qemu, CONFIG_SECCOMP controls other options except 'enable' in parse_sandbox(). So if SECCOMP is not configured, we don't need other options instead of only elevateprivileges.

#6 lore raw

Re: [Qemu-devel] [PATCH 1/1] sandbox: avoid to compile options if CONFIG_SECCOMP undefined

In reply to Eric Blake
Quoted 44 lines · Eric Blake

On 05/06/2018 10:32 PM, Yi Min Zhao wrote:

In the subject line: s/avoid to compile/avoid compiling/

Quoted 1 line

If CONFIG_SECCOMP is undefined, the option 'elevatorprivileges' remains

s/elevator/elevate/

Quoted 1 line

complied. This would make libvirt set the corresponding capability and

s/complied/compiled/

Quoted 21 lines

then trigger the guest startup fails. So let's wrap the options with CONFIG_SECCOMP.

---
  vl.c | 2 ++
  1 file changed, 2 insertions(+)
vl.c +1 -0
index fce1fd12d8..cb07b19c02 100644
@@ -268,6 +268,7 @@ static QemuOptsList qemu_sandbox_opts = {
              .name = "enable",
              .type = QEMU_OPT_BOOL,
          },
+#ifdef CONFIG_SECCOMP
          {
              .name = "obsolete",
              .type = QEMU_OPT_STRING,

vl.c static QemuOptsList qemu_sandbox_opts = { · line 288

Quoted 4 lines
vl.c +1 -0
@@ -284,6 +285,7 @@ static QemuOptsList qemu_sandbox_opts = {
              .name = "resourcecontrol",
              .type = QEMU_OPT_STRING,
          },
+#endif

The commit message mentions only 'elevateprivileges' (once the typo is fixed), but you are also crippling 'obsolete', 'spawn', and 'resourcecontrol'. Perhaps the commit message should call that out better? Or, since libvirt is looking at just 'elevateprivileges', per this line in libvirt's qemu_capabilities.c:

Quoted 4 lines

src/qemu/qemu_capabilities.c: { "sandbox", "elevateprivileges",
QEMU_CAPS_SECCOMP_BLACKLIST },

is it sufficient to just mask out that one option?

If seccomp is disabled, we should really disable the entire -sandbox argument, not merly the options to it.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw

Re: [Qemu-devel] [PATCH 1/1] sandbox: avoid to compile options if CONFIG_SECCOMP undefined

Quoted 42 lines · Daniel P. Berrangé
Quoted 41 lines · Eric Blake

On 05/06/2018 10:32 PM, Yi Min Zhao wrote:

In the subject line: s/avoid to compile/avoid compiling/

Quoted 1 line

If CONFIG_SECCOMP is undefined, the option 'elevatorprivileges' remains

s/elevator/elevate/

Quoted 1 line

complied. This would make libvirt set the corresponding capability and

s/complied/compiled/

Quoted 21 lines

then trigger the guest startup fails. So let's wrap the options with CONFIG_SECCOMP.

---
   vl.c | 2 ++
   1 file changed, 2 insertions(+)
vl.c +1 -0
index fce1fd12d8..cb07b19c02 100644
@@ -268,6 +268,7 @@ static QemuOptsList qemu_sandbox_opts = {
               .name = "enable",
               .type = QEMU_OPT_BOOL,
           },
+#ifdef CONFIG_SECCOMP
           {
               .name = "obsolete",
               .type = QEMU_OPT_STRING,

vl.c static QemuOptsList qemu_sandbox_opts = { · line 288

Quoted 4 lines
vl.c +1 -0
@@ -284,6 +285,7 @@ static QemuOptsList qemu_sandbox_opts = {
               .name = "resourcecontrol",
               .type = QEMU_OPT_STRING,
           },
+#endif

The commit message mentions only 'elevateprivileges' (once the typo is fixed), but you are also crippling 'obsolete', 'spawn', and 'resourcecontrol'. Perhaps the commit message should call that out better? Or, since libvirt is looking at just 'elevateprivileges', per this line in libvirt's qemu_capabilities.c:

Quoted 6 lines
Quoted 4 lines

src/qemu/qemu_capabilities.c: { "sandbox", "elevateprivileges",
QEMU_CAPS_SECCOMP_BLACKLIST },

is it sufficient to just mask out that one option?

If seccomp is disabled, we should really disable the entire -sandbox argument, not merly the options to it.

I think it would bring a lot of changes if disable the entire -sandbox argument.
Looking from current code, sandbox is a default qemu option group, and sandbox.enable is false by default unless you obviously define it with true. So, this patch is an easier way to fixup.

Quoted 3 lines

Regards,
Daniel

#8 lore raw

Re: [Qemu-devel] [PATCH 1/1] sandbox: avoid to compile options if CONFIG_SECCOMP undefined

Quoted 5 lines · Yi Min Zhao
Quoted 2 lines

If seccomp is disabled, we should really disable the entire -sandbox argument, not merly the options to it.

I think it would bring a lot of changes if disable the entire -sandbox argument.
Looking from current code, sandbox is a default qemu option group, and sandbox.enable is false by default unless you obviously define it with true. So, this patch is an easier way to fixup.

If the only thing you can do with -sandbox is turn it off (which is its default state), it's better to not advertise it at all in the first place. I agree with Daniel that it's better to cripple -sandbox from even being usable as a command-line argument if it isn't going to work, as that's easier to introspect.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#9 lore raw

Re: [Qemu-devel] [PATCH 1/1] sandbox: avoid to compile options if CONFIG_SECCOMP undefined

In reply to Eric Blake
Quoted 44 lines · Eric Blake

On 05/06/2018 10:32 PM, Yi Min Zhao wrote:

In the subject line: s/avoid to compile/avoid compiling/

Quoted 1 line

If CONFIG_SECCOMP is undefined, the option 'elevatorprivileges' remains

s/elevator/elevate/

Quoted 1 line

complied. This would make libvirt set the corresponding capability and

s/complied/compiled/

Quoted 21 lines

then trigger the guest startup fails. So let's wrap the options with CONFIG_SECCOMP.

---
  vl.c | 2 ++
  1 file changed, 2 insertions(+)
vl.c +1 -0
index fce1fd12d8..cb07b19c02 100644
@@ -268,6 +268,7 @@ static QemuOptsList qemu_sandbox_opts = {
              .name = "enable",
              .type = QEMU_OPT_BOOL,
          },
+#ifdef CONFIG_SECCOMP
          {
              .name = "obsolete",
              .type = QEMU_OPT_STRING,

vl.c static QemuOptsList qemu_sandbox_opts = { · line 288

Quoted 4 lines
vl.c +1 -0
@@ -284,6 +285,7 @@ static QemuOptsList qemu_sandbox_opts = {
              .name = "resourcecontrol",
              .type = QEMU_OPT_STRING,
          },
+#endif

The commit message mentions only 'elevateprivileges' (once the typo is fixed), but you are also crippling 'obsolete', 'spawn', and 'resourcecontrol'. Perhaps the commit message should call that out better? Or, since libvirt is looking at just 'elevateprivileges', per this line in libvirt's qemu_capabilities.c:

Quoted 4 lines

src/qemu/qemu_capabilities.c: { "sandbox", "elevateprivileges",
QEMU_CAPS_SECCOMP_BLACKLIST },

is it sufficient to just mask out that one option?

That would be inconsistent. I picked one option randomly, because they were added at the same time, but compiling out just one out of four is just odd. And with leaving them in even though the functionality is compiled out, libvirt has no way to tell upfront whether it's usable.

By that logic, removing the -sandbox option without CONFIG_SECCOMP makes sense, but libvirt already assumes this option is present on all supported QEMUs (>= 1.5.0), so please cc: me on that change if you decide to remove it as well.

Jano

#10 lore raw
In reply to Yi Min Zhao
Quoted 7 lines · Yi Min Zhao

1. Problem Description
======================
If QEMU is built without seccomp support, 'elevatorprivileges' remains compiled. This option of sandbox is treated as an indication for seccomp blacklist support in libvirt. This behavior is introduced by the libvirt commits 31ca6a5 and 3527f9d. It would make libvirt build wrong QEMU cmdline, and then the guest startup would fail.

Adding libvirt list.

This would still fail with older QEMUs, so the question is if we should also OR instead change something in libvirt.

Quoted 16 lines

2. Libvirt Log
==============
qemu-system-s390x: -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
resourcecontrol=deny: seccomp support is disabled

3. Fixup
========
Wrap the options except 'enable' for qemu_sandbox_opts by CONFIG_SECCOMP.

Yi Min Zhao (1):
sandbox: avoid to compile options if CONFIG_SECCOMP undefined

 vl.c | 2 ++
 1 file changed, 2 insertions(+)
#11 lore raw
Quoted 9 lines · Christian Borntraeger
Quoted 7 lines · Yi Min Zhao

1. Problem Description
======================
If QEMU is built without seccomp support, 'elevatorprivileges' remains compiled. This option of sandbox is treated as an indication for seccomp blacklist support in libvirt. This behavior is introduced by the libvirt commits 31ca6a5 and 3527f9d. It would make libvirt build wrong QEMU cmdline, and then the guest startup would fail.

Quoted 4 lines

Adding libvirt list.

This would still fail with older QEMUs, so the question is if we should also OR instead change something in libvirt.

Perhaps I'm missing something here, but libvirt can differentiate between different versions of QEMU, therefore not calling it with wrong or outdated arguments.

Quoted 18 lines
Quoted 17 lines

2. Libvirt Log
==============
qemu-system-s390x: -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
resourcecontrol=deny: seccomp support is disabled

3. Fixup
========
Wrap the options except 'enable' for qemu_sandbox_opts by CONFIG_SECCOMP.

Yi Min Zhao (1):
sandbox: avoid to compile options if CONFIG_SECCOMP undefined

 vl.c | 2 ++
 1 file changed, 2 insertions(+)
Signature · 1 line
Eduardo Otubo
#12 lore raw
Quoted 10 lines · Eduardo Otubo
Quoted 9 lines · Christian Borntraeger
Quoted 7 lines · Yi Min Zhao

1. Problem Description
======================
If QEMU is built without seccomp support, 'elevatorprivileges' remains compiled. This option of sandbox is treated as an indication for seccomp blacklist support in libvirt. This behavior is introduced by the libvirt commits 31ca6a5 and 3527f9d. It would make libvirt build wrong QEMU cmdline, and then the guest startup would fail.

Quoted 9 lines
Quoted 4 lines

Adding libvirt list.

This would still fail with older QEMUs, so the question is if we should also OR instead change something in libvirt.

Perhaps I'm missing something here, but libvirt can differentiate between different versions of QEMU, therefore not calling it with wrong or outdated arguments.

The code introduced in libvirt commit 31ca6a5 specifically looks for 'elevateprivileges' in 'parameters' of the 'sandbox' option through query-command-line-options.

Outdated QEMUs should not have this option there.

However, libvirtd does add the option by default not knowing whether it can fail for other reasons, e.g. SECCOMP not being enabled in the running kernel. I wonder if that is worth addressing.

Jano

Quoted 26 lines
Quoted 18 lines
Quoted 17 lines

2. Libvirt Log
==============
qemu-system-s390x: -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
resourcecontrol=deny: seccomp support is disabled

3. Fixup
========
Wrap the options except 'enable' for qemu_sandbox_opts by CONFIG_SECCOMP.

Yi Min Zhao (1):
sandbox: avoid to compile options if CONFIG_SECCOMP undefined

 vl.c | 2 ++
 1 file changed, 2 insertions(+)
Signature · 6 lines
Eduardo Otubo

--
libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list
#13 lore raw
Quoted 25 lines · Ján Tomko
Quoted 10 lines · Eduardo Otubo
Quoted 9 lines · Christian Borntraeger
Quoted 7 lines · Yi Min Zhao

1. Problem Description
======================
If QEMU is built without seccomp support, 'elevatorprivileges' remains compiled. This option of sandbox is treated as an indication for seccomp blacklist support in libvirt. This behavior is introduced by the libvirt commits 31ca6a5 and 3527f9d. It would make libvirt build wrong QEMU cmdline, and then the guest startup would fail.

Quoted 9 lines
Quoted 4 lines

Adding libvirt list.

This would still fail with older QEMUs, so the question is if we should also OR instead change something in libvirt.

Perhaps I'm missing something here, but libvirt can differentiate between different versions of QEMU, therefore not calling it with wrong or outdated arguments.

The code introduced in libvirt commit 31ca6a5 specifically looks for 'elevateprivileges' in 'parameters' of the 'sandbox' option through query-command-line-options.

Quoted 5 lines

Outdated QEMUs should not have this option there.

However, libvirtd does add the option by default not knowing whether it can fail for other reasons, e.g. SECCOMP not being enabled in the running kernel. I wonder if that is worth addressing.

So you prefer the qemu patch (with cc stable) as the best solution?