Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2563511imu; Mon, 19 Nov 2018 02:34:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wzec9F6Ib2K936tw5H9X7LOmLgJK9fmRDeh+y0Jj0xTDEp7zUAQ1YGW6RXuD7xX2NHgzox X-Received: by 2002:a17:902:76c2:: with SMTP id j2mr4036936plt.339.1542623678977; Mon, 19 Nov 2018 02:34:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542623678; cv=none; d=google.com; s=arc-20160816; b=an8ZLstw+wwLfjCBOexNYHKd2e2HdlYzvg84q0DB7OwELUgwrQwFUGtTRtBJ439MvL 6t4pHvPw+0OEyteh/IKfPVQ80JQEh1BTUDuRe02r8i7h1wiNIor39d+8k1BegEutdDXh zB2SC1rm1wmycvw/tJPCW568lNtlhADwNOel53XaXk6kc8u5xD2rhtTbGsulyP1b7z9b A3hZxFfvByEHR7Q41cUpe3K76PV5017wjIb9kMIDw5JJOm9pb/Xha3xDvr+mAI5jOS4W iw0qE5M+E85yyXFO+lhDaYT6Tpqec38Xj2s3Ft2t/xm9BY80pZQ8koy6bcCELEZkJYMi r1JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=i48REQ5xKcodhlmnW4XayGlQL3igcgkvyoSrOEc6atA=; b=wVcQGDmepHWX4C0fajThI8yDtx8OduIbAzeOtt9oAJ+qNdOaUBXzbXsSaU06lz0Tud NHgcH+tq95o8VXXi9Hn2qq3VqYq//f2ToOi02uBEHzi8Tnd41o1paVbYwkT6oVIK3kNE wSBxjXGlSYhc8je2AZB3pHLqt2QCjYMwpfca/eMs2DFWkPGQeI4h8vBdqYV9Lc7inBYe /9UscHauZgyUySuAZwiQXm8S6BBSHqCKMYemVt4vuapRU8C7nwrTBoMhamnuC8zZZoq9 0Lhe7cxc+zOeGZ6oHGfvNymuy1oZBC5HZKz1rRGcM+jcmxftC0Sj3RZw3ZajdXXwFLKR XpBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=F0neg97F; 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 o12si8786066pgn.145.2018.11.19.02.34.24; Mon, 19 Nov 2018 02:34:38 -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=@brauner.io header.s=google header.b=F0neg97F; 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 S1727879AbeKSU4q (ORCPT + 99 others); Mon, 19 Nov 2018 15:56:46 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34013 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727489AbeKSU4q (ORCPT ); Mon, 19 Nov 2018 15:56:46 -0500 Received: by mail-pl1-f195.google.com with SMTP id f12-v6so14409486plo.1 for ; Mon, 19 Nov 2018 02:33:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=i48REQ5xKcodhlmnW4XayGlQL3igcgkvyoSrOEc6atA=; b=F0neg97FwpmlJyDksyvozPh12H5rx3FrpdGz/ml4bg3rCrowQcKuS86kO0ctRgre1J xGIyy2FBfUtyVISppzCv5ZjgJOSHJ6e0M7Bvj5+8p0Kqc6M9aQR/BV630gDv0dcHsXYW DBu6PtPPb30HHLzwFwAHF3peu4ejVtRFEdmorK+5E+L1sBkX4Vf9N7yOrkeK9sWHRTOk miHpFk8qNTHRXX2sA5ePLBA1jAYCcVDin5aMmviW9zTb0/pMBCJx5+fj27bd92VYLo7s /+T0EfmCJHbqHuqQKEoU1FlSPfyefVsPfXR/CZRCIfwrOpMs4v82ZF1eeIUVZNsjZl23 c8Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=i48REQ5xKcodhlmnW4XayGlQL3igcgkvyoSrOEc6atA=; b=t6ljBCYY7qYx7vAeC7+mrNHEItabCl53rXaTFom3JdsRM4jjmpKo6TtuaG5dBxoKqk nMDjZpW0v9uP1Ph0Krz9Utx3OTN2AEThM2dTcM9dAs5BdM8+2RxUYov6Zac3Oqkor/NC 6K5806kzLQolKliEavvhehBwihfUu7sg3QBkKDUdWVaM7HJ8CQbgmVKsvMCe65mCSlaX bYJDz0fWEKdkUL2URGFMdgNefN/kgBUSO1YnQYjpJjddlI05q0UErOQwUtuJ5DA2s66u Kg9zEbOfEFERmw9YYq/qs4Xk07D41eDKpNYl5aSRVybv/wXc5pPrd3h50A73Ot2zYeUW j0zQ== X-Gm-Message-State: AGRZ1gJrrdzpWqzDqLUlsPD1yEOIpfjrLSlX41eylm6Vn2gV/7qtHuEF d5KxhcPIo0eAMEsD06j4EPTN6g== X-Received: by 2002:a17:902:d03:: with SMTP id 3-v6mr19784571plu.66.1542623613071; Mon, 19 Nov 2018 02:33:33 -0800 (PST) Received: from localhost.localdomain ([2404:4404:133a:4500:9d11:de0b:446c:8485]) by smtp.gmail.com with ESMTPSA id d21sm32958139pgv.37.2018.11.19.02.33.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 02:33:32 -0800 (PST) From: Christian Brauner To: ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: serge@hallyn.com, jannh@google.com, luto@kernel.org, akpm@linux-foundation.org, oleg@redhat.com, cyphar@cyphar.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, dancol@google.com, timmurray@google.com, linux-man@vger.kernel.org, Christian Brauner Subject: [PATCH v1 0/2] proc: allow signaling processes via file descriptors Date: Mon, 19 Nov 2018 11:32:37 +0100 Message-Id: <20181119103241.5229-1-christian@brauner.io> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hey, This little series introduces the ability to signal processes via file descriptors to eliminate race-conditions caused by pid recycling. With this patch an open() call on /proc/ will give userspace a handle to struct pid of the process associated with /proc/. This allows to maintain a stable handle on a process. Discussion has shown that a dedicated syscall is prefered over an ioctl(). Thus, the new syscall procfd_signal() is introduced to solve this problem. It operates on a process file descriptor. More details are found in the individual commit messages. With this series a process can be killed via: #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { int ret; char buf[1000]; if (argc < 2) exit(EXIT_FAILURE); ret = snprintf(buf, sizeof(buf), "/proc/%s", argv[1]); if (ret < 0) exit(EXIT_FAILURE); int fd = open(buf, O_DIRECTORY | O_CLOEXEC); if (fd < 0) { printf("%s - Failed to open \"%s\"\n", strerror(errno), buf); exit(EXIT_FAILURE); } ret = syscall(__NR_procfd_signal, fd, SIGKILL, NULL, 0); if (ret < 0) { printf("Failed to send SIGKILL \"%s\"\n", strerror(errno)); close(fd); exit(EXIT_FAILURE); } close(fd); exit(EXIT_SUCCESS); } Thanks! Christian Christian Brauner (2): proc: get process file descriptor from /proc/ signal: add procfd_signal() syscall procfd_signal.2: document procfd_signal syscall arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + fs/proc/base.c | 23 ++++++++ include/linux/proc_fs.h | 1 + include/linux/syscalls.h | 2 + kernel/signal.c | 76 ++++++++++++++++++++++++-- 6 files changed, 98 insertions(+), 6 deletions(-) -- 2.19.1