Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3771022ybl; Fri, 20 Dec 2019 15:28:52 -0800 (PST) X-Google-Smtp-Source: APXvYqzIUBp3ga3H1eeidAUyHZ4E/M7cclyMdN3pw7ZrsqGbP3O3e6LDOyXiVoLG/DBBxehCCQz7 X-Received: by 2002:a9d:68ca:: with SMTP id i10mr17228059oto.178.1576884531998; Fri, 20 Dec 2019 15:28:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576884531; cv=none; d=google.com; s=arc-20160816; b=q51xcUlqIlqkhsbOyPiQ8VuoXze078OnGAjrNfH0umwKN8sj0UQZW3KvRHkMFX5gUK TMHaRouno6w8XlQ32ch16NqeChp8HxlIEXC6aDIK74ruMYrQNv48wN50Ztrcm4TrV8EZ h8l97AwdEiQMglrDe33BoR1eBZg1sX2v8+1v6NtK+yeCHNCIohVygksG/M5Yeer6eTfS LaLzS9LGswWToJOsExtP5QWr8HL96KVRn942SJPHTwtiUmltDlqp80DnyBqY8OOVvH8I 30o4mkACyHpcY+dlBqGrJzdzzRgA7OQaqcXmKlnWsEtHNsl3u7fe/R7ZpXHumCbvYEGY SO9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=ZUqxZgsASKzXQm2M4tklMIaw/3yZpJ0Kn5yfMnOfzzY=; b=fvBgpfu+bf8PrNoVUjwgAsHofFDych5V+gRBZ03JqDsDdov4JYxQMhKSUriVYwJswJ gCtkBRz0XXff2dgeDJpGP6TLTGrhdmbF9Aqz9J2l5F1IDGvVqqtXdHBCs/lKlczMPGHt CkJ1aCE/RIsQ9a5/Hs8NfTEa4/lKqcmCxuU+JPFPlTgfPkZ5PB3SW5QFhaxIsQXYpJIv lGchvyeqeiSG1SOQqqt8vz9zAJOwRlNqNl2+TpNECOSwPUkHqiciteVPQ2bkJwqEHY31 zM0J2A7Nt22BsKE7AqZh4cNej73fjjyDTpj0Cg/wbtHpLrZDC7hbIlE18jjyoBhR/bLi bIyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=ijOzIAtj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q66si5318223oig.65.2019.12.20.15.28.40; Fri, 20 Dec 2019 15:28:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=ijOzIAtj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726594AbfLTX1x (ORCPT + 99 others); Fri, 20 Dec 2019 18:27:53 -0500 Received: from mail-il1-f196.google.com ([209.85.166.196]:47097 "EHLO mail-il1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726492AbfLTX1x (ORCPT ); Fri, 20 Dec 2019 18:27:53 -0500 Received: by mail-il1-f196.google.com with SMTP id t17so9310301ilm.13 for ; Fri, 20 Dec 2019 15:27:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=ZUqxZgsASKzXQm2M4tklMIaw/3yZpJ0Kn5yfMnOfzzY=; b=ijOzIAtjctijgjeGKCJEIw69D+tQ8KJziesTnkjrghSsh26P9NishfxV+v33x4HzAN M2qWhV2qzQhj3ofKKWr/SoDVbHNHHWbRoxpD1ie5hIoH09+/g0LNokwv07dK11OPFruH /Um6LDMKgFwgPdDrMF/HBA7U6Y3RJ2/dpyCoo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=ZUqxZgsASKzXQm2M4tklMIaw/3yZpJ0Kn5yfMnOfzzY=; b=QiRpUAYepd4DxEzTXaSe3QRc1tbUmP1Vp7MzNDsynsdnTaG0gim/xp63AzW9ZEYnE+ xg1Tms3MCXTHASP+VV9Pvb62wXOp0FJKadn1dCrrCNmOy83jeEWJZQEvahoeVyg6PoG4 4lmqwvK/C/6cir4qfbIIhuZiPj6lB0CxmkooF4IWmx55zdCuKzoh1I3xJet/vTFicOB9 tI/NdM6WYpvp5e+EwJemTkq/cZrrUhAZ2unzXLk4p6iFmefh2nyrjcJGw8DO8yanB/Hf jWsvkFzTqDvzOA+gMqoZslzj6H+GecRk53sO/ZOXApeLLg/iNBg8NuDFNN7fhqHhcA8b U8Sg== X-Gm-Message-State: APjAAAWMyHN2t+BUqIRB7xpWLIxn3gTzhUnXYq9jA+hPXUY+b1pL6Ldo h2d7hAHUscQbmRwfxTR1i9LczAHqb6uQbg== X-Received: by 2002:a92:cb10:: with SMTP id s16mr14563659ilo.176.1576884471551; Fri, 20 Dec 2019 15:27:51 -0800 (PST) Received: from ircssh-2.c.rugged-nimbus-611.internal (80.60.198.104.bc.googleusercontent.com. [104.198.60.80]) by smtp.gmail.com with ESMTPSA id m90sm1462397ilh.56.2019.12.20.15.27.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Dec 2019 15:27:51 -0800 (PST) Date: Fri, 20 Dec 2019 23:27:49 +0000 From: Sargun Dhillon To: linux-kernel@vger.kernel.org, containers@lists.linux-foundation.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: tycho@tycho.ws, jannh@google.com, cyphar@cyphar.com, christian.brauner@ubuntu.com, oleg@redhat.com, luto@amacapital.net, viro@zeniv.linux.org.uk, gpascutto@mozilla.com, ealvarez@mozilla.com, fweimer@redhat.com, jld@mozilla.com, arnd@arndb.de Subject: [PATCH v5 0/3] Add pidfd_getfd syscall Message-ID: <20191220232746.GA20215@ircssh-2.c.rugged-nimbus-611.internal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patchset introduces a mechanism (pidfd_getfd syscall) to get file descriptors from other processes via pidfd. Although this can be achieved using SCM_RIGHTS, and parasitic code injection, this offers a more straightforward mechanism, with less overhead and complexity. The process under manipulation's fd still remains. It includes a model for extensibility, specifically to allow for future features around cgroup migration of sockets, and allowing for the fd to be taken (closing the fd in the process under manipulation). The syscall numbers were chosen to be one greater than openat2. Summary of history: This initially started as a ptrace command. It did not require the process to be stopped, and felt like kind of an awkward fit for ptrace. After that, it moved to an ioctl on the pidfd. Given functionality, it made sense to make it a syscall which did not require the process to be stopped. Changes since v4: * Turn into a syscall * Move to PTRACE_MODE_ATTACH_REALCREDS from PTRACE_MODE_READ_REALCREDS * Remove the sample code. This will come in another patchset, as the new self-tests cover all the functionality. Changes since v3: * Add self-test * Move to ioctl passing fd directly, versus args struct * Shuffle around include files Changes since v2: * Move to ioctl on pidfd instead of ptrace function * Add security check before moving file descriptor Changes since the RFC v1: * Introduce a new helper to fs/file.c to fetch a file descriptor from any process. It largely uses the code suggested by Oleg, with a few changes to fix locking * It uses an extensible options struct to supply the FD, and option. * I added a sample, using the code from the user-ptrace sample Sargun Dhillon (3): vfs, fdtable: Add get_task_file helper pid: Introduce pidfd_getfd syscall test: Add test for pidfd getfd MAINTAINERS | 1 + arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + fs/file.c | 22 +- include/linux/file.h | 2 + include/linux/syscalls.h | 4 + include/uapi/asm-generic/unistd.h | 3 +- include/uapi/linux/pidfd.h | 10 + kernel/pid.c | 115 ++++++++ tools/testing/selftests/pidfd/.gitignore | 1 + tools/testing/selftests/pidfd/Makefile | 2 +- .../selftests/pidfd/pidfd_getfd_test.c | 262 ++++++++++++++++++ 28 files changed, 437 insertions(+), 5 deletions(-) create mode 100644 include/uapi/linux/pidfd.h create mode 100644 tools/testing/selftests/pidfd/pidfd_getfd_test.c -- 2.20.1