qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Arun Menon <armenon@redhat.com>,
	Juraj Marcin <jmarcin@redhat.com>,
	peterx@redhat.com, Fabiano Rosas <farosas@suse.de>
Subject: [PATCH v2 3/4] migration/cpr: Fix UAF in cpr_exec_cb() when execvp() fails
Date: Tue, 21 Oct 2025 18:04:06 -0400	[thread overview]
Message-ID: <20251021220407.2662288-4-peterx@redhat.com> (raw)
In-Reply-To: <20251021220407.2662288-1-peterx@redhat.com>

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>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/cpr-exec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/migration/cpr-exec.c b/migration/cpr-exec.c
index 087ca94c87..d284f6e734 100644
--- a/migration/cpr-exec.c
+++ b/migration/cpr-exec.c
@@ -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);
-- 
2.50.1



  parent reply	other threads:[~2025-10-21 22:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21 22:04 [PATCH v2 0/4] migration: A few fixes on coverity reports Peter Xu
2025-10-21 22:04 ` [PATCH v2 1/4] migration: Fix error leak in postcopy_ram_listen_thread() Peter Xu
2025-10-22 12:25   ` Fabiano Rosas
2025-10-21 22:04 ` [PATCH v2 2/4] migration/cpr: Fix coverity report in cpr_exec_persist_state() Peter Xu
2025-10-22 12:27   ` Fabiano Rosas
2025-10-21 22:04 ` Peter Xu [this message]
2025-10-21 22:04 ` [PATCH v2 4/4] migration/cpr: Avoid crashing QEMU when cpr-exec runs with no args Peter Xu
2025-10-22 12:27   ` Fabiano Rosas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251021220407.2662288-4-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=armenon@redhat.com \
    --cc=farosas@suse.de \
    --cc=jmarcin@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).