Skip to contentSkip to conversation

Allow -sandbox off with --disable-seccomp

PATCH In review David Gibson 6 participants 8 messages Feb 27, 2019 – Feb 28, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow -sandbox off with --disable-seccomp

At present, when seccomp support is compiled out with --disable-seccomp we fail with an error if the user puts -sandbox on the command line.

That kind of makes sense, but it's a bit strange that we reject a request to disable sandboxing with "-sandbox off" saying we don't support sandboxing.

This puts in a small sandbox to (correctly) silently ignore -sandbox off when we don't have sandboxing support compiled in. This makes life easier for testcases, since they can safely specify "-sandbox off" without having to care if the qemu they're using is compiled with sandbox support or not.

---
 vl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
vl.c +5 -3
index 502857a176..9d5f1b7ebb 100644
@@ -3857,9 +3857,11 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
 #else
-                error_report("-sandbox support is not enabled "
-                             "in this QEMU binary");
-                exit(1);
+                if (!g_str_equal(optarg, "off")) {
+                    error_report("-sandbox support is not enabled "
+                                 "in this QEMU binary");
+                    exit(1);
+                }
 #endif
                 break;
             case QEMU_OPTION_add_fd:
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 8 lines · David Gibson

At present, when seccomp support is compiled out with --disable-seccomp we fail with an error if the user puts -sandbox on the command line.

That kind of makes sense, but it's a bit strange that we reject a request to disable sandboxing with "-sandbox off" saying we don't support sandboxing.

Quoted 6 lines

This puts in a small sandbox to (correctly) silently ignore -sandbox off when we don't have sandboxing support compiled in. This makes life easier for testcases, since they can safely specify "-sandbox off" without having to care if the qemu they're using is compiled with sandbox support or not.

Quoted 27 lines
---
 vl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
vl.c +5 -4
index 502857a176..9d5f1b7ebb 100644
@@ -3857,9 +3857,11 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
 #else
-                error_report("-sandbox support is not enabled "
-                             "in this QEMU binary");
-                exit(1);
+                if (!g_str_equal(optarg, "off")) {
+                    error_report("-sandbox support is not enabled "
+                                 "in this QEMU binary");
+                    exit(1);
+                }
 #endif
                 break;
             case QEMU_OPTION_add_fd:
--

2.20.1

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Gibson
Quoted 12 lines · David Gibson

At present, when seccomp support is compiled out with --disable-seccomp we fail with an error if the user puts -sandbox on the command line.

That kind of makes sense, but it's a bit strange that we reject a request to disable sandboxing with "-sandbox off" saying we don't support sandboxing.

This puts in a small sandbox to (correctly) silently ignore -sandbox off when we don't have sandboxing support compiled in. This makes life easier for testcases, since they can safely specify "-sandbox off" without having to care if the qemu they're using is compiled with sandbox support or not.

Quoted 4 lines
---
 vl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
#3 lore raw
In reply to David Gibson
Quoted 23 lines · David Gibson

At present, when seccomp support is compiled out with --disable-seccomp we fail with an error if the user puts -sandbox on the command line.

That kind of makes sense, but it's a bit strange that we reject a request to disable sandboxing with "-sandbox off" saying we don't support sandboxing.

This puts in a small sandbox to (correctly) silently ignore -sandbox off when we don't have sandboxing support compiled in. This makes life easier for testcases, since they can safely specify "-sandbox off" without having to care if the qemu they're using is compiled with sandbox support or not.

---
 vl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
vl.c +0 -0
index 502857a176..9d5f1b7ebb 100644
@@ -3857,9 +3857,11 @@ int main(int argc, char **argv, char **envp)
                     exit(1);

vl.c int main(int argc, char **argv, char **envp) · line 3864

Quoted 10 lines
vl.c +5 -3
                 }
 #else
-                error_report("-sandbox support is not enabled "
-                             "in this QEMU binary");
-                exit(1);
+                if (!g_str_equal(optarg, "off")) {
+                    error_report("-sandbox support is not enabled "
+                                 "in this QEMU binary");
+                    exit(1);
+                }

'-sandbox off' is just syntax sugar for '-sandbox enable=off', with the default arg name handled by QemuOpts.

If we want to keep ability to run "-sandbox off" we should do it via the QEMU opts code we already have in the first part of the conditional, so that "-sandbox enable=off" also works as normal.

Essentially we need to push the #ifdef CONFIG_SECCOMP down into the parse_sandbox method, so that it parses the "enable" option normally but rejects any value except disabled..

The QemuOptsList should also be conditional to only register the "enable" arg and not the other bits.

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 :|
#4 lore raw
Quoted 13 lines · Daniel P. Berrangé
Quoted 12 lines · David Gibson

At present, when seccomp support is compiled out with --disable-seccomp we fail with an error if the user puts -sandbox on the command line.

That kind of makes sense, but it's a bit strange that we reject a request to disable sandboxing with "-sandbox off" saying we don't support sandboxing.

This puts in a small sandbox to (correctly) silently ignore -sandbox off when we don't have sandboxing support compiled in. This makes life easier for testcases, since they can safely specify "-sandbox off" without having to care if the qemu they're using is compiled with sandbox support or not.

Quoted 4 lines
Quoted 1 line

'-sandbox off' is just syntax sugar for '-sandbox enable=off', with the default arg name handled by QemuOpts.

Except that libvirt probes, via query-command-line-options, whether the '-sandbox' option supports the 'enable' key. You risk breaking introspection (where libvirt knows NOT to use enable=on|off) if -sandbox enable=off is advertised even when the feature is not compiled in.

Quoted 11 lines

If we want to keep ability to run "-sandbox off" we should do it via the QEMU opts code we already have in the first part of the conditional, so that "-sandbox enable=off" also works as normal.

Essentially we need to push the #ifdef CONFIG_SECCOMP down into the parse_sandbox method, so that it parses the "enable" option normally but rejects any value except disabled..

The QemuOptsList should also be conditional to only register the "enable" arg and not the other bits.

Whatever we do here had better be careful that the introspection used by libvirt doesn't break, when libvirt is trying to learn when seccomp was not compiled in.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#5 lore raw
Quoted 16 lines · Eric Blake
Quoted 14 lines · Daniel P. Berrangé
Quoted 13 lines · David Gibson

At present, when seccomp support is compiled out with --disable-seccomp we fail with an error if the user puts -sandbox on the command line.

That kind of makes sense, but it's a bit strange that we reject a request to disable sandboxing with "-sandbox off" saying we don't support sandboxing.

This puts in a small sandbox to (correctly) silently ignore -sandbox off when we don't have sandboxing support compiled in. This makes life easier for testcases, since they can safely specify "-sandbox off" without having to care if the qemu they're using is compiled with sandbox support or not.

Quoted 7 lines
Quoted 2 lines

'-sandbox off' is just syntax sugar for '-sandbox enable=off', with the default arg name handled by QemuOpts.

Except that libvirt probes, via query-command-line-options, whether the '-sandbox' option supports the 'enable' key. You risk breaking introspection (where libvirt knows NOT to use enable=on|off) if -sandbox enable=off is advertised even when the feature is not compiled in.

It is even more complex than that. Libvirt looks for "elevateprivileges" option to decide to enable the sandbox. It only looks for "enable" when libvirt is configured to disable the sandbox, at which point is sets "-sandbox off". So I don't think my suggestion should break it.

I do hate the idea of QEMU tailoring its CLI handling to suit the current specific impl of one client app though.

If anything I'd suggest we should completely disable any parsing of -sandbox when seccomp is disabled, rather than leaving getopt to parse -sandbox and then raise an error.

Quoted 10 lines
Quoted 10 lines

If we want to keep ability to run "-sandbox off" we should do it via the QEMU opts code we already have in the first part of the conditional, so that "-sandbox enable=off" also works as normal.

Essentially we need to push the #ifdef CONFIG_SECCOMP down into the parse_sandbox method, so that it parses the "enable" option normally but rejects any value except disabled..

Quoted 6 lines
Quoted 2 lines

The QemuOptsList should also be conditional to only register the "enable" arg and not the other bits.

Whatever we do here had better be careful that the introspection used by libvirt doesn't break, when libvirt is trying to learn when seccomp was not compiled in.

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 :|
#6 lore raw
Quoted 6 lines · Daniel P. Berrangé
Quoted 5 lines · Eric Blake
Quoted 4 lines · Daniel P. Berrangé
Quoted 3 lines · David Gibson

At present, when seccomp support is compiled out with --disable-seccomp we fail with an error if the user puts -sandbox on the command line.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

That kind of makes sense, but it's a bit strange that we reject a request to disable sandboxing with "-sandbox off" saying we don't support sandboxing.

This puts in a small sandbox to (correctly) silently ignore -sandbox off when we don't have sandboxing support compiled in. This makes life easier for testcases, since they can safely specify "-sandbox off" without having to care if the qemu they're using is compiled with sandbox support or not.

I can't see such test cases. Can you give specific examples?

Quoted 15 lines
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

'-sandbox off' is just syntax sugar for '-sandbox enable=off', with the default arg name handled by QemuOpts.

Except that libvirt probes, via query-command-line-options, whether the '-sandbox' option supports the 'enable' key. You risk breaking introspection (where libvirt knows NOT to use enable=on|off) if -sandbox enable=off is advertised even when the feature is not compiled in.

It is even more complex than that. Libvirt looks for "elevateprivileges" option to decide to enable the sandbox. It only looks for "enable" when libvirt is configured to disable the sandbox, at which point is sets "-sandbox off". So I don't think my suggestion should break it.

Quoted 6 lines

I do hate the idea of QEMU tailoring its CLI handling to suit the current specific impl of one client app though.

If anything I'd suggest we should completely disable any parsing of -sandbox when seccomp is disabled, rather than leaving getopt to parse -sandbox and then raise an error.

I'm confused. Are you proposing to silently ignore -sandbox OPTARG regardless of OPTARG when CONFIG_SECCOMP is off? If yes, I object. If a user asks for a sandbox, and we can't give him one, we should at least tell him as much.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

If we want to keep ability to run "-sandbox off" we should do it via the QEMU opts code we already have in the first part of the conditional, so that "-sandbox enable=off" also works as normal.

Essentially we need to push the #ifdef CONFIG_SECCOMP down into the parse_sandbox method, so that it parses the "enable" option normally but rejects any value except disabled..

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

The QemuOptsList should also be conditional to only register the "enable" arg and not the other bits.

Whatever we do here had better be careful that the introspection used by libvirt doesn't break, when libvirt is trying to learn when seccomp was not compiled in.

Currently, we have both

    #ifdef CONFIG_FOO
                case QEMU_OPTION_FOO:
                    ...
                    break;
    #endif

and

                case QEMU_OPTION_FOO:
    #ifdef CONFIG_FOO
                    ...
                    break;
    #else
                    error_report("FOO support is disabled");
                    exit(1);
    #endif

The patch adds a third variant. We need fewer variants, not more.

For what it's worth, conditional QMP commands do not exist when disabled, like the first variant above. In particular, introspection doesn't have them. Nicely obvious.

QAPIfying the command line (yes, yes, overdue) should make it more like QMP.

Wanting nicer errors than "unknown option / command" is legitimate.

Wanting to accept "switch FOO off" even though FOO is disabled is also legitimate.

Patches that provide such UI niceties while keeping introspection nicely obvious would be acceptable to me, provided they're not too complex. But they should be general, not a one-off.

#7 lore raw
Quoted 37 lines · Markus Armbruster
Quoted 6 lines · Daniel P. Berrangé
Quoted 5 lines · Eric Blake
Quoted 4 lines · Daniel P. Berrangé
Quoted 3 lines · David Gibson

At present, when seccomp support is compiled out with --disable-seccomp we fail with an error if the user puts -sandbox on the command line.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

That kind of makes sense, but it's a bit strange that we reject a request to disable sandboxing with "-sandbox off" saying we don't support sandboxing.

This puts in a small sandbox to (correctly) silently ignore -sandbox off when we don't have sandboxing support compiled in. This makes life easier for testcases, since they can safely specify "-sandbox off" without having to care if the qemu they're using is compiled with sandbox support or not.

I can't see such test cases. Can you give specific examples?

Quoted 18 lines
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

'-sandbox off' is just syntax sugar for '-sandbox enable=off', with the default arg name handled by QemuOpts.

Except that libvirt probes, via query-command-line-options, whether the '-sandbox' option supports the 'enable' key. You risk breaking introspection (where libvirt knows NOT to use enable=on|off) if -sandbox enable=off is advertised even when the feature is not compiled in.

It is even more complex than that. Libvirt looks for "elevateprivileges" option to decide to enable the sandbox. It only looks for "enable" when libvirt is configured to disable the sandbox, at which point is sets "-sandbox off". So I don't think my suggestion should break it.

I do hate the idea of QEMU tailoring its CLI handling to suit the current specific impl of one client app though.

Quoted 8 lines
Quoted 3 lines

If anything I'd suggest we should completely disable any parsing of -sandbox when seccomp is disabled, rather than leaving getopt to parse -sandbox and then raise an error.

I'm confused. Are you proposing to silently ignore -sandbox OPTARG regardless of OPTARG when CONFIG_SECCOMP is off? If yes, I object. If a user asks for a sandbox, and we can't give him one, we should at least tell him as much.

No, i mean remove "case QEMU_OPTION_sandbox:" from the code, which will cause us to report '-sandbox' as an unsupported argument.

Quoted 7 lines

Currently, we have both

    #ifdef CONFIG_FOO
                case QEMU_OPTION_FOO:
                    ...
                    break;
    #endif

This is what I was suggesting for -sandbox above.

Quoted 4 lines

and

Quoted 8 lines
                case QEMU_OPTION_FOO:
    #ifdef CONFIG_FOO
                    ...
                    break;
    #else
                    error_report("FOO support is disabled");
                    exit(1);
    #endif

This is what -sandbox does currently.

Quoted 10 lines

The patch adds a third variant. We need fewer variants, not more.

For what it's worth, conditional QMP commands do not exist when disabled, like the first variant above. In particular, introspection doesn't have them. Nicely obvious.

QAPIfying the command line (yes, yes, overdue) should make it more like QMP.

Quoted 8 lines

Wanting nicer errors than "unknown option / command" is legitimate.

Wanting to accept "switch FOO off" even though FOO is disabled is also legitimate.

Patches that provide such UI niceties while keeping introspection nicely obvious would be acceptable to me, provided they're not too complex. But they should be general, not a one-off.

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 :|