From: Philipp Rudo <prudo@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] Fix read after xfree in linux_nat_detach
Date: Wed, 22 Mar 2017 13:11:00 -0000 [thread overview]
Message-ID: <20170322131132.98976-2-prudo@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170322131132.98976-1-prudo@linux.vnet.ibm.com>
At the end of linux_nat_detach there is a check whether the inferior has a
fork. If no fork exists the main_lwp is detached (detach_one_lwp) and
later, outside the check, deleted (delete_lwp). This is problematic as
detach_one_lwp also calls delete_lwp freeing main_lwp. Thus the second
call to delete_lwp reads from already freed memory. Fix this by removing
delete_lwp at the end of detach_one_lwp.
gdb/ChangeLog:
* linux-nat.c (detach_one_lwp): Remove call to delete_lwp.
(detach_callback): Add call to delete_lwp and rename ...
(detach_and_delete_callback): ... to this.
(linux_nat_detach): Adjust.
---
gdb/linux-nat.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 73ef2d4..b578f69 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1483,18 +1483,19 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p)
target_pid_to_str (lp->ptid),
strsignal (signo));
}
-
- delete_lwp (lp->ptid);
}
static int
-detach_callback (struct lwp_info *lp, void *data)
+detach_and_delete_callback (struct lwp_info *lp, void *data)
{
/* We don't actually detach from the thread group leader just yet.
If the thread group exits, we must reap the zombie clone lwps
before we're able to reap the leader. */
if (ptid_get_lwp (lp->ptid) != ptid_get_pid (lp->ptid))
- detach_one_lwp (lp, NULL);
+ {
+ detach_one_lwp (lp, NULL);
+ delete_lwp (lp->ptid);
+ }
return 0;
}
@@ -1516,7 +1517,7 @@ linux_nat_detach (struct target_ops *ops, const char *args, int from_tty)
they're no longer running. */
iterate_over_lwps (pid_to_ptid (pid), stop_wait_callback, NULL);
- iterate_over_lwps (pid_to_ptid (pid), detach_callback, NULL);
+ iterate_over_lwps (pid_to_ptid (pid), detach_and_delete_callback, NULL);
/* Only the initial process should be left right now. */
gdb_assert (num_lwps (ptid_get_pid (inferior_ptid)) == 1);
--
2.8.4
next prev parent reply other threads:[~2017-03-22 13:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-22 13:11 [PATCH] Fix memory leak in python.c:do_start_initialization Philipp Rudo
2017-03-22 13:11 ` Philipp Rudo [this message]
2017-03-22 15:07 ` [PATCH] Fix read after xfree in linux_nat_detach Pedro Alves
2017-03-22 17:17 ` Philipp Rudo
2017-03-22 17:26 ` Pedro Alves
2017-03-23 13:17 ` [PATCH v2] " Philipp Rudo
2017-03-23 13:42 ` Pedro Alves
[not found] ` <f712cd1a-cf44-44da-9bf4-3ccd407a76a0@redhat.com>
2017-04-12 8:14 ` Philipp Rudo
2017-03-22 15:19 ` [PATCH] Fix memory leak in python.c:do_start_initialization Pedro Alves
2017-03-22 17:52 ` Philipp Rudo
2017-03-22 18:45 ` Pedro Alves
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=20170322131132.98976-2-prudo@linux.vnet.ibm.com \
--to=prudo@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.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