From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Brauner Subject: Re: [RFC v2] ptrace, pidfd: add pidfd_ptrace syscall Date: Mon, 27 Apr 2020 19:08:26 +0200 Message-ID: <20200427170826.mdklazcrn4xaeafm@wittgenstein> References: <20200426130100.306246-1-hagen@jauu.net> <20200426163430.22743-1-hagen@jauu.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Return-path: Content-Disposition: inline In-Reply-To: <20200426163430.22743-1-hagen-GvnIQ6b/HdU@public.gmane.org> Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Hagen Paul Pfeifer Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Florian Weimer , Al Viro , Christian Brauner , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Arnd Bergmann , Brian Gerst , Sami Tolvanen , David Howells , Aleksa Sarai , Andy Lutomirski , Oleg Nesterov , "Eric W . Biederman" , Arnaldo Carvalho de Melo , Sargun Dhillon , linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-arch.vger.kernel.org On Sun, Apr 26, 2020 at 06:34:30PM +0200, Hagen Paul Pfeifer wrote: > Working on a safety-critical stress testing tool, using ptrace in an > rather uncommon way (stop, peeking memory, ...) for a bunch of > applications in an automated way I realized that once opened processes > where restarted and PIDs recycled. Resulting in monitoring and > manipulating the wrong processes. > > With the advent of pidfd we are now able to stick with one stable handle > to identifying processes exactly. We now have the ability to get this > race free. Sending signals now works like a charm, next step is to > extend the functionality also for ptrace. > > API: > long pidfd_ptrace(int pidfd, enum __ptrace_request request, > void *addr, void *data, unsigned flags); I'm in general not opposed to this if there's a clear need for this and users that are interested. But I think if people really prefer having this a new syscall then we should probably try to improve on the old one. Things that come to mind right away without doing a deep review are replacing the void *addr pointer with a dedicated struct ptract_args or union ptrace_args and a size argument. If we're not doing something like this or something more fundamental we can equally well either just duplicate all enums in the old ptrace syscall and append a _PIDFD to it where it makes sense. Christian From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from youngberry.canonical.com ([91.189.89.112]:37408 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726194AbgD0RIa (ORCPT ); Mon, 27 Apr 2020 13:08:30 -0400 Date: Mon, 27 Apr 2020 19:08:26 +0200 From: Christian Brauner Subject: Re: [RFC v2] ptrace, pidfd: add pidfd_ptrace syscall Message-ID: <20200427170826.mdklazcrn4xaeafm@wittgenstein> References: <20200426130100.306246-1-hagen@jauu.net> <20200426163430.22743-1-hagen@jauu.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200426163430.22743-1-hagen@jauu.net> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Hagen Paul Pfeifer Cc: linux-kernel@vger.kernel.org, Florian Weimer , Al Viro , Christian Brauner , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Arnd Bergmann , Brian Gerst , Sami Tolvanen , David Howells , Aleksa Sarai , Andy Lutomirski , Oleg Nesterov , "Eric W . Biederman" , Arnaldo Carvalho de Melo , Sargun Dhillon , linux-api@vger.kernel.org, linux-arch@vger.kernel.org Message-ID: <20200427170826.IOPIV6yMNc1CBUScu_Y5vYHObxDlOGEBqDvWbvqzL98@z> On Sun, Apr 26, 2020 at 06:34:30PM +0200, Hagen Paul Pfeifer wrote: > Working on a safety-critical stress testing tool, using ptrace in an > rather uncommon way (stop, peeking memory, ...) for a bunch of > applications in an automated way I realized that once opened processes > where restarted and PIDs recycled. Resulting in monitoring and > manipulating the wrong processes. > > With the advent of pidfd we are now able to stick with one stable handle > to identifying processes exactly. We now have the ability to get this > race free. Sending signals now works like a charm, next step is to > extend the functionality also for ptrace. > > API: > long pidfd_ptrace(int pidfd, enum __ptrace_request request, > void *addr, void *data, unsigned flags); I'm in general not opposed to this if there's a clear need for this and users that are interested. But I think if people really prefer having this a new syscall then we should probably try to improve on the old one. Things that come to mind right away without doing a deep review are replacing the void *addr pointer with a dedicated struct ptract_args or union ptrace_args and a size argument. If we're not doing something like this or something more fundamental we can equally well either just duplicate all enums in the old ptrace syscall and append a _PIDFD to it where it makes sense. Christian