]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
migration/cpr: Fix UAF in cpr_exec_cb() when execvp() fails
authorPeter Xu <peterx@redhat.com>
Tue, 21 Oct 2025 22:04:06 +0000 (18:04 -0400)
committerPeter Xu <peterx@redhat.com>
Mon, 3 Nov 2025 21:04:09 +0000 (16:04 -0500)
Per reported and analyzed by Peter:

https://lore.kernel.org/r/CAFEAcA82ih8RVCm-u1oxiS0V2K4rV4jMzNb13pAV=e2ivmiDRA@mail.gmail.com

Fix the issue by moving the error_setg_errno() earlier.  When at it, clear
argv variable after freed.

Resolves: Coverity CID 1641397
Fixes: a3eae205c6 ("migration: cpr-exec mode")
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20251021220407.2662288-4-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
migration/cpr-exec.c

index 087ca94c8704290da93e97c33c757659413519c7..d284f6e73417be643f73a3a46a880002346be1bd 100644 (file)
@@ -152,10 +152,10 @@ static void cpr_exec_cb(void *opaque)
      * exec should only fail if argv[0] is bogus, or has a permissions problem,
      * or the system is very short on resources.
      */
-    g_strfreev(argv);
+    error_setg_errno(&err, errno, "execvp %s failed", argv[0]);
+    g_clear_pointer(&argv, g_strfreev);
     cpr_exec_unpreserve_fds();
 
-    error_setg_errno(&err, errno, "execvp %s failed", argv[0]);
     error_report_err(error_copy(err));
     migrate_set_state(&s->state, s->state, MIGRATION_STATUS_FAILED);
     migrate_set_error(s, err);