Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3154583ybz; Mon, 27 Apr 2020 10:57:20 -0700 (PDT) X-Google-Smtp-Source: APiQypLv7IfVStx3c9rOSg4rZSUFylAXsDWb/HHpLdPILjTp3tLhHaBsMxMWbpC3I8HkkQRbDE1F X-Received: by 2002:a17:906:90cc:: with SMTP id v12mr21122984ejw.211.1588010239890; Mon, 27 Apr 2020 10:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588010239; cv=none; d=google.com; s=arc-20160816; b=wNwV5Hf0S1w1yvUbyi03qPZsvoVNvfVfuLzfvQw73IS1yGnIOqT0tJFGJTPqMeZ8UQ JqHSFB6UPbDqnrnVSTA6RagNSHRC/7APX277vtsvm59rwb/Pv/2wkXGqtRwSHFKeDiGj P6nlFc69+gsahpShCXkopBg4CCHMbsTjPHbv3YcnhAtRNS3m2hOmv9GacD5vYWneBNGL cYWoaUQpR4yJfef9jlprnyhhnNJhEH0r/kWT0YynsEZd7GE/aErAkPTkkKWeAxXlxfEX aPt5+pNlhVUHcRV9Xnr3/C8PP6nlcAes2svp68S6vm+ER/ppYrLFMVJnBkdqNrrJWYGa xaxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QgX2UlkPShntWDyuJpzvmZjjIQUfcagM19kKDn9F6wE=; b=Sh6rUxyq0eAcxJRpjXcgWGbpqjO+DqFOe5+zTDtflNnkBh1Ds2bWeGzN2EOUes8TPS 22leZfYMKkTyOmZdREIL7aq2CWvgFm55AhTOU3r9S9xqYZOIFDrjaZNjg7ev1VyTCci/ SdLpEysMeggbroE5OqZ/ztAZsnPadcYiFvywpVueXR5ljrINgrYuVJiPdFAU81JXJW7Z 5fK+PgScGF2CMqXDRWjx4zXUpsreBZ7aj3Bjii1zeWqJtb7WgidtcXJqMMk3Akmj2nZt ekoaigTjplwpTQQXzomL/x3OctzTqmjHTMSArttsXCDRo54qQsQoaODlNlgXO/tipgq8 MGkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Dz0+iV/t"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o22si192166ejh.233.2020.04.27.10.56.55; Mon, 27 Apr 2020 10:57:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Dz0+iV/t"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726344AbgD0RxP (ORCPT + 99 others); Mon, 27 Apr 2020 13:53:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726223AbgD0RxO (ORCPT ); Mon, 27 Apr 2020 13:53:14 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B83C0610D5 for ; Mon, 27 Apr 2020 10:53:14 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id r17so14604303lff.2 for ; Mon, 27 Apr 2020 10:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QgX2UlkPShntWDyuJpzvmZjjIQUfcagM19kKDn9F6wE=; b=Dz0+iV/t1KqOhDyK8EACleXuaC/vjXfE1GO0GBbVnqrRsUa80DP/dAv2adRGhBR6lk Gtfme/Ltdzg9pa5fyKx56wosVSu05n/9fhuacV+55wUjiAG2q8Zh57oWm7m+MfyhTiik R5drk7ygprRSpnuoep7YKEZq+P/7K9unwsYjSlignb2OiZ1mCdV63zXO1+Ky4rew12qM ldAk+8skqB2yaciEVy8GPzlkDPk9+SkvOKeWdPa50NWvYa6M8Mv4RdRRXedkT5JIpXz3 TRC3ISyczWILl/Mtw3LbLzelmcVBzcGRm8NhXEKkWv2gCdJ2Phv9wFYqYPJak4AwmMeZ 5EiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QgX2UlkPShntWDyuJpzvmZjjIQUfcagM19kKDn9F6wE=; b=gd8YGs48cFf+eajoLyToolvZlKj4w9qJHhi2Lj6PDgVIzVsCaKwygM4CBT1v2tVYAK M7gRfnCBPfK8VesF3N/FEFoF3S77yB/bakjs+8GkRvhB0pm3jX8wKA5BxfLPiz3aCkJ3 wSaFHwravavXV1bm62Ogc8WiiVTeq7uqdUyej5QNG2BflsGvMXWXI1rl0athLQZ+cB18 MwMdAOzwyN+ckxIYjENINfbX0GovXMriEvo1OSoWA7K+wJwN3m63hACLmCCL4Di/9FN8 BE1XTKT/EX6ZQJaHL1E69OmTP6KimGcOqMrQXW1R3nrEWNHBQxFI2k9bKUlNcJef7gvx 5z3g== X-Gm-Message-State: AGi0Puawq4MQoPgxWGPphoPFSt7/23AehMcMOYwyAYJ0LQviTCGB3BIV J5FV30MiT0BKxD50f52wcI87Tr6FWzY1zKWIgfOVZw== X-Received: by 2002:a19:e04a:: with SMTP id g10mr16042699lfj.164.1588009992307; Mon, 27 Apr 2020 10:53:12 -0700 (PDT) MIME-Version: 1.0 References: <20200426130100.306246-1-hagen@jauu.net> <20200426163430.22743-1-hagen@jauu.net> <20200427170826.mdklazcrn4xaeafm@wittgenstein> In-Reply-To: <20200427170826.mdklazcrn4xaeafm@wittgenstein> From: Jann Horn Date: Mon, 27 Apr 2020 19:52:45 +0200 Message-ID: Subject: Re: [RFC v2] ptrace, pidfd: add pidfd_ptrace syscall To: Christian Brauner Cc: Hagen Paul Pfeifer , kernel list , 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 , linux-arch Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 27, 2020 at 7:08 PM Christian Brauner wrote: > 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. Yeah, it seems like just adding pidfd flavors of PTRACE_ATTACH and PTRACE_SEIZE should do the job. And if we do make a new syscall, there is a bunch of de-crufting that can be done... for example, just as some low-hanging fruit, a new ptrace API probably shouldn't have PTRACE_PEEKTEXT/PTRACE_PEEKDATA/PTRACE_POKETEXT/PTRACE_POKEDATA (we have /proc/$pid/mem for that, which is much saner than doing peek/poke in word-size units), and probably also shouldn't support all the weird arch-specific register-accessing requests (e.g. PTRACE_PEEKUSR/PTRACE_POKEUSR/PTRACE_GETREGS/PTRACE_SETREGS/PTRACE_GETFPREGS/...) that are nowadays accessible via PTRACE_GETREGSET/PTRACE_SETREGSET. (And there are also some more major changes that I think would be sensible; for example, it'd be neat if you could have notifications about the tracee delivered through a pollable file descriptor, and if you could get the kernel to tell you in each notification which type of ptrace stop you're dealing with (e.g. distinguishing syscall-entry-stop vs syscall-exit-stop), and it would be great to be able to directly inject syscalls into the child instead of having to figure out where a syscall instruction you can abuse is and then setting the instruction pointer to that, and it'd be helpful to be able to have multiple tracers attached to a single process so that you can e.g. have strace and gdb active on the same process concurrently...)