Skip to contentSkip to conversation

monitor: Add whitelist support for QMP commands

PATCH In review Julia Suvorova 6 participants 14 messages Jan 31, 2019 – Mar 11, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 monitor: Add whitelist support for QMP commands

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

---
 chardev/char.c            |  2 +-
 gdbstub.c                 |  2 +-
 include/monitor/monitor.h |  2 +-
 monitor.c                 | 82 +++++++++++++++++++++++++++++++++++++--
 qemu-options.hx           |  8 +++-
 stubs/monitor.c           |  2 +-
 vl.c                      |  5 ++-
 7 files changed, 92 insertions(+), 11 deletions(-)
chardev/char.c +1 -1
index ccba36bafb..9af8690806 100644
@@ -726,7 +726,7 @@ Chardev *qemu_chr_new_noreplay(const char *label, const char *filename,
 
     if (qemu_opt_get_bool(opts, "mux", 0)) {
         assert(permit_mux_mon);
-        monitor_init(chr, MONITOR_USE_READLINE);
+        monitor_init(chr, MONITOR_USE_READLINE, NULL);
     }
 
 out:
gdbstub.c +1 -1
index 3129b5c284..a91a47e79b 100644
@@ -2542,7 +2542,7 @@ int gdbserver_start(const char *device)
         /* Initialize a monitor terminal for gdb */
         mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB,
                                    NULL, &error_abort);
-        monitor_init(mon_chr, 0);
+        monitor_init(mon_chr, 0, NULL);
     } else {
         qemu_chr_fe_deinit(&s->chr, true);
         mon_chr = s->mon_chr;
include/monitor/monitor.h +1 -1
index c1b40a9cac..a0d7ad2ba2 100644
@@ -19,7 +19,7 @@ extern __thread Monitor *cur_mon;
 bool monitor_cur_is_qmp(void);
 
 void monitor_init_globals(void);
-void monitor_init(Chardev *chr, int flags);
+void monitor_init(Chardev *chr, int flags, const char *whitelist_file);
 void monitor_cleanup(void);
 
 int monitor_suspend(Monitor *mon);
monitor.c +78 -4

139 lines not on this page · raw message

qemu-options.hx +6 -2
index 521511ec13..e5d1b7dfb5 100644
@@ -3195,12 +3195,16 @@ Like -qmp but uses pretty JSON formatting.
 ETEXI
 
 DEF("mon", HAS_ARG, QEMU_OPTION_mon, \
-    "-mon [chardev=]name[,mode=readline|control][,pretty[=on|off]]\n", QEMU_ARCH_ALL)
+    "-mon [chardev=]name[,mode=readline|control][,pretty[=on|off]]" \
+    "[,whitelist=file]\n", QEMU_ARCH_ALL)
 STEXI
-@item -mon [chardev=]name[,mode=readline|control][,pretty[=on|off]]
+@item -mon [chardev=]name[,mode=readline|control][,pretty[=on|off]][,whitelist=@var{file}]
 @findex -mon
 Setup monitor on chardev @var{name}. @code{pretty} turns on JSON pretty printing
 easing human reading and debugging.
+The @code{whitelist} option disables all commands except those specified in
+@var{file}. The file must contain one command name per line. This option is only
+avaliable in 'control' mode.
 ETEXI
 
 DEF("debugcon", HAS_ARG, QEMU_OPTION_debugcon, \
stubs/monitor.c +1 -1
index 32bd7012c3..36725b8090 100644
@@ -12,7 +12,7 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
     return -1;
 }
 
-void monitor_init(Chardev *chr, int flags)
+void monitor_init(Chardev *chr, int flags, const char *whitelist_file)
 {
 }
 
vl.c +4 -1
index bc9fbec654..81278a0155 100644
@@ -2337,6 +2337,7 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
     Chardev *chr;
     const char *chardev;
     const char *mode;
+    const char *whitelist_file;
     int flags;
 
     mode = qemu_opt_get(opts, "mode");
@@ -2366,7 +2367,9 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
         return -1;
     }
 
-    monitor_init(chr, flags);
+    whitelist_file = qemu_opt_get(opts, "whitelist");
+
+    monitor_init(chr, flags, whitelist_file);
     return 0;
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Subject: [Qemu-devel] [PATCH] monitor: Add whitelist support for QMP commands
Type: series
Message-id: [email protected]

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'
5b7f9be0bb monitor: Add whitelist support for QMP commands

=== OUTPUT BEGIN ===
ERROR: Author email address is mangled by the mailing list #2:
Author: Julia Suvorova via Qemu-devel <[email protected]>

total: 1 errors, 0 warnings, 206 lines checked

Commit 5b7f9be0bbd6 (monitor: Add whitelist support for QMP commands) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
In reply to Julia Suvorova
Quoted 13 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

---

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4606

Quoted 5 lines
monitor.c +4 -1
-void monitor_init(Chardev *chr, int flags)
+static void process_whitelist_file(Monitor *mon, const char *whitelist_file)
+{
+    char cmd_name[256];
+    FILE *fd = fopen(whitelist_file, "r");

If you use qemu_open() here (followed by fdopen if you still prefer fscanf over read), then you can support "/dev/fdset/NNN" to auto-magically support someone passing in the whitelist via an inherited file descriptor, rather than having to be somewhere on disk that qemu can directly open().

Quoted 5 lines
monitor.c +5 -0
+
+    if (fd == NULL) {
+        error_report("Could not open whitelist file: %s", strerror(errno));
+        exit(1);
+    }

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4621

Quoted 10 lines
monitor.c +10 -0
+
+    mon->whitelist = g_hash_table_new_full(g_str_hash,
+                                           g_str_equal,
+                                           g_free,
+                                           NULL);
+
+    g_hash_table_add(mon->whitelist, g_strdup("qmp_capabilities"));
+    g_hash_table_add(mon->whitelist, g_strdup("query-commands"));
+
+    while (fscanf(fd, "%255s", cmd_name) == 1) {

%255s fits your cmd_name array declaration and stops consuming at either 255 bytes or at the first whitespace encountered, but where do you check for overflow from a file that passes more than 255 non-whitespace bytes without a newline? Also, this is a bit sloppy in that it skips all leading whitespace, rather than ensuring that the user actually passed newline-separated command names. Does glib provide any interfaces for more easily reading in an array of lines from a file?

Quoted 7 lines

+++ b/qemu-options.hx

qemu-options.hx +1 -1
@@ -3195,12 +3195,16 @@ Like -qmp but uses pretty JSON formatting.
 ETEXI
 
 DEF("mon", HAS_ARG, QEMU_OPTION_mon, \
-    "-mon [chardev=]name[,mode=readline|control][,pretty[=on|off]]\n", QEMU_ARCH_ALL)
+    "-mon [chardev=]name[,mode=readline|control][,pretty[=on|off]]" \

qemu-options.hx Like -qmp but uses pretty JSON formatting. · line 3207

Quoted 10 lines
qemu-options.hx +5 -1
+    "[,whitelist=file]\n", QEMU_ARCH_ALL)
 STEXI
-@item -mon [chardev=]name[,mode=readline|control][,pretty[=on|off]]
+@item -mon [chardev=]name[,mode=readline|control][,pretty[=on|off]][,whitelist=@var{file}]
 @findex -mon
 Setup monitor on chardev @var{name}. @code{pretty} turns on JSON pretty printing
 easing human reading and debugging.
+The @code{whitelist} option disables all commands except those specified in
+@var{file}. The file must contain one command name per line. This option is only
+avaliable in 'control' mode.

s/avaliable/available/

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw
Quoted 14 lines · Eric Blake
Quoted 13 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

---

Quoted 11 lines

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4606

Quoted 5 lines
monitor.c +4 -1
-void monitor_init(Chardev *chr, int flags)
+static void process_whitelist_file(Monitor *mon, const char *whitelist_file)
+{
+    char cmd_name[256];
+    FILE *fd = fopen(whitelist_file, "r");

If you use qemu_open() here (followed by fdopen if you still prefer fscanf over read), then you can support "/dev/fdset/NNN" to auto-magically support someone passing in the whitelist via an inherited file descriptor, rather than having to be somewhere on disk that qemu can directly open().

Cool, thanks!

Quoted 16 lines
Quoted 5 lines
monitor.c +5 -0
+
+    if (fd == NULL) {
+        error_report("Could not open whitelist file: %s", strerror(errno));
+        exit(1);
+    }

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4621

Quoted 10 lines
monitor.c +10 -0
+
+    mon->whitelist = g_hash_table_new_full(g_str_hash,
+                                           g_str_equal,
+                                           g_free,
+                                           NULL);
+
+    g_hash_table_add(mon->whitelist, g_strdup("qmp_capabilities"));
+    g_hash_table_add(mon->whitelist, g_strdup("query-commands"));
+
+    while (fscanf(fd, "%255s", cmd_name) == 1) {
Quoted 7 lines

%255s fits your cmd_name array declaration and stops consuming at either 255 bytes or at the first whitespace encountered, but where do you check for overflow from a file that passes more than 255 non-whitespace bytes without a newline? Also, this is a bit sloppy in that it skips all leading whitespace, rather than ensuring that the user actually passed newline-separated command names. Does glib provide any interfaces for more easily reading in an array of lines from a file?

With glib it would be something like that:

g_mapped_file_new_from_fd() : fd -> GMappedFile g_mapped_file_get_contents() : GMappedFile -> char *
g_strsplit_set() : char * -> char **

All this would need to be released afterwards.
Do you think it would be better?

Best regards, Julia Suvorova.

#4 lore raw
In reply to Eric Blake
Quoted 42 lines · Eric Blake
Quoted 13 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

---

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4606

Quoted 5 lines
monitor.c +4 -1
-void monitor_init(Chardev *chr, int flags)
+static void process_whitelist_file(Monitor *mon, const char *whitelist_file)
+{
+    char cmd_name[256];
+    FILE *fd = fopen(whitelist_file, "r");

If you use qemu_open() here (followed by fdopen if you still prefer fscanf over read), then you can support "/dev/fdset/NNN" to auto-magically support someone passing in the whitelist via an inherited file descriptor, rather than having to be somewhere on disk that qemu can directly open().

Quoted 5 lines
monitor.c +5 -0
+
+    if (fd == NULL) {
+        error_report("Could not open whitelist file: %s", strerror(errno));
+        exit(1);
+    }

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4621

Quoted 10 lines
monitor.c +10 -0
+
+    mon->whitelist = g_hash_table_new_full(g_str_hash,
+                                           g_str_equal,
+                                           g_free,
+                                           NULL);
+
+    g_hash_table_add(mon->whitelist, g_strdup("qmp_capabilities"));
+    g_hash_table_add(mon->whitelist, g_strdup("query-commands"));
+
+    while (fscanf(fd, "%255s", cmd_name) == 1) {
Quoted 7 lines

%255s fits your cmd_name array declaration and stops consuming at either 255 bytes or at the first whitespace encountered, but where do you check for overflow from a file that passes more than 255 non-whitespace bytes without a newline? Also, this is a bit sloppy in that it skips all leading whitespace, rather than ensuring that the user actually passed newline-separated command names. Does glib provide any interfaces for more easily reading in an array of lines from a file?

With glib, normally you'd use:

  char *content;
  gsize len;
  GError *err = NULL;
  char **lines;

g_file_get_contents(filename, &contnet, &len, &err)

  lines = g_str_split(content, "\n", 0);

  g_free(content);

...do something with lines

  g_strfreev(lines);

The GIO library provides higher level functions for I/O but we don't use that in QEMU

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 :|
#5 lore raw
Quoted 51 lines · Daniel P. Berrangé
Quoted 42 lines · Eric Blake
Quoted 13 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

---

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4606

Quoted 5 lines
monitor.c +4 -1
-void monitor_init(Chardev *chr, int flags)
+static void process_whitelist_file(Monitor *mon, const char *whitelist_file)
+{
+    char cmd_name[256];
+    FILE *fd = fopen(whitelist_file, "r");

If you use qemu_open() here (followed by fdopen if you still prefer fscanf over read), then you can support "/dev/fdset/NNN" to auto-magically support someone passing in the whitelist via an inherited file descriptor, rather than having to be somewhere on disk that qemu can directly open().

Quoted 5 lines
monitor.c +5 -0
+
+    if (fd == NULL) {
+        error_report("Could not open whitelist file: %s", strerror(errno));
+        exit(1);
+    }

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4621

Quoted 10 lines
monitor.c +10 -0
+
+    mon->whitelist = g_hash_table_new_full(g_str_hash,
+                                           g_str_equal,
+                                           g_free,
+                                           NULL);
+
+    g_hash_table_add(mon->whitelist, g_strdup("qmp_capabilities"));
+    g_hash_table_add(mon->whitelist, g_strdup("query-commands"));
+
+    while (fscanf(fd, "%255s", cmd_name) == 1) {
Quoted 7 lines

%255s fits your cmd_name array declaration and stops consuming at either 255 bytes or at the first whitespace encountered, but where do you check for overflow from a file that passes more than 255 non-whitespace bytes without a newline? Also, this is a bit sloppy in that it skips all leading whitespace, rather than ensuring that the user actually passed newline-separated command names. Does glib provide any interfaces for more easily reading in an array of lines from a file?

Quoted 8 lines

With glib, normally you'd use:

   char *content;
   gsize len;
   GError *err = NULL;
   char **lines;

g_file_get_contents(filename, &contnet, &len, &err)

With g_file_get_contents() I won't be able to do qemu_open() and support "/dev/fdset/NNN". The workaround seems to me unnecessarily complex.

Quoted 11 lines
   lines = g_str_split(content, "\n", 0);

   g_free(content);

...do something with lines

   g_strfreev(lines);

The GIO library provides higher level functions for I/O but we don't use that in QEMU

#6 lore raw
Quoted 60 lines · Julia Suvorova
Quoted 57 lines · Daniel P. Berrangé
Quoted 41 lines · Eric Blake
Quoted 12 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

---

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4606

Quoted 5 lines
monitor.c +4 -1
-void monitor_init(Chardev *chr, int flags)
+static void process_whitelist_file(Monitor *mon, const char *whitelist_file)
+{
+    char cmd_name[256];
+    FILE *fd = fopen(whitelist_file, "r");

If you use qemu_open() here (followed by fdopen if you still prefer fscanf over read), then you can support "/dev/fdset/NNN" to auto-magically support someone passing in the whitelist via an inherited file descriptor, rather than having to be somewhere on disk that qemu can directly open().

Quoted 5 lines
monitor.c +5 -0
+
+    if (fd == NULL) {
+        error_report("Could not open whitelist file: %s", strerror(errno));
+        exit(1);
+    }

monitor.c static void monitor_qmp_setup_handlers_bh(void *opaque) · line 4621

Quoted 10 lines
monitor.c +10 -0
+
+    mon->whitelist = g_hash_table_new_full(g_str_hash,
+                                           g_str_equal,
+                                           g_free,
+                                           NULL);
+
+    g_hash_table_add(mon->whitelist, g_strdup("qmp_capabilities"));
+    g_hash_table_add(mon->whitelist, g_strdup("query-commands"));
+
+    while (fscanf(fd, "%255s", cmd_name) == 1) {
Quoted 7 lines

%255s fits your cmd_name array declaration and stops consuming at either 255 bytes or at the first whitespace encountered, but where do you check for overflow from a file that passes more than 255 non-whitespace bytes without a newline? Also, this is a bit sloppy in that it skips all leading whitespace, rather than ensuring that the user actually passed newline-separated command names. Does glib provide any interfaces for more easily reading in an array of lines from a file?

With glib, normally you'd use:

   char *content;
   gsize len;
   GError *err = NULL;
   char **lines;
Quoted 4 lines
Quoted 1 line

g_file_get_contents(filename, &contnet, &len, &err)

With g_file_get_contents() I won't be able to do qemu_open() and support "/dev/fdset/NNN". The workaround seems to me unnecessarily complex.

Yes, its a question of whether the /dev/fdset/NNN feature is needed or not. At the very least though you should be using getline() rather than fscanf so that we don't have a large hardcoded buffer on the stack.

Quoted 5 lines
Quoted 5 lines
   lines = g_str_split(content, "\n", 0);

   g_free(content);
Quoted 7 lines
Quoted 7 lines

...do something with lines

   g_strfreev(lines);

The GIO library provides higher level functions for I/O but we don't use that in QEMU

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
In reply to Julia Suvorova
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] monitor: Add whitelist support for QMP commands

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
5b7f9be monitor: Add whitelist support for QMP commands

=== OUTPUT BEGIN ===
ERROR: Author email address is mangled by the mailing list #2:
Author: Julia Suvorova via Qemu-devel <[email protected]>

total: 1 errors, 0 warnings, 206 lines checked

Commit 5b7f9be0bbd6 (monitor: Add whitelist support for QMP commands) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#8 lore raw
In reply to Julia Suvorova
Quoted 11 lines · Julia Suvorova

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

---

Please include a test case. tests/qmp-cmd-test.c looks like a starting point.

Interesting cases:
1. QMP negotiation still works.
2. A whitelisted command succeeds.
3. A forbidden command fails with the expected error.

monitor.c static void qmp_request_free(QMPRequest *req) · line 369

Quoted 8 lines
monitor.c +8 -0
+static void monitor_qmp_cleanup_commands(Monitor *mon)
+{
+    QmpCommand *cmd, *next_cmd;
+
+    if (!monitor_is_qmp(mon) ||
+        mon->qmp.commands == &qmp_cap_negotiation_commands) {
+        return;
+    }

Checking side-effects can be avoided with a bool flag:

  if (!mon->qmp_commands_needs_free) {
      return;
  }

Any place that allocates qmp.commands must set this flag and then we don't need to worry whether we're checking the right side-effects in the cleanup function.

I think this makes the code easier to read but it's just a suggestion.

Quoted 5 lines
qemu-options.hx +0 -0
index 521511ec13..e5d1b7dfb5 100644

qemu-options.hx Like -qmp but uses pretty JSON formatting. · line 3201

Quoted 9 lines
qemu-options.hx +3 -2
@@ -3195,12 +3195,16 @@ Like -qmp but uses pretty JSON formatting.
 ETEXI
 
 DEF("mon", HAS_ARG, QEMU_OPTION_mon, \
-    "-mon [chardev=]name[,mode=readline|control][,pretty[=on|off]]\n", QEMU_ARCH_ALL)
+    "-mon [chardev=]name[,mode=readline|control][,pretty[=on|off]]" \
+    "[,whitelist=file]\n", QEMU_ARCH_ALL)
 STEXI
-@item -mon [chardev=]name[,mode=readline|control][,pretty[=on|off]]
+@item -mon [chardev=]name[,mode=readline|control][,pretty[=on|off]][,whitelist=@var{file}]

Your change reminded me that "[chardev=]name" should be "[chardev=]@var{name}" since 'name' isn't a string literal but a variable.

This is a pre-existing issue but please add a patch to this series to fix it.

qemu-options.hx Like -qmp but uses pretty JSON formatting. · line 3207

Quoted 6 lines
qemu-options.hx +3 -0
 @findex -mon
 Setup monitor on chardev @var{name}. @code{pretty} turns on JSON pretty printing
 easing human reading and debugging.
+The @code{whitelist} option disables all commands except those specified in
+@var{file}. The file must contain one command name per line. This option is only
+avaliable in 'control' mode.

s/avaliable/available/

#9 lore raw
In reply to Julia Suvorova
Quoted 2 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is

For a value of "secure". I'm not saying this can't be useful, just tempering expecations. I guess you intend to use this to restrict the monitor to sufficiently harmless commands, such as commands that merely return information without changing anything. However, even such commands can be abused for denial of service. Whether that's an issue depends on your use case.

Quoted 8 lines

convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

Please describe your intended use case in more detail, and provide at least a rough security analysis that includes the denial of service aspect.

#10 lore raw
Quoted 19 lines · Markus Armbruster
Quoted 2 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is

For a value of "secure". I'm not saying this can't be useful, just tempering expecations. I guess you intend to use this to restrict the monitor to sufficiently harmless commands, such as commands that merely return information without changing anything. However, even such commands can be abused for denial of service. Whether that's an issue depends on your use case.

Quoted 7 lines

convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

Quoted 5 lines
Quoted 1 line

Please describe your intended use case in more detail, and provide at least a rough security analysis that includes the denial of service aspect.

It is planned to use the web interface for micro:bit board, e.g. send a button press as a QMP command and send a LED display changing as a QMP event, and send them via WebSocket protocol from QEMU to a web page. The monitor will also send commands from some other sensors, for example, an accelerometer/magnetometer. Therefore, it is convenient to limit the monitor so that it can send only these commands of buttons/sensors.

Best regards, Julia Suvorova.

#11 lore raw
Quoted 26 lines · Julia Suvorova via Qemu-devel
Quoted 19 lines · Markus Armbruster
Quoted 2 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is

For a value of "secure". I'm not saying this can't be useful, just tempering expecations. I guess you intend to use this to restrict the monitor to sufficiently harmless commands, such as commands that merely return information without changing anything. However, even such commands can be abused for denial of service. Whether that's an issue depends on your use case.

Quoted 7 lines

convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

Quoted 5 lines
Quoted 1 line

Please describe your intended use case in more detail, and provide at least a rough security analysis that includes the denial of service aspect.

Quoted 7 lines

It is planned to use the web interface for micro:bit board, e.g. send a button press as a QMP command and send a LED display changing as a QMP event, and send them via WebSocket protocol from QEMU to a web page. The monitor will also send commands from some other sensors, for example, an accelerometer/magnetometer. Therefore, it is convenient to limit the monitor so that it can send only these commands of buttons/sensors.

Covers "describe your intended use case" nicely, thanks. Still missing:
"a rough security analysis that includes the denial of service aspect". Here are two questions to help you get started. Is "the web interface" trusted? If not, what if it floods QEMU with button presses?

#12 lore raw
Quoted 36 lines · Markus Armbruster
Quoted 26 lines · Julia Suvorova via Qemu-devel
Quoted 19 lines · Markus Armbruster
Quoted 2 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is

For a value of "secure". I'm not saying this can't be useful, just tempering expecations. I guess you intend to use this to restrict the monitor to sufficiently harmless commands, such as commands that merely return information without changing anything. However, even such commands can be abused for denial of service. Whether that's an issue depends on your use case.

Quoted 7 lines

convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

Quoted 5 lines
Quoted 1 line

Please describe your intended use case in more detail, and provide at least a rough security analysis that includes the denial of service aspect.

Quoted 7 lines

It is planned to use the web interface for micro:bit board, e.g. send a button press as a QMP command and send a LED display changing as a QMP event, and send them via WebSocket protocol from QEMU to a web page. The monitor will also send commands from some other sensors, for example, an accelerometer/magnetometer. Therefore, it is convenient to limit the monitor so that it can send only these commands of buttons/sensors.

Quoted 4 lines

Covers "describe your intended use case" nicely, thanks. Still missing:
"a rough security analysis that includes the denial of service aspect". Here are two questions to help you get started. Is "the web interface" trusted? If not, what if it floods QEMU with button presses?

In the case of a trusted connection, we don't even need a whitelist. The oob execution must be disabled in order to prohibit the direct execution of speculative series of commands. The regular command suspends the monitor and causes it to stop reading the commands until the execution is completed, which prevents the client from capturing too many resources. And since the suspension of the monitor doesn't stop the sending of events, the display will work fine.

Best regards, Julia Suvorova.

#13 lore raw

I apologize for the long delay.

Quoted 42 lines · Julia Suvorova via Qemu-devel
Quoted 36 lines · Markus Armbruster
Quoted 26 lines · Julia Suvorova via Qemu-devel
Quoted 19 lines · Markus Armbruster
Quoted 2 lines · Julia Suvorova via Qemu-devel

The whitelist option allows to run a reduced monitor with a subset of QMP commands. This allows the monitor to run in secure mode, which is

For a value of "secure". I'm not saying this can't be useful, just tempering expecations. I guess you intend to use this to restrict the monitor to sufficiently harmless commands, such as commands that merely return information without changing anything. However, even such commands can be abused for denial of service. Whether that's an issue depends on your use case.

Quoted 7 lines

convenient for sending commands via the WebSocket monitor using the web UI. This is planned to be done on micro:bit board.

The list of allowed commands should be written to a file, one per line. The command line will look like this:
-mon chardev_name,mode=control,whitelist=path_to_file

Quoted 5 lines
Quoted 1 line

Please describe your intended use case in more detail, and provide at least a rough security analysis that includes the denial of service aspect.

Quoted 7 lines

It is planned to use the web interface for micro:bit board, e.g. send a button press as a QMP command and send a LED display changing as a QMP event, and send them via WebSocket protocol from QEMU to a web page. The monitor will also send commands from some other sensors, for example, an accelerometer/magnetometer. Therefore, it is convenient to limit the monitor so that it can send only these commands of buttons/sensors.

Quoted 4 lines

Covers "describe your intended use case" nicely, thanks. Still missing:
"a rough security analysis that includes the denial of service aspect". Here are two questions to help you get started. Is "the web interface" trusted? If not, what if it floods QEMU with button presses?

Quoted 6 lines

In the case of a trusted connection, we don't even need a whitelist. The oob execution must be disabled in order to prohibit the direct execution of speculative series of commands. The regular command suspends the monitor and causes it to stop reading the commands until the execution is completed, which prevents the client from capturing too many resources.

It could still peg one core, at least in theory.

Quoted 2 lines

And since the suspension of the monitor doesn't stop the
sending of events, the display will work fine.

This is not an objection; I asked for a rough security analysis not to challenge its premises, but to make sure you have one. Now put it on record by working it into your commit message.

I still have to review the actual patch. You may want to wait for that before you respin.