* [PATCH] gdbstub: Fix double close() of the follow-fork-mode socket
@ 2024-03-12 0:07 Ilya Leoshkevich
2024-03-12 8:10 ` Alex Bennée
0 siblings, 1 reply; 2+ messages in thread
From: Ilya Leoshkevich @ 2024-03-12 0:07 UTC (permalink / raw)
To: Alex Bennée, Peter Maydell; +Cc: qemu-devel, Ilya Leoshkevich
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>
---
gdbstub/user.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/gdbstub/user.c b/gdbstub/user.c
index 7f9f19a1249..08aed022e26 100644
--- a/gdbstub/user.c
+++ b/gdbstub/user.c
@@ -502,6 +502,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;
@@ -527,7 +528,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:
@@ -542,7 +542,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.44.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] gdbstub: Fix double close() of the follow-fork-mode socket
2024-03-12 0:07 [PATCH] gdbstub: Fix double close() of the follow-fork-mode socket Ilya Leoshkevich
@ 2024-03-12 8:10 ` Alex Bennée
0 siblings, 0 replies; 2+ messages in thread
From: Alex Bennée @ 2024-03-12 8:10 UTC (permalink / raw)
To: Ilya Leoshkevich; +Cc: Peter Maydell, qemu-devel
Ilya Leoshkevich <iii@linux.ibm.com> writes:
> 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>
Queued to gdbstub/next, thanks.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-12 10:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-12 0:07 [PATCH] gdbstub: Fix double close() of the follow-fork-mode socket Ilya Leoshkevich
2024-03-12 8:10 ` Alex Bennée
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).