From patchwork Thu Oct 10 18:15:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13830653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCF87CFC5EB for ; Thu, 10 Oct 2024 18:16:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A94E6B0093; Thu, 10 Oct 2024 14:16:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 532D36B0095; Thu, 10 Oct 2024 14:16:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E88A6B0096; Thu, 10 Oct 2024 14:16:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 040026B0093 for ; Thu, 10 Oct 2024 14:16:12 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4811B1A0C77 for ; Thu, 10 Oct 2024 18:16:06 +0000 (UTC) X-FDA: 82658496984.06.62BCDE7 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf15.hostedemail.com (Postfix) with ESMTP id B26F7A000D for ; Thu, 10 Oct 2024 18:16:07 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=nCa1iDt0; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=kACLuJiy; spf=pass (imf15.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1728584098; a=rsa-sha256; cv=pass; b=vKiwWmXIXIQWl+/PmBHI32srSbGgT1xq90ONaGO2mrveG5k4CZNTSANO3po3JPu4QAgvVu VGNLWKj+t9C388Z2Xc/M9eZ2msWSW/p+yEGFetq16NYqOXSafAcmlO72QUYB7lVzCU2AKz d9x3+suIPvzyJ6ludq4W9OMO2lvCBe8= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=nCa1iDt0; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=kACLuJiy; spf=pass (imf15.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728584098; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YGsMJ89EHfHWpqvg+1cE2NG8PMFwvAfUZSszICkBT4E=; b=Ip0Ok44haHkXqnOD3YZEIIVFMZ1kvfwclyWj3nwCuJE+MmJmSaxE68xPoUjeueI0eocIKQ pPuxxQdip3UtdVhbTRGh4/okdpe7t1OgIxWL/EctLXZhGxeu1xjDDabxTzD0H1aKt3DOsT 731PaiQvvBrU8uUsG5HLzvR7/bqZRyA= Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49AHtdrn013529; Thu, 10 Oct 2024 18:16:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=YGsMJ89EHfHWpqvg+1cE2NG8PMFwvAfUZSszICkBT4E=; b= nCa1iDt00ID9Pk6RcM3uIjqztm7WKbGNTs1fyBCmKVL1d4DqsVq6vW/Y1MZ10gNc PpwzCi5rB/oVCy95vcRSoAi53gHZ5+ms3pCQBLKJcD2h8qmQ7iFGp8YKbHqOi5v2 pqszFuGDrcMLDtyAXh7JWJMZs1Ysoajprmjn78tf4j/b9CoTSAKKlbdISpnRaiVP pJCFcdzuGP6jcba2armVunLYH6t6GK3nRBjAWdO7FpIHbfcKPV/EFzpBuCqhXlVj MFzu2cDeWBbE1VNNJnOTMITElWCwdZ3WfAdRePU+NnYTO2M/Z1mnzehOl5Odb2qk +C/zmXsANqQ2kAQJXP7WBw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42302pk8p0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Oct 2024 18:15:59 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49AHG4jN017547; Thu, 10 Oct 2024 18:15:58 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2049.outbound.protection.outlook.com [104.47.58.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 422uwag77j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Oct 2024 18:15:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SzYDtgO6EHiM3MCh2cEF+Mj10F0QwKkBWq3clH0da5o8uA5jHDBtPgWjh1ljuLAxxw4O+1ySU8Xu+JEDwp1IGKOny0JGCHoVpXwEcxfBGIzIX2Ie5fm1XTmmkS8YMjsFXm6Nm4iiejyIIx+QcHLWpyDztuQPTWBl27DLPYhHJtcIGr9neEEvbjMAwKlkezqBOk5hJQqyTgdF21jb24QPPpk2r1eBrr/BeZ93CHI51gxvRt0Gwu6VvKQr8aQUPHPeKpC+hzn/deYJ2NPqT8lWUNzC9abh4Uoz0jsW/ru9mKVvBH6a3H6MVSHaSP+DrmfOg2sv9+xb+a9G/uYTJ0UG1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YGsMJ89EHfHWpqvg+1cE2NG8PMFwvAfUZSszICkBT4E=; b=EXtp675OxYiYK2+MvCcvhanuAdlUmuRLj+nq646/lUXM6sr3hM78r0NFrHXlnhTbHU1bQkfqOR7ZNH3nWRm+kcUrnSvGgj479FC8SXTCZz9BYnNmUu4rG9dKpQi4ua1ExV71aQ7YVslQ+V075IAY7WPZq+xk7CR+b7Z3zzkaAklJNsAZ89KKc8HXqLlFQfagmISSn9p/DEWxcqRHiMZOHmE+O2ANBRvaX16whpdxgkcIqse3z0spj02THmXdU8dQ15zYR4RsKyOet0KuKa+s0Kq1xktDwQrdX11k+NWpE9bBzY0TAp2UrLyxdTgh4w0fSaBZXtdFTwfvhVIAE091Dg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YGsMJ89EHfHWpqvg+1cE2NG8PMFwvAfUZSszICkBT4E=; b=kACLuJiyJ/8bJR1+CZ7Lvur9Wbg5UmWtRUpOp7fCDxEhqy9+IKu2Z9LmI9WglqO4LttK7MjVE0ZaTVf8KWeV8uWqhvvwdU8rEGjPvsxz2JT1SNomMPWHW1pPLL8E8ZCEL7G/w342cBTK5KoOjWUBJo2UXnO2FigomAuhNIvUIFY= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7826.namprd10.prod.outlook.com (2603:10b6:a03:56b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Thu, 10 Oct 2024 18:15:54 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.8048.017; Thu, 10 Oct 2024 18:15:54 +0000 From: Lorenzo Stoakes To: Christian Brauner Cc: Shuah Khan , "Liam R . Howlett" , Suren Baghdasaryan , Vlastimil Babka , pedro.falcato@gmail.com, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] pidfd: add PIDFD_SELF* sentinels to refer to own thread/process Date: Thu, 10 Oct 2024 19:15:44 +0100 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0429.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a0::33) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|SJ2PR10MB7826:EE_ X-MS-Office365-Filtering-Correlation-Id: 5dd2b124-fd38-4ebc-9c53-08dce9579480 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: W8qwq3le7UrSvLX0QzEHM1cAw0GuLIOSrMReslPJPAkPSrEw+XsFfOE2Vk2ssb7bvXcDWAkZmFQvASf1k66p/XL5K+gpoIWscZFRBO3sE/DUdiG+BRS156qs8yGFYOoPXfSeQjJsYUqvWvbeVZZH4XXvfMTHm1hPUHAq1i2EF5748dlznQu5WF6/HRXNrU0BnemuB9BTKR9+nOlHz6tttyzX/0oxj2DmnmvKAYPFNzvxJk9mkmezMVs7ZxV6O+JKLX904Aab10oTV+bNEJwyZTgcHqDxFCPTUfdauuTBA/yejh4r2WVG39Jxs5QXBlgzaYSs0c7Aj83rgF5phR3+eTzkIWKq5HWhinBQch03OoWWPlxb/MdUXvy1Sb4YFCUmJwm+2QJwTeb0w2s+XPWzEjNEkYWdZUSTx4h0JqY93BTXcHYlyWctAJZD6x72i7ceBtxz92Ij+wgmveH4iRAaknyeZFc2mBIw9Ithnb2yf8JiS4AqohbYYQB2DkKYj7K5tK+6/LlaxEnE7sQ7eDzpnZxNGACF1PjjSywRrzDJ3YCvIhnsE/7j4eR0XYn6lYitL4VOXm72LEC34SJRJIQxHctREWH9xLA/QRUmWZSSchljOtqEfSqDlm6CIZDK95EdAEVryGJyb5LmrUCeEBO498qQPZl8DhyGdZVAmuXRVJygxCK2PnJuqDyjoGekOAx6JZ0T2x2RChL9zCfjST6jp7txANAnPoexiwNGL53b7ho7AnOlPmXwuv4G9VVIgD/FOIwSWsGONfehRvat3YvIIENrsU4kYjwYLl6uvoghYWAB+zZfqTIISBBI+z5v/+O3Jx0p6SDP7Q9nYtWThsvwk0/iFeJVf6g5sRbuHfROjwM5UQt/7/5X+xhdBFCWHKPd4djdYGG/HX39qn3npDTfwiSj9ipWALc02WWPxbqKEObGNok4z9aXJ06eTbtbcYfErHdHE80WDSH8id7W05avVErrrHTuXP/ZcJMkhWi0VrdeUBIOhRTS2v1ia1g9GcYxb/nq5ShW1xFR3dCMzqX7nzHSLPRtHaNQauTCr+S+6DJOTFcIYQoMCqe3kSdV6giD4GoljKpLjU7csk9JraJJuFh0/64AN+6XjYr7UzPajqsd3zu/HeHfrYW5TH4j91epv1G//MSFOCkCnPYDGbZUiBnmMdszpB//GRokb6gxIm6u7PL6ad8U/HvYs8J7PbIJs5TpMD1BgQ+tCtQNFtRvC8UIBmOuAhXPfyLShGwGG/pSUM5sxPS/uwlFlbwHMb7Okt/JzGT9I8NxYdwWA7Tm/A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9QBkI1JOPkgWpBT3phKOtQmV46Dl2P6/S3TuWeiShC0gtrGiTPaihfB/uVyldJLXW0XZDITuW8ALgLev5cAHNVyEQerAjSNTBfGt+HJfWY74HDeTnK2iI0PA3SDyNGBjQxqWja0PMipv6CkaH9+e8OP3C+8RXI6v3V53laJyWKe2H0yFSgF52f5q9dRC0ePJnScVSBu3yQGzMkrKXRkq5eJRFK9cREuMAiJtGAvV5l/7AQthNvAiPFzxHONHnag+wVxIQE2VwC60b0Veu6hEceJBbLx4wrCe6RnkQFpE4GaFlaphRd87cOrJKYNGaIyr6gnY7fnNd19xxAkEwnxKK9wxe2p6Wn96zDqYbWQjGcNUelHw+yYajLkjX1/7scn58kzz4xPiMbUt/KFfrzZ8zdhVrG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dphWAi50IR09+X1KajylRbUIKxtiYEexowseQgNhW1UvRjFDs6ULXU+F6jsFPsDF1BE3BWRuuXGDkHQ8zW57GeBOYLk71EofVLauWZEngDiNPyAbmXa61i4s6nwQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: NsBZ1Hicglu18lL2jXMniK0Jij6xlgW6bGcgXr5VF4elH4FaOULpYh0STR2jbU09vNuEV1dBHZBNlogL4q9neU8UcvkfNX8VetFNiFsPdFJRbhz5kiIIy2IFMpB/tW/2i+BVMjrAY6YH9tN5LpgrWZfjTpJb6YoIIb6VYBbjxVYmZQEN+aSbFXcpm+L2C2bdVU42k+td2yJoqWQItpwU5fnZOp3cAMy4fvwZKYqhkTTx/asnzqxBARMYsB1u0AUbAsLl2ANVkWaa0zkczmhtJw0nd3zeTcq5f9tvOdf7qVNBeNxdm++Df4gJSXDP1imnFSkEnvFVh+MSol6PnsX4R1ZDv65o8mSr02Ive5qFO9ui8iF8qXToh43NDY1tioEohUQkviUOSPLCECh2LVvAxPIi7Z7UKZIFLJT64WDwGbWoXMugFafzu6BAgWL92vKid0SleyC9siRxJ6Dn+Y8xuXXnMhJMGXFO/+wIqRWsTSX/qUvNqf8JIuTCS7burFi0RI0cHe6ymmG/MEgE1kaWcqBgwWhzegwU7m68VrJPigrGPPgiod51RuI0gBPlHhCq324L/+VuQGm07EO404Xsla7Cuzd9BytE6WY5VA5/DL8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5dd2b124-fd38-4ebc-9c53-08dce9579480 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 18:15:54.5317 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zF1BACghZQQQOX9ERbKM9aSQzLl+yrQIy1YRrhVd6C64EXa7I1txuUgmhLJi7mZQckmoqo8Yb9FfpzGbKTuC6B6ITRalBNVyeFhjriESi5o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7826 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-10_13,2024-10-10_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 adultscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410100120 X-Proofpoint-ORIG-GUID: frTi7iFCRY5pC-kfceov9tqY0sywy46C X-Proofpoint-GUID: frTi7iFCRY5pC-kfceov9tqY0sywy46C X-Stat-Signature: rzqpb4kc1cqbwbchpe6e8ik9beg9soqm X-Rspamd-Queue-Id: B26F7A000D X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1728584167-710356 X-HE-Meta: U2FsdGVkX18DZmMG54NmuTWDeQqBITSw2Vtwdmoi1fFQAcGq+94W6V5XYdOBtsIhX8/oJT7tYx+0iKRHTZmZ0XVUVAXwMsjzgkNAFlYnEhvJVI4CQvGTjw5J5LWGSbvd59ax3RmbSHDgHRmQMfP9tmyWsH8vOHUzMkCgzBPBLPWsSe2dTKAtwLM0Z/xa4YChjakdpgCuNHg+aun3AmmQa4JnzyxoWJ3Ogp9C0zvi1vuqC+JR1g9k+kqC2/Zi4QxsIO6fLOol1j3zIGC0pwmL58C5tth+hCBUM2PTPjDAnG/57hal87E8KgzJmi4riEWxf9R0YHQLhxxpCN9gBwohUmxkj5iWpqFXy6cPaBSwS1kNxwsB8nZlYSWtT74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+pW5ldPTXMnOMoE5OnFL3OHUqVpWnWe5f2U8InKKWHkHktGbsxNjWQ5xJE9H6RPyUUe/AKxAx0nk/bdfIizlaEspm2DTgS88ycsD0TtMk0i8uIIcWbfBbCKzZRALNr27PYQvnCyALCP1XAPcU+rr6ThwpZmcje/a2bLgV9cl31zGcJCfMhz0Y6xnqGFXAgZaC1F0I6o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: It is useful to be able to utilise pidfd mechanisms to reference the current thread or process (from a userland point of view - thread group leader from the kernel's point of view). Therefore introduce PIDFD_SELF_THREAD to refer to the current thread, and PIDFD_SELF_THREAD_GROUP to refer to the current thread group leader. For convenience and to avoid confusion from userland's perspective we alias these: * PIDFD_SELF is an alias for PIDFD_SELF_THREAD - This is nearly always what the user will want to use, as they would find it surprising if for instance fd's were unshared()'d and they wanted to invoke pidfd_getfd() and that failed. * PIDFD_SELF_PROCESS is an alias for PIDFD_SELF_THREAD_GROUP - Most users have no concept of thread groups or what a thread group leader is, and from userland's perspective and nomenclature this is what userland considers to be a process. Due to the refactoring of the central __pidfd_get_pid() function we can implement this functionality centrally, providing the use of this sentinel in most functionality which utilises pidfd's. We need to explicitly adjust kernel_waitid_prepare() to permit this (though it wouldn't really make sense to use this there, we provide the ability for consistency). We explicitly disallow use of this in setns(), which would otherwise have required explicit custom handling, as it doesn't make sense to set the current calling thread to join the namespace of itself. As the callers of pidfd_get_pid() expect an increased reference count on the pid we do so in the self case, reducing churn and avoiding any breakage from existing logic which decrements this reference count. In the pidfd_send_signal() system call, we can continue to fdput() the struct fd output by pidfs_to_pid_proc() even if PIDFD_SELF* is specified, as this will be empty and the invocation will be a no-op. This change implicitly provides PIDFD_SELF* support in the waitid(P_PIDFS, ...), process_madvise(), process_mrelease(), pidfd_send_signal(), and pidfd_getfd() system calls. Things such as polling a pidfs and general fd operations are not supported, this strictly provides the sentinel for APIs which explicitly accept a pidfd. Signed-off-by: Lorenzo Stoakes --- include/linux/pid.h | 9 +++--- include/uapi/linux/pidfd.h | 15 +++++++++ kernel/exit.c | 3 +- kernel/nsproxy.c | 1 + kernel/pid.c | 65 +++++++++++++++++++++++--------------- 5 files changed, 62 insertions(+), 31 deletions(-) -- 2.46.2 diff --git a/include/linux/pid.h b/include/linux/pid.h index 68b02eab7509..7c9ed1b5d16f 100644 --- a/include/linux/pid.h +++ b/include/linux/pid.h @@ -77,18 +77,19 @@ struct file; /** * __pidfd_get_pid() - Retrieve a pid associated with the specified pidfd. * - * @pidfd: The pidfd whose pid we want, or the fd of a /proc/ file if - * @alloc_proc is also set. + * @pidfd: The pidfd whose pid we want, the fd of a /proc/ file if + * @alloc_proc is also set, or PIDFD_SELF_* to refer to the current + * thread or thread group leader. * @pin_pid: If set, then the reference counter of the returned pid is * incremented. If not set, then @fd should be provided to pin the * pidfd. * @allow_proc: If set, then an fd of a /proc/ file can be passed instead * of a pidfd, and this will be used to determine the pid. * @flags: Output variable, if non-NULL, then the file->f_flags of the - * pidfd will be set here. + * pidfd will be set here. If PIDFD_SELF_* set, this is zero. * @fd: Output variable, if non-NULL, then the pidfd reference will * remain elevated and the caller will need to decrement it - * themselves. + * themselves. If PIDFD_SELF_* set, this is empty. * * Returns: If successful, the pid associated with the pidfd, otherwise an * error. diff --git a/include/uapi/linux/pidfd.h b/include/uapi/linux/pidfd.h index 565fc0629fff..f4db20d76f4b 100644 --- a/include/uapi/linux/pidfd.h +++ b/include/uapi/linux/pidfd.h @@ -29,4 +29,19 @@ #define PIDFD_GET_USER_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 9) #define PIDFD_GET_UTS_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 10) +/* + * Special sentinel values which can be used to refer to the current thread or + * thread group leader (which from a userland perspective is the process). + */ +#define PIDFD_SELF PIDFD_SELF_THREAD +#define PIDFD_SELF_PROCESS PIDFD_SELF_THREAD_GROUP + +#define PIDFD_SELF_THREAD -100 /* Current thread. */ +#define PIDFD_SELF_THREAD_GROUP -200 /* Current thread group leader. */ + +static inline bool pidfd_is_self_sentinel(pid_t pid) +{ + return pid == PIDFD_SELF_THREAD || pid == PIDFD_SELF_THREAD_GROUP; +} + #endif /* _UAPI_LINUX_PIDFD_H */ diff --git a/kernel/exit.c b/kernel/exit.c index 619f0014c33b..3eb20f8252ee 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -71,6 +71,7 @@ #include #include +#include #include #include @@ -1739,7 +1740,7 @@ int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid, break; case P_PIDFD: type = PIDTYPE_PID; - if (upid < 0) + if (upid < 0 && !pidfd_is_self_sentinel(upid)) return -EINVAL; pid = pidfd_get_pid(upid, &f_flags); diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index dc952c3b05af..d239f7eeaa1f 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c @@ -550,6 +550,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags) struct nsset nsset = {}; int err = 0; + /* If fd is PIDFD_SELF_*, implicitly fail here, as invalid. */ if (!fd_file(f)) return -EBADF; diff --git a/kernel/pid.c b/kernel/pid.c index 25cc1c36a1b1..0f8943ecc471 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -539,22 +539,31 @@ struct pid *__pidfd_get_pid(unsigned int pidfd, bool pin_pid, bool allow_proc, unsigned int *flags, struct fd *fd) { - struct file *file; + struct file *file = NULL; struct pid *pid; - struct fd f = fdget(pidfd); - - file = fd_file(f); - if (!file) - return ERR_PTR(-EBADF); - - pid = pidfd_pid(file); - /* If we allow opening a pidfd via /proc/, do so. */ - if (IS_ERR(pid) && allow_proc) - pid = tgid_pidfd_to_pid(file); - - if (IS_ERR(pid)) { - fdput(f); - return pid; + unsigned int f_flags = 0; + struct fd f = {}; + + if (pidfd == PIDFD_SELF_THREAD) { + pid = *task_pid_ptr(current, PIDTYPE_PID); + f_flags = PIDFD_THREAD; + } else if (pidfd == PIDFD_SELF_THREAD_GROUP) { + pid = *task_pid_ptr(current, PIDTYPE_TGID); + } else { + f = fdget(pidfd); + file = fd_file(f); + if (!file) + return ERR_PTR(-EBADF); + + pid = pidfd_pid(file); + /* If we allow opening a pidfd via /proc/, do so. */ + if (IS_ERR(pid) && allow_proc) + pid = tgid_pidfd_to_pid(file); + + if (IS_ERR(pid)) { + fdput(f); + return pid; + } } if (pin_pid) @@ -562,18 +571,22 @@ struct pid *__pidfd_get_pid(unsigned int pidfd, bool pin_pid, else WARN_ON_ONCE(!fd); /* Nothing to keep pid/pidfd around? */ - if (flags) - *flags = file->f_flags; + if (file) { + f_flags = file->f_flags; - /* - * If the user provides an fd output then it will handle decrementing - * its reference counter. - */ - if (fd) - *fd = f; - else - /* Otherwise we release it. */ - fdput(f); + /* + * If the user provides an fd output then it will handle decrementing + * its reference counter. + */ + if (fd) + *fd = f; + else + /* Otherwise we release it. */ + fdput(f); + } + + if (flags) + *flags = f_flags; return pid; }