Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Philipp Rudo <prudo@linux.vnet.ibm.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: [PATCH v2] Fix read after xfree in linux_nat_detach
Date: Thu, 23 Mar 2017 13:17:00 -0000	[thread overview]
Message-ID: <20170323141724.1707affa@ThinkPad> (raw)
In-Reply-To: <4fd5805f-7763-9548-d743-45dd2aa1b17c@redhat.com>

On Wed, 22 Mar 2017 17:26:27 +0000
Pedro Alves <palves@redhat.com> wrote:

> On 03/22/2017 05:16 PM, Philipp Rudo wrote:
> 
> > Looks like we can get simply rid of it.  I'll see that I get a test
> > case running which forks to verify it, tomorrow.  
> 
> This forks handling is the support for the "checkpoint" & 
> friends commands, covered by gdb.base/checkpoint.exp.
> Doesn't seem to exercise detach yet though, unfortunately.

I double checked, the same bug also happens when checkpointing.  The
fix now is simply to remove delete_lwp at the end of linux_nat_detach.

Although testing detach would be good, I'm not sure if the testsuite
would have found this bug.

---

From ee3dced0b22cc1edb10a82aeb79ae35d78d665bc Mon Sep 17 00:00:00 2001
From: Philipp Rudo <prudo@linux.vnet.ibm.com>
Date: Wed, 22 Mar 2017 13:53:50 +0100
Subject: [PATCH v2] Fix read after xfree in linux_nat_detach

At the end of linux_nat_detach the main_lwp is deleted (delete_lwp).
This is problematic as during detach (detach_one_lwp and
linux_fork_detach) main_lwp already gets freed.  Thus calling
delete_lwp causes a read after free.  Fix it by removing the
unnecessary delete_lwp.

gdb/ChangeLog:
	* linux-nat.c (linux_nat_detach): delete_lwp causes read after
free. Remove it.
---
 gdb/linux-nat.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index dff0da5..efe7daf 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1549,7 +1549,6 @@ linux_nat_detach (struct target_ops *ops, const
char *args, int from_tty) 
       inf_ptrace_detach_success (ops);
     }
-  delete_lwp (main_lwp->ptid);
 }
 
 /* Resume execution of the inferior process.  If STEP is nonzero,
-- 
2.8.4


  reply	other threads:[~2017-03-23 13:17 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 ` [PATCH] Fix read after xfree in linux_nat_detach Philipp Rudo
2017-03-22 15:07   ` Pedro Alves
2017-03-22 17:17     ` Philipp Rudo
2017-03-22 17:26       ` Pedro Alves
2017-03-23 13:17         ` Philipp Rudo [this message]
2017-03-23 13:42           ` [PATCH v2] " 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=20170323141724.1707affa@ThinkPad \
    --to=prudo@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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