From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Ilya Leoshkevich" <iii@linux.ibm.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 8/8] gdbstub: Fix double close() of the follow-fork-mode socket
Date: Tue, 12 Mar 2024 11:25:32 +0000 [thread overview]
Message-ID: <20240312112532.1558319-9-alex.bennee@linaro.org> (raw)
In-Reply-To: <20240312112532.1558319-1-alex.bennee@linaro.org>
From: Ilya Leoshkevich <iii@linux.ibm.com>
When the terminal GDB_FORK_ENABLED state is reached, the coordination
socket is not needed anymore and is therefore closed. However, if there
is a communication error between QEMU gdbstub and GDB, the generic
error handling code attempts to close it again.
Fix by closing it later - before returning - instead.
Fixes: Coverity CID 1539966
Fixes: d547e711a8a5 ("gdbstub: Implement follow-fork-mode child")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20240312001813.13720-1-iii@linux.ibm.com>
diff --git a/gdbstub/user.c b/gdbstub/user.c
index 2005f3312b..edeb72efeb 100644
--- a/gdbstub/user.c
+++ b/gdbstub/user.c
@@ -517,6 +517,7 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid)
switch (gdbserver_user_state.fork_state) {
case GDB_FORK_ENABLED:
if (gdbserver_user_state.running_state) {
+ close(fd);
return;
}
QEMU_FALLTHROUGH;
@@ -542,7 +543,6 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid)
gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
break;
case GDB_FORK_ENABLE:
- close(fd);
gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
break;
case GDB_FORK_DISABLE:
@@ -557,7 +557,6 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid)
if (write(fd, &b, 1) != 1) {
goto fail;
}
- close(fd);
gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
break;
case GDB_FORK_DISABLING:
--
2.39.2
next prev parent reply other threads:[~2024-03-12 11:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 11:25 [PULL for 9.0 0/8] final maintainer updates (testing, gdbstub) Alex Bennée
2024-03-12 11:25 ` [PULL 1/8] gitlab: aggressively avoid extra GIT data Alex Bennée
2024-03-12 11:25 ` [PULL 2/8] tests/vm: ensure we build everything by default Alex Bennée
2024-03-12 11:25 ` [PULL 3/8] gdbstub: Rename back gdb_handlesig Alex Bennée
2024-03-12 11:25 ` [PULL 4/8] linux-user: Move tswap_siginfo out of target code Alex Bennée
2024-03-12 11:25 ` [PULL 5/8] gdbstub: Save target's siginfo Alex Bennée
2024-03-12 11:25 ` [PULL 6/8] gdbstub: Add Xfer:siginfo:read stub Alex Bennée
2024-03-12 11:25 ` [PULL 7/8] tests/tcg: Add multiarch test for " Alex Bennée
2024-03-12 11:25 ` Alex Bennée [this message]
2024-03-12 13:42 ` [PULL for 9.0 0/8] final maintainer updates (testing, gdbstub) Peter Maydell
2024-03-12 15:01 ` Alex Bennée
2024-03-12 15:19 ` Peter Maydell
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=20240312112532.1558319-9-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=iii@linux.ibm.com \
--cc=philmd@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).