Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion PT_EXITKILL (Was: pdeath_signal)

Received: by 10.180.99.163 with SMTP id er3mr5744059wib.2.1352380205065;
        Thu, 08 Nov 2012 05:10:05 -0800 (PST)
Path: ha8ni169901wib.1!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!newsfeed.x-privat.org!bofh.it!news.nic.it!robomod
From: u3...@miso.sublimeip.com (Amnon Shiloh)
Newsgroups: linux.kernel
Subject: Re: PT_EXITKILL (Was: pdeath_signal)
Date: Thu, 08 Nov 2012 14:10:04 +0100
Message-ID: <k3A1S-2kF-79@gated-at.bofh.it>
References: <k3zyO-1Ct-29@gated-at.bofh.it>
X-Original-To: o...@redhat.com (Oleg Nesterov)
Reply-To: u3...@dialix.com.au
X-Mailer: ELM [version 2.5 PL8]
MIME-Version: 1.0
Sender: robo...@news.nic.it
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org
Approved: robo...@news.nic.it
Lines: 73
Organization: linux.* mail to news gateway
X-Original-Cc: dvlas...@redhat.com (Denys Vlasenko),
	mtk.manpa...@gmail.com (Michael Kerrisk),
	serge.hal...@canonical.com (Serge Hallyn),
	scarybea...@gmail.com (Chris Evans),
	dhowe...@redhat.com (David Howells),
	ebied...@xmission.com (Eric W. Biederman),
	a...@linux-foundation.org (Andrew Morton), u3...@dialix.com.au,
	secur...@kernel.org, linux-ker...@vger.kernel.org
X-Original-Date: Fri, 9 Nov 2012 00:03:48 +1100 (EST)
X-Original-Message-ID: <20121108130348.4F9CB592017@miso.sublimeip.com>
X-Original-References: <20121108123716.GA20...@redhat.com>
X-Original-Sender: linux-kernel-ow...@vger.kernel.org
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi Again,

> Or the child can check getppid() == saved_parent_pid after PTRACE_TRACEME.

In fact that's what I did when I  tested the new option - the child ran:

	volatile long ready = 0;
	int saved_parent_pid = getpid();

	if(!(son = fork())
	{
		while(!ready)
		{
			sched_yield();
			if(getppid() != saved_parent_pid)
				exit(1);
		}
		execve(...);
	}
	ptrace(PTRACE_ATTACH, son, 0, 0);
	waitpid(son, ...);
	ptrace(PTRACE_SETOPTIONS, son, 0, PTRACE_P_TRACEFORK|PTRACE_O_EXITKILL);
	ptrace(PTRACE_POKEDATA, son, &ready, 1);
	/* continue tracing */

I also checked that PTRACE_O_EXITKILL is inherited to grandchildren.

Yes, I may also use PTRACE_SEIZE, but since it is not yet documented,
I will need to read the kernel code more to make extra sure it has no
unwanted side effects.

Best Regards,
Amnon.


Oleg Nesterov wrote:
> 
> Hi Amnon,
> 
> On 11/08, Amnon Shiloh wrote:
> >
> > Thanks for the patch, I tried it and it works nicely!
> 
> OK, thanks. I'll wait for other comments a bit and then send
> the patch to Andrew.
> 
> > Also, I just noticed that this new option (PTRACE_O_EXITKILL) is not
> > safe with ptrace(PTRACE_TRACEME)+execve, because the parent may die
> > before even having a chance to set PTRACE_O_EXITKILL!
> 
> Not safe? I guess you meant that PTRACE_O_EXITKILL can't prevent
> this race? Yes sure. Or the parent can die before it does
> PTRACE_O_EXITKILL.
> 
> > However, that's easy to fix by using PTRACE_ATTACH instead.
> 
> Or the child can check getppid() == saved_parent_pid after PTRACE_TRACEME.
> 
> But if you switch to PTRACE_ATTACH, I'd suggest to use PTRACE_SEIZE.
> Note that, in particular, this allows you to specify the options at
> attach.
> 
> As for PF_NO_SIGSTOP, I'll write another email.
> 
> Oleg.
> 
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/