Skip to contentSkip to conversation

tests/qtest/fuzz: Add generic fuzzer for VNC

PATCH Superseded Navid Emamdoost 4 participants 13 messages Oct 9, 2025 – Jan 13

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/qtest/fuzz: Add generic fuzzer for VNC

Add a new generic fuzz target for the QEMU VNC server. This allows the generic fuzzer to directly exercise the VNC protocol implementation by connecting to a VNC unix socket.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
---
 tests/qtest/fuzz/generic_fuzz_configs.h | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/fuzz/generic_fuzz_configs.h +4 -0
index ef0ad95712..2e802ab226 100644
@@ -247,6 +247,10 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .args = "-machine q35 -nodefaults -vnc vnc=unix:/tmp/qemu-vnc.sock",
+        .objects = "*",
     }
 };
 
Signature · 1 line
2.51.0.740.g6adb054d12-goog
#1 lore raw
Quoted 32 lines · Navid Emamdoost

Add a new generic fuzz target for the QEMU VNC server. This allows the generic fuzzer to directly exercise the VNC protocol implementation by connecting to a VNC unix socket.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
---
 tests/qtest/fuzz/generic_fuzz_configs.h | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/fuzz/generic_fuzz_configs.h +0 -0
index ef0ad95712..2e802ab226 100644

tests/qtest/fuzz/generic_fuzz_configs.h const generic_fuzz_config predefined_configs[] = { · line 252

Quoted 6 lines
tests/qtest/fuzz/generic_fuzz_configs.h +3 -0
@@ -247,6 +247,10 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .args = "-machine q35 -nodefaults -vnc vnc=unix:/tmp/qemu-vnc.sock",

How about also adding ",websocket=unix:/tmp/qemu-vnc-ws.sock" ?

I'm guessing the fuzz tool is not intelligent enough to be able to negotiate TLS over the connections ?

Quoted 8 lines
tests/qtest/fuzz/generic_fuzz_configs.h +1 -0
+        .objects = "*",
     }
 };
 
Signature · 1 line
2.51.0.740.g6adb054d12-goog

With 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 :|
#2 lore raw
In reply to Navid Emamdoost
Quoted 3 lines · Navid Emamdoost

Add a new generic fuzz target for the QEMU VNC server. This allows the generic fuzzer to directly exercise the VNC protocol implementation by connecting to a VNC unix socket.

Without a client connected to the socket (or even a client trying to fuzz the VNC protocol), much of the code will be unreachable. Still, fuzzing this probably does not hurt.

Quoted 29 lines

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
---
 tests/qtest/fuzz/generic_fuzz_configs.h | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/fuzz/generic_fuzz_configs.h +0 -0
index ef0ad95712..2e802ab226 100644

tests/qtest/fuzz/generic_fuzz_configs.h const generic_fuzz_config predefined_configs[] = { · line 252

Quoted 6 lines
tests/qtest/fuzz/generic_fuzz_configs.h +3 -0
@@ -247,6 +247,10 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .args = "-machine q35 -nodefaults -vnc vnc=unix:/tmp/qemu-vnc.sock",

Does using a hardoded socket create problems when running multiple processes fuzzers in parallel? AFAIK oss-fuzz does this.

Quoted 7 lines
tests/qtest/fuzz/generic_fuzz_configs.h +1 -1
+        .objects = "*",
     }
 };
 
--

2.51.0.740.g6adb054d12-goog

#3 lore raw

v2 cover tests/qtest/fuzz: Add generic fuzzer for VNC

Hi Alexander and Daniel,

Thank you for the excellent feedback. I've updated the patch to incorporate your suggestions.

---

Changes in v2:
- Dynamically generate VNC socket paths to prevent collisions during parallel fuzzing runs. (Suggested by Alexander Bulekov)
- Add a WebSocket VNC listener to the fuzzer to increase coverage of that transport protocol. (Suggested by Daniel P. Berrangé)

Navid Emamdoost (1):
tests/qtest/fuzz: Add generic fuzzer for VNC

 tests/qtest/fuzz/fuzz.c                 | 65 +++++++++++++++++++++++++
 tests/qtest/fuzz/generic_fuzz_configs.h |  5 ++
 2 files changed, 70 insertions(+)
Signature · 1 line
2.51.0.760.g7b8bcc2412-goog
#4 lore raw

PATCH v2 1/1 tests/qtest/fuzz: Add generic fuzzer for VNC

Add a new generic fuzz target for the QEMU VNC server. This target exercises both the standard VNC protocol and the VNC-over-WebSocket transport layer, increasing coverage of a primary remote attack surface.

To support parallel fuzzing (e.g., with oss-fuzz), the VNC unix socket paths are generated dynamically. The fuzzer harness inspects the command line for placeholders and replaces them with unique paths created by mkstemp() before execution.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
---
 tests/qtest/fuzz/fuzz.c                 | 65 +++++++++++++++++++++++++
 tests/qtest/fuzz/generic_fuzz_configs.h |  5 ++
 2 files changed, 70 insertions(+)
tests/qtest/fuzz/fuzz.c +65 -0
index ca248a51a6..b77c3ceb2b 100644
@@ -126,6 +126,46 @@ static FuzzTarget *fuzz_get_target(char* name)
     return NULL;
 }
 
+/*
+ * Global variables to hold the unique socket paths for cleanup.
+ */
+static char g_vnc_socket_path[sizeof("/tmp/qemu-vnc.XXXXXX")];
+static char g_vnc_ws_socket_path[sizeof("/tmp/qemu-vnc-ws.XXXXXX")];
+
+/*
+ * atexit() handler to clean up both socket files.
+ */
+static void cleanup_vnc_sockets(void)
+{
+    if (g_vnc_socket_path[0] != '\0') {
+        unlink(g_vnc_socket_path);
+    }
+    if (g_vnc_ws_socket_path[0] != '\0') {
+        unlink(g_vnc_ws_socket_path);
+    }
+}
+
+/* Helper function to find and replace a placeholder in a GString */
+static bool replace_socket_placeholder(GString *cmd_line, const char *placeholder,
+                                       const char *path_template, char *global_path_out)
+{
+    char *placeholder_ptr = strstr(cmd_line->str, placeholder);
+    if (placeholder_ptr) {
+        int fd;
+        strcpy(global_path_out, path_template);
+        fd = mkstemp(global_path_out);
+        if (fd == -1) {
+            perror("mkstemp failed");
+            return false;
+        }
+        close(fd);
+
+        gssize pos = placeholder_ptr - cmd_line->str;
+        g_string_erase(cmd_line, pos, strlen(placeholder));
+        g_string_insert(cmd_line, pos, global_path_out);
+    }
+    return true;
+}
 
 /* Sometimes called by libfuzzer to mutate two inputs into one */
 size_t LLVMFuzzerCustomCrossOver(const uint8_t *data1, size_t size1,
@@ -213,6 +253,31 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
     g_string_append_printf(cmd_line, " %s -qtest /dev/null ",
                            getenv("QTEST_LOG") ? "" : "-qtest-log none");
 
+    /*
+     * For the VNC fuzzer, we replace placeholders for both the standard
+     * and WebSocket VNC listeners with unique socket paths.
+     */
+    if (strcmp(fuzz_target->name, "generic-fuzz-vnc") == 0) {
+        bool success = true;
+        success &= replace_socket_placeholder(cmd_line, "VNC_SOCKET_PATH",
+                                              "/tmp/qemu-vnc.XXXXXX", g_vnc_socket_path);
+        success &= replace_socket_placeholder(cmd_line, "VNC_WS_SOCKET_PATH",
+                                              "/tmp/qemu-vnc-ws.XXXXXX", g_vnc_ws_socket_path);
+
+        if (!success) {
+            exit(1);
+        }
+
+        /* Check that placeholders were actually found and replaced */
+        if (g_vnc_socket_path[0] == '\0' || g_vnc_ws_socket_path[0] == '\0') {
+            fprintf(stderr, "ERROR: VNC fuzzer is missing a socket placeholder\n");
+            exit(1);
+        }
+
+        /* Register a single cleanup handler for both sockets */
+        atexit(cleanup_vnc_sockets);
+    }
+
     /* Split the runcmd into an argv and argc */
     wordexp_t result;
     wordexp(cmd_line->str, &result, 0);
tests/qtest/fuzz/generic_fuzz_configs.h +5 -0
index ef0ad95712..bd2d875dd8 100644
@@ -247,6 +247,11 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .args = "-machine q35 -nodefaults "
+		"-vnc vnc=unix:VNC_SOCKET_PATH,websocket=unix:VNC_WS_SOCKET_PATH",
+        .objects = "*",
     }
 };
 
Signature · 1 line
2.51.0.760.g7b8bcc2412-goog
#5 lore raw

Friendly ping.

Quoted 136 lines · Navid Emamdoost

Add a new generic fuzz target for the QEMU VNC server. This target exercises both the standard VNC protocol and the VNC-over-WebSocket transport layer, increasing coverage of a primary remote attack surface.

To support parallel fuzzing (e.g., with oss-fuzz), the VNC unix socket paths are generated dynamically. The fuzzer harness inspects the command line for placeholders and replaces them with unique paths created by mkstemp() before execution.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
---
 tests/qtest/fuzz/fuzz.c                 | 65 +++++++++++++++++++++++++
 tests/qtest/fuzz/generic_fuzz_configs.h |  5 ++
 2 files changed, 70 insertions(+)
tests/qtest/fuzz/fuzz.c +65 -0
index ca248a51a6..b77c3ceb2b 100644
@@ -126,6 +126,46 @@ static FuzzTarget *fuzz_get_target(char* name)
     return NULL;
 }
 
+/*
+ * Global variables to hold the unique socket paths for cleanup.
+ */
+static char g_vnc_socket_path[sizeof("/tmp/qemu-vnc.XXXXXX")];
+static char g_vnc_ws_socket_path[sizeof("/tmp/qemu-vnc-ws.XXXXXX")];
+
+/*
+ * atexit() handler to clean up both socket files.
+ */
+static void cleanup_vnc_sockets(void)
+{
+    if (g_vnc_socket_path[0] != '\0') {
+        unlink(g_vnc_socket_path);
+    }
+    if (g_vnc_ws_socket_path[0] != '\0') {
+        unlink(g_vnc_ws_socket_path);
+    }
+}
+
+/* Helper function to find and replace a placeholder in a GString */
+static bool replace_socket_placeholder(GString *cmd_line, const char *placeholder,
+                                       const char *path_template, char *global_path_out)
+{
+    char *placeholder_ptr = strstr(cmd_line->str, placeholder);
+    if (placeholder_ptr) {
+        int fd;
+        strcpy(global_path_out, path_template);
+        fd = mkstemp(global_path_out);
+        if (fd == -1) {
+            perror("mkstemp failed");
+            return false;
+        }
+        close(fd);
+
+        gssize pos = placeholder_ptr - cmd_line->str;
+        g_string_erase(cmd_line, pos, strlen(placeholder));
+        g_string_insert(cmd_line, pos, global_path_out);
+    }
+    return true;
+}
 
 /* Sometimes called by libfuzzer to mutate two inputs into one */
 size_t LLVMFuzzerCustomCrossOver(const uint8_t *data1, size_t size1,
@@ -213,6 +253,31 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
     g_string_append_printf(cmd_line, " %s -qtest /dev/null ",
                            getenv("QTEST_LOG") ? "" : "-qtest-log none");
 
+    /*
+     * For the VNC fuzzer, we replace placeholders for both the standard
+     * and WebSocket VNC listeners with unique socket paths.
+     */
+    if (strcmp(fuzz_target->name, "generic-fuzz-vnc") == 0) {
+        bool success = true;
+        success &= replace_socket_placeholder(cmd_line, "VNC_SOCKET_PATH",
+                                              "/tmp/qemu-vnc.XXXXXX", g_vnc_socket_path);
+        success &= replace_socket_placeholder(cmd_line, "VNC_WS_SOCKET_PATH",
+                                              "/tmp/qemu-vnc-ws.XXXXXX", g_vnc_ws_socket_path);
+
+        if (!success) {
+            exit(1);
+        }
+
+        /* Check that placeholders were actually found and replaced */
+        if (g_vnc_socket_path[0] == '\0' || g_vnc_ws_socket_path[0] == '\0') {
+            fprintf(stderr, "ERROR: VNC fuzzer is missing a socket placeholder\n");
+            exit(1);
+        }
+
+        /* Register a single cleanup handler for both sockets */
+        atexit(cleanup_vnc_sockets);
+    }
+
     /* Split the runcmd into an argv and argc */
     wordexp_t result;
     wordexp(cmd_line->str, &result, 0);
tests/qtest/fuzz/generic_fuzz_configs.h +5 -1
index ef0ad95712..bd2d875dd8 100644
@@ -247,6 +247,11 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .args = "-machine q35 -nodefaults "
+               "-vnc vnc=unix:VNC_SOCKET_PATH,websocket=unix:VNC_WS_SOCKET_PATH",
+        .objects = "*",
     }
 };
 
--

2.51.0.760.g7b8bcc2412-goog

Signature · 2 lines
Thank you,
Navid.
#6 lore raw
In reply to Navid Emamdoost
Quoted 59 lines · Navid Emamdoost

Add a new generic fuzz target for the QEMU VNC server. This target exercises both the standard VNC protocol and the VNC-over-WebSocket transport layer, increasing coverage of a primary remote attack surface.

To support parallel fuzzing (e.g., with oss-fuzz), the VNC unix socket paths are generated dynamically. The fuzzer harness inspects the command line for placeholders and replaces them with unique paths created by mkstemp() before execution.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
---
 tests/qtest/fuzz/fuzz.c                 | 65 +++++++++++++++++++++++++
 tests/qtest/fuzz/generic_fuzz_configs.h |  5 ++
 2 files changed, 70 insertions(+)
tests/qtest/fuzz/fuzz.c +18 -0
index ca248a51a6..b77c3ceb2b 100644
@@ -126,6 +126,46 @@ static FuzzTarget *fuzz_get_target(char* name)
     return NULL;
 }
 
+/*
+ * Global variables to hold the unique socket paths for cleanup.
+ */
+static char g_vnc_socket_path[sizeof("/tmp/qemu-vnc.XXXXXX")];
+static char g_vnc_ws_socket_path[sizeof("/tmp/qemu-vnc-ws.XXXXXX")];
+
+/*
+ * atexit() handler to clean up both socket files.
+ */
+static void cleanup_vnc_sockets(void)
+{
+    if (g_vnc_socket_path[0] != '\0') {
+        unlink(g_vnc_socket_path);
+    }
+    if (g_vnc_ws_socket_path[0] != '\0') {
+        unlink(g_vnc_ws_socket_path);
+    }
+}

tests/qtest/fuzz/fuzz.c static FuzzTarget *fuzz_get_target(char* name) · line 156

Quoted 10 lines
tests/qtest/fuzz/fuzz.c +10 -0
+
+/* Helper function to find and replace a placeholder in a GString */
+static bool replace_socket_placeholder(GString *cmd_line, const char *placeholder,
+                                       const char *path_template, char *global_path_out)
+{
+    char *placeholder_ptr = strstr(cmd_line->str, placeholder);
+    if (placeholder_ptr) {
+        int fd;
+        strcpy(global_path_out, path_template);
+        fd = mkstemp(global_path_out);

Appologies for the delay. Let's use g_mkstemp, if possible.

Quoted 16 lines
tests/qtest/fuzz/fuzz.c +12 -0
+        if (fd == -1) {
+            perror("mkstemp failed");
+            return false;
+        }
+        close(fd);
+
+        gssize pos = placeholder_ptr - cmd_line->str;
+        g_string_erase(cmd_line, pos, strlen(placeholder));
+        g_string_insert(cmd_line, pos, global_path_out);
+    }
+    return true;
+}
 
 /* Sometimes called by libfuzzer to mutate two inputs into one */
 size_t LLVMFuzzerCustomCrossOver(const uint8_t *data1, size_t size1,

tests/qtest/fuzz/fuzz.c int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) · line 260

Quoted 8 lines
tests/qtest/fuzz/fuzz.c +5 -0
@@ -213,6 +253,31 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
     g_string_append_printf(cmd_line, " %s -qtest /dev/null ",
                            getenv("QTEST_LOG") ? "" : "-qtest-log none");
 
+    /*
+     * For the VNC fuzzer, we replace placeholders for both the standard
+     * and WebSocket VNC listeners with unique socket paths.
+     */
+    if (strcmp(fuzz_target->name, "generic-fuzz-vnc") == 0) {

Can generic_fuzz_config.argfunc be used here, instead? We use it for virtio_9p to create/share temp directories in generic_fuzzer_virtio_9p_args. I would rather have one way of dynamically generating arguments.

-Alex

Quoted 45 lines
tests/qtest/fuzz/fuzz.c +20 -0
+        bool success = true;
+        success &= replace_socket_placeholder(cmd_line, "VNC_SOCKET_PATH",
+                                              "/tmp/qemu-vnc.XXXXXX", g_vnc_socket_path);
+        success &= replace_socket_placeholder(cmd_line, "VNC_WS_SOCKET_PATH",
+                                              "/tmp/qemu-vnc-ws.XXXXXX", g_vnc_ws_socket_path);
+
+        if (!success) {
+            exit(1);
+        }
+
+        /* Check that placeholders were actually found and replaced */
+        if (g_vnc_socket_path[0] == '\0' || g_vnc_ws_socket_path[0] == '\0') {
+            fprintf(stderr, "ERROR: VNC fuzzer is missing a socket placeholder\n");
+            exit(1);
+        }
+
+        /* Register a single cleanup handler for both sockets */
+        atexit(cleanup_vnc_sockets);
+    }
+
 
 
 
     /* Split the runcmd into an argv and argc */
     wordexp_t result;
     wordexp(cmd_line->str, &result, 0);
tests/qtest/fuzz/generic_fuzz_configs.h +5 -1
index ef0ad95712..bd2d875dd8 100644
@@ -247,6 +247,11 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .args = "-machine q35 -nodefaults "
+		"-vnc vnc=unix:VNC_SOCKET_PATH,websocket=unix:VNC_WS_SOCKET_PATH",
+        .objects = "*",
     }
 };
 
--

2.51.0.760.g7b8bcc2412-goog

#7 lore raw

v3 cover tests/qtest/fuzz: Add generic fuzzer for VNC

Hi Alex,

Thank you for reviewing the patch and for the excellent feedback.

I've updated the patch to incorporate your suggestions. The new version uses the generic_fuzz_config.argfunc mechanism to dynamically generate the VNC socket arguments, which aligns it with the existing pattern.

---

Changes in v3:
- Removed VNC-specific logic from fuzz.c
- Created generic_fuzzer_vnc_args to encapsulate all the logic for the VNC fuzzer's arguments.
- Used g_mkstemp to create unique socket paths.

Navid Emamdoost (1):
tests/qtest/fuzz: Add generic fuzzer for VNC

 tests/qtest/fuzz/generic_fuzz_configs.h | 50 +++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
Signature · 1 line
2.51.2.1041.gc1ab5b90ca-goog
#8 lore raw

PATCH v3 1/1 tests/qtest/fuzz: Add generic fuzzer for VNC

Add a new generic fuzz target for the QEMU VNC server. This target exercises both the standard VNC protocol and the VNC-over-WebSocket transport layer, increasing coverage of a primary remote attack surface.

To support parallel fuzzing (e.g., with oss-fuzz), the VNC unix socket paths are generated dynamically. The fuzzer harness inspects the command line for placeholders and replaces them with unique paths created by mkstemp() before execution.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
---
 tests/qtest/fuzz/generic_fuzz_configs.h | 50 +++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
tests/qtest/fuzz/generic_fuzz_configs.h +50 -0
index ef0ad95712..9c46e106a4 100644
@@ -29,6 +29,52 @@ static inline gchar *generic_fuzzer_virtio_9p_args(void){
     "writeout=immediate,fmode=0600,dmode=0700", tmpdir);
 }
 
+/*
+ * Global variables and cleanup handler for VNC fuzzer sockets.
+ * These are needed because the socket paths must be available at exit.
+ */
+static char g_vnc_socket_path[sizeof("/tmp/qemu-vnc.XXXXXX")];
+static char g_vnc_ws_socket_path[sizeof("/tmp/qemu-vnc-ws.XXXXXX")];
+
+static void cleanup_vnc_sockets(void)
+{
+    if (g_vnc_socket_path[0] != '\0') {
+        unlink(g_vnc_socket_path);
+    }
+    if (g_vnc_ws_socket_path[0] != '\0') {
+        unlink(g_vnc_ws_socket_path);
+    }
+}
+
+/*
+ * Dynamically generate VNC arguments with unique unix socket paths.
+ * This allows multiple fuzzing jobs to run in parallel without conflict.
+ */
+static inline gchar *generic_fuzzer_vnc_args(void)
+{
+    static bool cleanup_registered = false;
+    int fd;
+
+    strcpy(g_vnc_socket_path, "/tmp/qemu-vnc.XXXXXX");
+    fd = g_mkstemp(g_vnc_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    strcpy(g_vnc_ws_socket_path, "/tmp/qemu-vnc-ws.XXXXXX");
+    fd = g_mkstemp(g_vnc_ws_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    if (!cleanup_registered) {
+        atexit(cleanup_vnc_sockets);
+        cleanup_registered = true;
+    }
+
+    return g_strdup_printf("-machine q35 -nodefaults "
+                           "-vnc vnc=unix:%s,websocket=unix:%s",
+                           g_vnc_socket_path, g_vnc_ws_socket_path);
+}
+
 const generic_fuzz_config predefined_configs[] = {
     {
         .name = "virtio-net-pci-slirp",
@@ -247,6 +293,10 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .argfunc = generic_fuzzer_vnc_args,
+        .objects = "*",
     }
 };
 
Signature · 1 line
2.51.2.1041.gc1ab5b90ca-goog
Reviewed-by on v3 1/1
#9 lore raw
Quoted 27 lines · Navid Emamdoost

Add a new generic fuzz target for the QEMU VNC server. This target exercises both the standard VNC protocol and the VNC-over-WebSocket transport layer, increasing coverage of a primary remote attack surface.

To support parallel fuzzing (e.g., with oss-fuzz), the VNC unix socket paths are generated dynamically. The fuzzer harness inspects the command line for placeholders and replaces them with unique paths created by mkstemp() before execution.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
Quoted 1 line
Quoted 76 lines
---
 tests/qtest/fuzz/generic_fuzz_configs.h | 50 +++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
tests/qtest/fuzz/generic_fuzz_configs.h +50 -1
index ef0ad95712..9c46e106a4 100644
@@ -29,6 +29,52 @@ static inline gchar *generic_fuzzer_virtio_9p_args(void){
     "writeout=immediate,fmode=0600,dmode=0700", tmpdir);
 }
 
+/*
+ * Global variables and cleanup handler for VNC fuzzer sockets.
+ * These are needed because the socket paths must be available at exit.
+ */
+static char g_vnc_socket_path[sizeof("/tmp/qemu-vnc.XXXXXX")];
+static char g_vnc_ws_socket_path[sizeof("/tmp/qemu-vnc-ws.XXXXXX")];
+
+static void cleanup_vnc_sockets(void)
+{
+    if (g_vnc_socket_path[0] != '\0') {
+        unlink(g_vnc_socket_path);
+    }
+    if (g_vnc_ws_socket_path[0] != '\0') {
+        unlink(g_vnc_ws_socket_path);
+    }
+}
+
+/*
+ * Dynamically generate VNC arguments with unique unix socket paths.
+ * This allows multiple fuzzing jobs to run in parallel without conflict.
+ */
+static inline gchar *generic_fuzzer_vnc_args(void)
+{
+    static bool cleanup_registered = false;
+    int fd;
+
+    strcpy(g_vnc_socket_path, "/tmp/qemu-vnc.XXXXXX");
+    fd = g_mkstemp(g_vnc_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    strcpy(g_vnc_ws_socket_path, "/tmp/qemu-vnc-ws.XXXXXX");
+    fd = g_mkstemp(g_vnc_ws_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    if (!cleanup_registered) {
+        atexit(cleanup_vnc_sockets);
+        cleanup_registered = true;
+    }
+
+    return g_strdup_printf("-machine q35 -nodefaults "
+                           "-vnc vnc=unix:%s,websocket=unix:%s",
+                           g_vnc_socket_path, g_vnc_ws_socket_path);
+}
+
 const generic_fuzz_config predefined_configs[] = {
     {
         .name = "virtio-net-pci-slirp",
@@ -247,6 +293,10 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .argfunc = generic_fuzzer_vnc_args,
+        .objects = "*",
     }
 };
 
--

2.51.2.1041.gc1ab5b90ca-goog

#10 lore raw

Hi Alexander,

I don't see this old fuzzing patch merged yet. Who is normally collecting and merging fuzz patches ?

Quoted 104 lines · Alexander Bulekov
Quoted 27 lines · Navid Emamdoost

Add a new generic fuzz target for the QEMU VNC server. This target exercises both the standard VNC protocol and the VNC-over-WebSocket transport layer, increasing coverage of a primary remote attack surface.

To support parallel fuzzing (e.g., with oss-fuzz), the VNC unix socket paths are generated dynamically. The fuzzer harness inspects the command line for placeholders and replaces them with unique paths created by mkstemp() before execution.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
Quoted 1 line
Quoted 72 lines
---
 tests/qtest/fuzz/generic_fuzz_configs.h | 50 +++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
tests/qtest/fuzz/generic_fuzz_configs.h +50 -0
index ef0ad95712..9c46e106a4 100644
@@ -29,6 +29,52 @@ static inline gchar *generic_fuzzer_virtio_9p_args(void){
     "writeout=immediate,fmode=0600,dmode=0700", tmpdir);
 }
 
+/*
+ * Global variables and cleanup handler for VNC fuzzer sockets.
+ * These are needed because the socket paths must be available at exit.
+ */
+static char g_vnc_socket_path[sizeof("/tmp/qemu-vnc.XXXXXX")];
+static char g_vnc_ws_socket_path[sizeof("/tmp/qemu-vnc-ws.XXXXXX")];
+
+static void cleanup_vnc_sockets(void)
+{
+    if (g_vnc_socket_path[0] != '\0') {
+        unlink(g_vnc_socket_path);
+    }
+    if (g_vnc_ws_socket_path[0] != '\0') {
+        unlink(g_vnc_ws_socket_path);
+    }
+}
+
+/*
+ * Dynamically generate VNC arguments with unique unix socket paths.
+ * This allows multiple fuzzing jobs to run in parallel without conflict.
+ */
+static inline gchar *generic_fuzzer_vnc_args(void)
+{
+    static bool cleanup_registered = false;
+    int fd;
+
+    strcpy(g_vnc_socket_path, "/tmp/qemu-vnc.XXXXXX");
+    fd = g_mkstemp(g_vnc_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    strcpy(g_vnc_ws_socket_path, "/tmp/qemu-vnc-ws.XXXXXX");
+    fd = g_mkstemp(g_vnc_ws_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    if (!cleanup_registered) {
+        atexit(cleanup_vnc_sockets);
+        cleanup_registered = true;
+    }
+
+    return g_strdup_printf("-machine q35 -nodefaults "
+                           "-vnc vnc=unix:%s,websocket=unix:%s",
+                           g_vnc_socket_path, g_vnc_ws_socket_path);
+}
+
 const generic_fuzz_config predefined_configs[] = {
     {
         .name = "virtio-net-pci-slirp",
@@ -247,6 +293,10 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .argfunc = generic_fuzzer_vnc_args,
+        .objects = "*",
     }
 };
 
Quoted 5 lines
Quoted 4 lines

--
2.51.2.1041.gc1ab5b90ca-goog

With 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 :|
#11 lore raw
Quoted 4 lines · Daniel P. Berrangé

Hi Alexander,

I don't see this old fuzzing patch merged yet. Who is normally collecting and merging fuzz patches ?

Hi Daniel,
In the past, as far as I remember it has been either me or Thomas. I can put together the pull-req. Apologies for the delay

Quoted 119 lines · Alexander Bulekov
Quoted 104 lines · Navid Emamdoost
Quoted 27 lines

Add a new generic fuzz target for the QEMU VNC server. This target exercises both the standard VNC protocol and the VNC-over-WebSocket transport layer, increasing coverage of a primary remote attack surface.

To support parallel fuzzing (e.g., with oss-fuzz), the VNC unix socket paths are generated dynamically. The fuzzer harness inspects the command line for placeholders and replaces them with unique paths created by mkstemp() before execution.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
Quoted 1 line
Quoted 72 lines
---
 tests/qtest/fuzz/generic_fuzz_configs.h | 50 +++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
tests/qtest/fuzz/generic_fuzz_configs.h +50 -0
index ef0ad95712..9c46e106a4 100644
@@ -29,6 +29,52 @@ static inline gchar *generic_fuzzer_virtio_9p_args(void){
     "writeout=immediate,fmode=0600,dmode=0700", tmpdir);
 }
 
+/*
+ * Global variables and cleanup handler for VNC fuzzer sockets.
+ * These are needed because the socket paths must be available at exit.
+ */
+static char g_vnc_socket_path[sizeof("/tmp/qemu-vnc.XXXXXX")];
+static char g_vnc_ws_socket_path[sizeof("/tmp/qemu-vnc-ws.XXXXXX")];
+
+static void cleanup_vnc_sockets(void)
+{
+    if (g_vnc_socket_path[0] != '\0') {
+        unlink(g_vnc_socket_path);
+    }
+    if (g_vnc_ws_socket_path[0] != '\0') {
+        unlink(g_vnc_ws_socket_path);
+    }
+}
+
+/*
+ * Dynamically generate VNC arguments with unique unix socket paths.
+ * This allows multiple fuzzing jobs to run in parallel without conflict.
+ */
+static inline gchar *generic_fuzzer_vnc_args(void)
+{
+    static bool cleanup_registered = false;
+    int fd;
+
+    strcpy(g_vnc_socket_path, "/tmp/qemu-vnc.XXXXXX");
+    fd = g_mkstemp(g_vnc_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    strcpy(g_vnc_ws_socket_path, "/tmp/qemu-vnc-ws.XXXXXX");
+    fd = g_mkstemp(g_vnc_ws_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    if (!cleanup_registered) {
+        atexit(cleanup_vnc_sockets);
+        cleanup_registered = true;
+    }
+
+    return g_strdup_printf("-machine q35 -nodefaults "
+                           "-vnc vnc=unix:%s,websocket=unix:%s",
+                           g_vnc_socket_path, g_vnc_ws_socket_path);
+}
+
 const generic_fuzz_config predefined_configs[] = {
     {
         .name = "virtio-net-pci-slirp",
@@ -247,6 +293,10 @@ const generic_fuzz_config predefined_configs[] = {
         .args = "-machine q35 -nodefaults "
         "-parallel file:/dev/null",
         .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .argfunc = generic_fuzzer_vnc_args,
+        .objects = "*",
     }
 };
 
Quoted 5 lines
Quoted 4 lines

--
2.51.2.1041.gc1ab5b90ca-goog

With regards,
Daniel
--

|: 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 :|
#12 lore raw
Quoted 9 lines · Alexander Bulekov
Quoted 4 lines · Daniel P. Berrangé

Hi Alexander,

I don't see this old fuzzing patch merged yet. Who is normally collecting and merging fuzz patches ?

Hi Daniel,
In the past, as far as I remember it has been either me or Thomas. I can put together the pull-req. Apologies for the delay

Hi,

FYI, I handed over the maintainership of the qtests to Fabiano Rosas, so I'm not looking for qtest-related patches anymore. Please CC: Fabiano if you want to get something merged by him. Thanks!

Regards,
Thomas

Quoted 120 lines
Quoted 119 lines · Alexander Bulekov
Quoted 104 lines · Navid Emamdoost
Quoted 27 lines

Add a new generic fuzz target for the QEMU VNC server. This target exercises both the standard VNC protocol and the VNC-over-WebSocket transport layer, increasing coverage of a primary remote attack surface.

To support parallel fuzzing (e.g., with oss-fuzz), the VNC unix socket paths are generated dynamically. The fuzzer harness inspects the command line for placeholders and replaces them with unique paths created by mkstemp() before execution.

---

This new target increases code coverage in the VNC subsystem and related networking and I/O code.
The baseline coverage below was generated by running all existing fuzz targets with the oss-fuzz corpus. The new target shows significant gains:

----------------------------------------------------------------------------
File New Target Baseline Change
----------------------------------------------------------------------------

vnc.c                      339/3212 (10.6%)     3/3212 (0.1%)        +336
keymaps.c                  91/184 (49.5%)       0/184 (0.0%)         +91
net-listener.c             76/198 (38.4%)       3/198 (1.5%)         +73
channel-socket.c           73/575 (12.7%)       19/575 (3.3%)        +54
qemu-sockets.c             44/1019 (4.3%)       0/1019 (0.0%)        +44
vnc-jobs.c                 41/219 (18.7%)       0/219 (0.0%)         +41
dns-resolver.c             28/145 (19.3%)       3/145 (2.1%)         +25
Quoted 1 line
Quoted 72 lines
---
  tests/qtest/fuzz/generic_fuzz_configs.h | 50 +++++++++++++++++++++++++
  1 file changed, 50 insertions(+)
tests/qtest/fuzz/generic_fuzz_configs.h +50 -0
index ef0ad95712..9c46e106a4 100644
@@ -29,6 +29,52 @@ static inline gchar *generic_fuzzer_virtio_9p_args(void){
      "writeout=immediate,fmode=0600,dmode=0700", tmpdir);
  }
 
+/*
+ * Global variables and cleanup handler for VNC fuzzer sockets.
+ * These are needed because the socket paths must be available at exit.
+ */
+static char g_vnc_socket_path[sizeof("/tmp/qemu-vnc.XXXXXX")];
+static char g_vnc_ws_socket_path[sizeof("/tmp/qemu-vnc-ws.XXXXXX")];
+
+static void cleanup_vnc_sockets(void)
+{
+    if (g_vnc_socket_path[0] != '\0') {
+        unlink(g_vnc_socket_path);
+    }
+    if (g_vnc_ws_socket_path[0] != '\0') {
+        unlink(g_vnc_ws_socket_path);
+    }
+}
+
+/*
+ * Dynamically generate VNC arguments with unique unix socket paths.
+ * This allows multiple fuzzing jobs to run in parallel without conflict.
+ */
+static inline gchar *generic_fuzzer_vnc_args(void)
+{
+    static bool cleanup_registered = false;
+    int fd;
+
+    strcpy(g_vnc_socket_path, "/tmp/qemu-vnc.XXXXXX");
+    fd = g_mkstemp(g_vnc_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    strcpy(g_vnc_ws_socket_path, "/tmp/qemu-vnc-ws.XXXXXX");
+    fd = g_mkstemp(g_vnc_ws_socket_path);
+    g_assert_cmpint(fd, !=, -1);
+    close(fd);
+
+    if (!cleanup_registered) {
+        atexit(cleanup_vnc_sockets);
+        cleanup_registered = true;
+    }
+
+    return g_strdup_printf("-machine q35 -nodefaults "
+                           "-vnc vnc=unix:%s,websocket=unix:%s",
+                           g_vnc_socket_path, g_vnc_ws_socket_path);
+}
+
  const generic_fuzz_config predefined_configs[] = {
      {
          .name = "virtio-net-pci-slirp",
@@ -247,6 +293,10 @@ const generic_fuzz_config predefined_configs[] = {
          .args = "-machine q35 -nodefaults "
          "-parallel file:/dev/null",
          .objects = "parallel*",
+    },{
+        .name = "vnc",
+        .argfunc = generic_fuzzer_vnc_args,
+        .objects = "*",
      }
  };
 
Quoted 5 lines
Quoted 4 lines

--
2.51.2.1041.gc1ab5b90ca-goog

With regards,
Daniel
--

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