From: zhaoguohan@kylinos.cn
To: Jason Wang <jasowang@redhat.com>
Cc: qemu-devel@nongnu.org, GuoHan Zhao <zhaoguohan@kylinos.cn>
Subject: [PATCH] net/passt: don't close socketpair fds after ownership transfer
Date: Tue, 24 Mar 2026 11:04:39 +0800 [thread overview]
Message-ID: <20260324030439.820494-1-zhaoguohan@kylinos.cn> (raw)
From: GuoHan Zhao <zhaoguohan@kylinos.cn>
qemu_chr_add_client() and g_subprocess_launcher_take_fd() take
ownership of sv[0] and sv[1], respectively.
Closing them in the caller after the handoff can result in the same
fd being closed twice when the owning cleanup path runs.
Avoid this by tracking ownership and only closing descriptors that
are still owned by the caller.
Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
---
net/passt.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/net/passt.c b/net/passt.c
index 4ff94ee509d4..930fe44cce4f 100644
--- a/net/passt.c
+++ b/net/passt.c
@@ -331,10 +331,8 @@ static int net_passt_stream_start(NetPasstState *s, Error **errp)
/* start passt */
if (net_passt_start_daemon(s, sv[1], errp) == -1) {
close(sv[0]);
- close(sv[1]);
return -1;
}
- close(sv[1]);
return 0;
}
@@ -458,6 +456,7 @@ static int net_passt_vhost_user_init(NetPasstState *s, Error **errp)
error_setg(errp, "Failed to make socket chardev");
goto err;
}
+ sv[0] = -1;
s->vhost_user = g_new0(struct VhostUserState, 1);
if (!qemu_chr_fe_init(&s->vhost_chr, chr, errp) ||
@@ -467,8 +466,10 @@ static int net_passt_vhost_user_init(NetPasstState *s, Error **errp)
/* start passt */
if (net_passt_start_daemon(s, sv[1], errp) == -1) {
+ sv[1] = -1;
goto err;
}
+ sv[1] = -1;
do {
if (qemu_chr_fe_wait_connected(&s->vhost_chr, errp) < 0) {
@@ -482,11 +483,14 @@ static int net_passt_vhost_user_init(NetPasstState *s, Error **errp)
qemu_set_info_str(&s->data.nc, "vhost-user,connected to pid %d", s->pid);
- close(sv[1]);
return 0;
err:
- close(sv[0]);
- close(sv[1]);
+ if (sv[0] >= 0) {
+ close(sv[0]);
+ }
+ if (sv[1] >= 0) {
+ close(sv[1]);
+ }
return -1;
}
--
2.43.0
reply other threads:[~2026-03-24 4:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260324030439.820494-1-zhaoguohan@kylinos.cn \
--to=zhaoguohan@kylinos.cn \
--cc=jasowang@redhat.com \
--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