From patchwork Fri Oct 11 11:05:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13832513 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 46870CFD378 for ; Fri, 11 Oct 2024 12:25:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88ED66B00AD; Fri, 11 Oct 2024 08:25:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 819116B00AE; Fri, 11 Oct 2024 08:25:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CDC66B00B0; Fri, 11 Oct 2024 08:25:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 336976B00AD for ; Fri, 11 Oct 2024 08:25:44 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 34CB9C0DA5 for ; Fri, 11 Oct 2024 12:25:38 +0000 (UTC) X-FDA: 82661242482.10.3DF1429 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf22.hostedemail.com (Postfix) with ESMTP id DF62EC0013 for ; Fri, 11 Oct 2024 12:25:36 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=TXv4qsVF; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lCKfbcZ4; spf=pass (imf22.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=1728649356; 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=DQXBsOR2E19Q2CMf9E95TjmQXv+9t0EfWPaUCkT1KJk=; b=LSJx0+d1/uK4aX8HoyejhvZUKZhuObbHCAbQNrwW3AoaB+XxK6EffaiO6qm0g2551XzTdX Z3XWGWhyQTlGNBHjNHASxPD8WhJU+pwgIJQmKE3fZ7N6t9hhJY2cVSS4EnIpbTMJNxz8gQ aZy4mI4t/CQ1A98KO37SBQj8ccaVNXY= ARC-Authentication-Results: i=2; imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=TXv4qsVF; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lCKfbcZ4; spf=pass (imf22.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=1728649356; a=rsa-sha256; cv=pass; b=hkckI+Kh0zvW3X8b/+DhYe0I/rzi+/yWj7xJh8s2436l4XPmUX6IrI3IK8q9m16sguOCDS EDIlN4khRX9aryEVj0Rak6itC2V3nJs1XQoCFJXfTEebgh9sk+/fqsWKImLkPZ4JPy2xf1 LG4x00T0w3HiRpfay/GUN1/DcE634Ss= 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 49B8BfAl006316; Fri, 11 Oct 2024 11:06:10 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=DQXBsOR2E19Q2CMf9E95TjmQXv+9t0EfWPaUCkT1KJk=; b= TXv4qsVF+ujZ0t1Av1RWl44phnlq8CevmeGNsfaP/ZfryV/pQu1t7iFxNtkn7Zzm WDM3CVpbj7x1q/zwkDcuFcWqtYBSPyMPyvLXwACjOonf+NinWvGroYbz0fg2UZgd qqAIga0BLuW5KDeyDOqK2vEx5vdLwXL3wDJ8GfuZlbAt/RMXI7LoPWsFZ9EvZXjw 6g90JJgrteuz7x2VfTYh9C59TBMGgIZisJu9lgNS6+S8sQtDE0MAlx9/BpjVwJqH 7lWU0u0/lR9bLNEDrdMplNmSXRxvulR4G7eXtCHm3JSMsWF1Zutkl3GnNIbSH4S2 mG+ul+e+wHF3xjYdG4DXTQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42302pmep1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 11:06:09 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49B8so8T033321; Fri, 11 Oct 2024 11:06:09 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 422uwb648y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 11:06:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ODKo7apHZo7LKizVKpjZMLJLoO8/sA+aw6QN2JcDQ7Jk133L/yZ+7cg1oWGfoMHKLXZHaJlZAEcyb7oRpkWA8FY/JXZVsDV+oPmzcFCdd5i65aEWmc5mwt6TZJPw1dQrIwrwAahpD0sn/odO4bK4hhaexdNeZeP2Il2+HoO4Ffr9WWMV10i3cpu4Jf7Ukg1wuRdJYL4s+1PEukgkbxbF1G5Pnn4JjnJReam31QoFgTV6DlISSvn76hQTZfOvy/GKw5JHMOQ8ZVIgw52ysTalqx+sz4lkL2efqytchAaztwGg1uxyUyBZQ6lAuxeA5gbMN3/8u4x0gKBme/WvjI27KQ== 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=DQXBsOR2E19Q2CMf9E95TjmQXv+9t0EfWPaUCkT1KJk=; b=lJ6cNE6d69xligD+8Y+W5bXJTfwa+JVUo7K3+LhvCLoKN7aaAC0zqoDzimhPlORt5J5ALsvnFjmWQJC5OpUSzVzOEhjnv577XnReXSy+fGrEG5n/dIzE+q5OdhGKwwj0dUUrcSJUXaF9RuP2bt3FqRSIoOTX8JgAU1Z8/jjFC2H4s6yXwWL2JGFtDaduKff7hOmZgLeuMXcT+q2fvy0odiCgdLOLoAslhYM3wnAB9aH2bm+cyf/QKGdUDqM42f8XGjg7XJGjJZcmCOWtlaRZLbuDGWd+o19UqFcJ90+CuLCODYVd+q0uyM7ZjhL4DILRtSR+4fvaQo02tOd8NQ4kuQ== 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=DQXBsOR2E19Q2CMf9E95TjmQXv+9t0EfWPaUCkT1KJk=; b=lCKfbcZ4soWqX+WzV3VzrbRZizFWlZcH2e/fvMhi7u0qtehUwxL69p2ojwGJ1P2x8okrITX+2O3CECmfFO2td7rwLpl7KqhFBiV0nw5vWMtsAyJKKBahawndT/YpEf33w+MbcaaTCm1on8+5rv+eQoMi6y8Fu20/m/psdKs1mHg= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by CY8PR10MB6708.namprd10.prod.outlook.com (2603:10b6:930:94::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 11:06:06 +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; Fri, 11 Oct 2024 11:06:06 +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 v2 1/3] pidfd: extend pidfd_get_pid() and de-duplicate pid lookup Date: Fri, 11 Oct 2024 12:05:55 +0100 Message-ID: <8e7edaf2f648fb01a71def749f17f76c0502dee1.1728643714.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0084.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2bd::17) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|CY8PR10MB6708:EE_ X-MS-Office365-Filtering-Correlation-Id: d734e814-a680-4f02-cbcc-08dce9e4b43b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: aEVSgP7asg9ZNzMhRdvV5G88ic9NuixlcS6+dvoivRybZsXvJeRF4xBS82p5lll/kR3a1s0TpGGkOqia5OFBCHXtWGwMZ8Icdm9sIPwQpA88Ffind0MTrLUYp9IimsNSziG3CTDItXJgW8Q/9ryk9PPJasBP2KC/8f5UY9aE3XUzUsQFFlkZkMSJ/lrkqIt3EbzAJuBVs9dhqceMkcuyMJuYx/UDeQ75+YPNBW7H4zwvi+mtheF2LJZD1+mt7cayvpwE1H2slRZv5kwDms88pCrSvWEBo6MZG8tPoGWyalegKbZhIeZkX4qI1Qk0IrguTSeN4rzzTEw++9m0mtxRZ3mZqdBYnBfFW/jig3DgWg20HSJepu4bV/n9OWywvQhurXgeTjrn7FwmkEKPewHDzQpbkHL26SgVvzJTeVe+RrfkjUafmLPHk4+H+FHk/s6Ngdz0QjiSTyTNvYNDAV2K0YDCMQCo3NMGehVkmRkKz2MTAu7vS86Gwu///OwtlKMMssFeEEdUmsFOdB1JCdKrZ4vXWgx6oG/Ei7Ng7tMvLASrr+ptFZDS6Qf6Oj0yXB5qVenEBFa0qpPfKixImaB8fpqe3uNhIp5ZQzf5tl3qcFSUVF63V2rFfceupRhEH1V2gdY57pRG44ThahkURyAfsY883Z24abOX/ZzOcGCOdCfr+UnFC2fLS5EZ3+2MN0cvtneBbdXQ+TnyiADCX5t2gEA4Ou3XDCe9lNDx98zM/BM/8Gu8DF8GXIhmJIGhiYo78cFRRQlHt/cZMI3GszLGBOM7KQJu0+JFO25cTehqZhR9J3w6rjjXJ6siqx9FSxG40dJptc1VtrBMMWl7i9ViKDbBi0A5K4SvrKvVPKH3q1ViJWEsMyEUt8qX4qzduw0lCAwULt3XMJhT0Vq9fUNR+++bvasqfXZyvs7az55CTuoThnTKlHz8koP/uO7/a/7nNTii7LaR9OZLWODY0h9kJeg5KWLnPT6hFQHhFzzaZE022biRALmeJoiLlhqvd9QgL33b4MrCFkQLK7ykWvrV57SRE68NjouwERLO4CncfeaX267xC8i4Bv6SPIl2OIo4iRQEiAZ8RrYsp+uA0Pug5Fb94UIPXL9jz3Og95zQ8gDUXUnL64CAEZvAI6DHEvLAUVQIryVZUl9lAqihkpr/kkMlze5UDQFVbxPR+4hthbbTEu3b3+R/SFkHpI70Zp+Gbc6GX+oZN3O+p316USwyhf8CQ7lFeviiMTmhokKiZpKa5AlOpFw1apMONo6awvZ7roL4bW2p4CmwMhBHMWIV8w== 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)(10070799003)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z+sM9QLQAQK7c3DhDQn3ncZ/AnCqknka2Z2B1uvcW9mL36McNVJhrKdByXv5YOwNb80G5QOUi+k71nBxhCFYF5bnH6Y6qYeK5PVpYKkLze2Gc8AxXmI5W7NDqzAVeYXz46lDDN6D4bL2CgIKLJkAgv9sjYwfTYJmzFXA9mAbD+Es1OxjP6R2OFNhs9hJW0gec6Avjt1p7ZTFd+suLRenFhDi3DsSuqvA9rxtIA2wJ4FaAmhnA608V/h9PsTRCpyJ7mRChr1xMgNvzxBwxp2p5AidHBFIz4/L1kCJSr6/8Z8cWBh8BC5VhYwXWGWMjb5ZgOy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jOkiwBsq/ZNrIubZlSSdWrBazDvZbIJ/f1BEpfSHRcyh+7JN+Z6LV9HKxayEVL6NWaf7ntiie/W6/Gqk3HJiizuUz7QAzTnr4UYbWgIrUPg5FPujKRdp4/sSA0YoNevo/CLZvBq9soef/E+56Z7MUpd6xGU8A+Folp0fLya78m5LBkDOU9e7IkYM3hEJ42+Kv13ajG4h8JAS5tmx6yTHvbJpRZJdq9AXEEoB7IdsJsTK9Q6EWzyde8/QWlp/MpiQY1GxWKI6amgj5hOPtLBmsuOv7YQIdRQGMtwLWf/nJBCw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: zztqj/R3iwT8JwSeGfJ+To2W6SJ2jLKHmqhLRrToqetfYRhubQLb9knBBP7OAqsvZEl8h/vj2kU+s2z/QvHITX3k6939HvoBW8Jv170XamgReAqt+bOqDWNtfD7llTQ8dje6OvEanEjUc/2UncveNOQSxIciURKW/JCbfnDIZw2u3nZSRhhUGmsWCHr6qVMRYevifsYIZ5Bu0ra3efEQwpL3IeeYmyNv6MruuCTU7yknmNssdLPdzTFKOA+s6ohDlk5DnWfQK9k2ta1Cbvw1MEYcJt+k/OGA77UuimbV3vsjoPky4/dFchI0v55M46R52t6KDBGTw/nkkntnuFseJ8wrF+VnsN4AzEF0Flzvc7yZB8ILt0kNljH5ISjYrVYZW7Lc0eFcMgty8Qtx+5daoYXbadhtAek6SJa1stn3tBtWuOSU6J34hudShG6T8zeqv3ZjYJweeCNy0oJp0por16NAGKhytqeoBpRunu8e60OMDybNIVa4Z2jtGaOuWFn0gjgTo9ke7WA2k8GRg37010oK/6g9HX4frvryGRwqdekZieZE68nIqPAqzEOejoQ2GsRaFiLQSgB2KCXzLVUMwy4nlj20CxvOII2TjH6ycWc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d734e814-a680-4f02-cbcc-08dce9e4b43b X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 11:06:06.7548 (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: d40LdCJIg/NyZlC04FQ124w4qTOElfB5xJp1hZC5ozlF4JFZ4xAz1r+KEZFr9AfbR1UwSxqp5Q/nvVJOxT5MlDJuSEvmICfIJRHpXTY6tvo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6708 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-11_09,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410110076 X-Proofpoint-ORIG-GUID: 50b_V9ipNSchOEy4dqNWDoO1LtCrWp2H X-Proofpoint-GUID: 50b_V9ipNSchOEy4dqNWDoO1LtCrWp2H X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DF62EC0013 X-Stat-Signature: 98hzckruh4sj886puurzunfjbxpq4ggi X-Rspam-User: X-HE-Tag: 1728649536-299943 X-HE-Meta: U2FsdGVkX1+vupVDyZOlajhKmUbhhMVVfYI78yxhACEsk67S/fNm06SE5n/CnLjxhyYB8t4iWlb1Shn2XmqMokuBN/FbMpA9AmrnGBWIRqvR25oOw8d6t4weIvUUk2RABy2PM6lxYrDUaPcPfbYtnxAcXsAPVYznRLhkZxMc1/LPtSQc1buakd+I61mIfyowymNH5AjF/Z1WKdDfh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vxVribnqmNA4f8Hzq5prqcPBSK03nej6mPpqlGJ5+cXuVI9wL1lm54dMXjTkrEwm2aqB+ZJv2Wx1RQ1LJjIM9UFsZGBFqTs8LZEf/aME42xq7dA35D17ceAZqCPDIE4AyBuMvGwBgyhw4yQgeEU/abdwxS0Vc/514THXxisg6hLEY91ZkbyTE6inCVspp8kR6bOTbKeYRLOOGFc9Hr3G7vBsigL2Jzcjproa83vSrCue6TXt8QK0r6pISaUHLVl/RGsTPeaL96aWAi1TYlA0BE3jv24/d3rSA4X7PZMKZp+7t6NgAXpIx4CIgs+hWQGANBHTHd/lkHsCLnJno7q/ci 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: The means by which a pid is determined from a pidfd is duplicated, with some callers holding a reference to the (pid)fd, and others explicitly pinning the pid. Introduce __pidfd_get_pid() which abstracts both approaches and provide optional output parameters for file->f_flags and the fd (the latter of which, if provided, prevents the function from decrementing the fd's refernce count). Additionally, allow the ability to open a pidfd by opening a /proc/ directory, utilised by the pidfd_send_signal() system call, providing a pidfd_get_pid_proc() helper function to do so. Doing this allows us to eliminate open-coded pidfd pid lookup and to consistently handle this in one place. This lays the groundwork for a subsequent patch which adds a new sentinel pidfd to explicitly reference the current process (i.e. thread group leader) without the need for a pidfd. Signed-off-by: Lorenzo Stoakes --- include/linux/pid.h | 42 +++++++++++++++++++++++++++++++- kernel/pid.c | 58 ++++++++++++++++++++++++++++++--------------- kernel/signal.c | 22 ++++------------- 3 files changed, 84 insertions(+), 38 deletions(-) diff --git a/include/linux/pid.h b/include/linux/pid.h index a3aad9b4074c..68b02eab7509 100644 --- a/include/linux/pid.h +++ b/include/linux/pid.h @@ -2,6 +2,7 @@ #ifndef _LINUX_PID_H #define _LINUX_PID_H +#include #include #include #include @@ -72,8 +73,47 @@ extern struct pid init_struct_pid; 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. + * @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. + * @fd: Output variable, if non-NULL, then the pidfd reference will + * remain elevated and the caller will need to decrement it + * themselves. + * + * Returns: If successful, the pid associated with the pidfd, otherwise an + * error. + */ +struct pid *__pidfd_get_pid(unsigned int pidfd, bool pin_pid, + bool allow_proc, unsigned int *flags, + struct fd *fd); + +static inline struct pid *pidfd_get_pid(unsigned int pidfd, unsigned int *flags) +{ + return __pidfd_get_pid(pidfd, /* pin_pid = */ true, + /* allow_proc = */ false, + flags, /* fd = */ NULL); +} + +static inline struct pid *pidfd_to_pid_proc(unsigned int pidfd, + unsigned int *flags, + struct fd *fd) +{ + return __pidfd_get_pid(pidfd, /* pin_pid = */ false, + /* allow_proc = */ true, + flags, fd); +} + struct pid *pidfd_pid(const struct file *file); -struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags); struct task_struct *pidfd_get_task(int pidfd, unsigned int *flags); int pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret); void do_notify_pidfd(struct task_struct *task); diff --git a/kernel/pid.c b/kernel/pid.c index 2715afb77eab..25cc1c36a1b1 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -534,22 +535,46 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns) } EXPORT_SYMBOL_GPL(find_ge_pid); -struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags) +struct pid *__pidfd_get_pid(unsigned int pidfd, bool pin_pid, + bool allow_proc, unsigned int *flags, + struct fd *fd) { - struct fd f; + struct file *file; struct pid *pid; + struct fd f = fdget(pidfd); - f = fdget(fd); - if (!fd_file(f)) + file = fd_file(f); + if (!file) return ERR_PTR(-EBADF); - pid = pidfd_pid(fd_file(f)); - if (!IS_ERR(pid)) { - get_pid(pid); - *flags = fd_file(f)->f_flags; + 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; } - fdput(f); + if (pin_pid) + get_pid(pid); + else + WARN_ON_ONCE(!fd); /* Nothing to keep pid/pidfd around? */ + + if (flags) + *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); + return pid; } @@ -747,23 +772,18 @@ SYSCALL_DEFINE3(pidfd_getfd, int, pidfd, int, fd, unsigned int, flags) { struct pid *pid; - struct fd f; int ret; /* flags is currently unused - make sure it's unset */ if (flags) return -EINVAL; - f = fdget(pidfd); - if (!fd_file(f)) - return -EBADF; - - pid = pidfd_pid(fd_file(f)); + pid = pidfd_get_pid(pidfd, NULL); if (IS_ERR(pid)) - ret = PTR_ERR(pid); - else - ret = pidfd_getfd(pid, fd); + return PTR_ERR(pid); - fdput(f); + ret = pidfd_getfd(pid, fd); + + put_pid(pid); return ret; } diff --git a/kernel/signal.c b/kernel/signal.c index 4344860ffcac..868bfa674c62 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3875,17 +3875,6 @@ static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, return copy_siginfo_from_user(kinfo, info); } -static struct pid *pidfd_to_pid(const struct file *file) -{ - struct pid *pid; - - pid = pidfd_pid(file); - if (!IS_ERR(pid)) - return pid; - - return tgid_pidfd_to_pid(file); -} - #define PIDFD_SEND_SIGNAL_FLAGS \ (PIDFD_SIGNAL_THREAD | PIDFD_SIGNAL_THREAD_GROUP | \ PIDFD_SIGNAL_PROCESS_GROUP) @@ -3908,10 +3897,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, siginfo_t __user *, info, unsigned int, flags) { int ret; - struct fd f; struct pid *pid; kernel_siginfo_t kinfo; enum pid_type type; + unsigned int f_flags; + struct fd f; /* Enforce flags be set to 0 until we add an extension. */ if (flags & ~PIDFD_SEND_SIGNAL_FLAGS) @@ -3921,12 +3911,8 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, if (hweight32(flags & PIDFD_SEND_SIGNAL_FLAGS) > 1) return -EINVAL; - f = fdget(pidfd); - if (!fd_file(f)) - return -EBADF; - /* Is this a pidfd? */ - pid = pidfd_to_pid(fd_file(f)); + pid = pidfd_to_pid_proc(pidfd, &f_flags, &f); if (IS_ERR(pid)) { ret = PTR_ERR(pid); goto err; @@ -3939,7 +3925,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, switch (flags) { case 0: /* Infer scope from the type of pidfd. */ - if (fd_file(f)->f_flags & PIDFD_THREAD) + if (f_flags & PIDFD_THREAD) type = PIDTYPE_PID; else type = PIDTYPE_TGID; From patchwork Fri Oct 11 11:05:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13832425 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 35D4ACFD342 for ; Fri, 11 Oct 2024 11:06:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2AE56B00B6; Fri, 11 Oct 2024 07:06:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B2C26B00B7; Fri, 11 Oct 2024 07:06:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76A056B00B8; Fri, 11 Oct 2024 07:06:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 504AF6B00B6 for ; Fri, 11 Oct 2024 07:06:25 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1D0441210A3 for ; Fri, 11 Oct 2024 11:06:21 +0000 (UTC) X-FDA: 82661042688.29.3FC0B89 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf29.hostedemail.com (Postfix) with ESMTP id A475E12001F for ; Fri, 11 Oct 2024 11:06:18 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=miEzzZFw; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=naBbbxdI; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf29.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@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=1728644629; 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=8nWoDMl5VOvjzc4SgroRs1FM4zRRVAwaOsTS/I20V4M=; b=DCrf3f7UBnxopINgHGYwNkJII6YCt3xfLY1cgKoZqKTPHI4aJ3rgUd1zPClfDuZCowbzuE gefY2/rw8l4qgiTiWIkesjZebcFSk6d/RDCyAAr1HOxDED+OP+xs46CdqTaNUSUhxFDJUz H7rwD5+hOn720o7sdWFc+u2B24YQ724= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1728644629; a=rsa-sha256; cv=pass; b=SWfYrIaaFRg30MNmhj+hAAwRPyEU8NHFf6RQ9s1lta0py7J6Hw5HfNuvXzXjdErZMIncZ0 r/KdD4y32FDnrUqV++0Y4Rdcl3zJz+3NnK0qepak3GXp17pNVYzTGxLvcs68HgtJl7g7B8 iYUMOCPbL+RdSicHHSaaX9GwDz4zbi4= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=miEzzZFw; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=naBbbxdI; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf29.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49B8BeW1026139; Fri, 11 Oct 2024 11:06:13 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=8nWoDMl5VOvjzc4SgroRs1FM4zRRVAwaOsTS/I20V4M=; b= miEzzZFwvV1+PH1NuWfyYyBG3VhgvAchD6E7qeRHCnBKawtTLC6qclj7w7zlM/7v euciQgj6IZzRJaHzZOtNsl/3G81I3x5hpo2BkPac8EM28b/hHMhdsGMBu1Fti3eK O4WZwFnBEkWvzZYITkhd8EEC7NXpj2cANYrkxqRpHt8wisI+Q+bOkRKMUeKPfZt8 vDhhFiMS+9542YdSXftcfyZqxExkSfBxaiDu60wZB9pdixTGtKDypThB4L5ejvGq AUbQ9YuJV51Rh2bemLTs7iBERFaYaIk5RRaA7wzxMh7MybIgJue3u3J+Gt4hg2NN qCxvoZtBXbGngCHpHgRBew== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42306emn7d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 11:06:13 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49B8soBg005760; Fri, 11 Oct 2024 11:06:12 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2173.outbound.protection.outlook.com [104.47.57.173]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 422uwb70jq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 11:06:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SM9+D4jzdr2ZgQQhFMfz6MtfY5+j3CQHlbfnhkPyaWaQDHargJRzAyqCWy4G6ZflYFlSYeCrSGIt/eYeuCAIw1NDeOy/cScoI31+hILt3ykQA6Sz6K4N3w1QKid4rHwSmN4w3sOc17+KhjOGJg8PBrHv5f14xrAjYBZF148Ehl8k1jCeKNc+IBS7Ot57Ipxvh6Rf9l8rwY/guKMBFlZXLBy5F+LW39FVpnrpVOnswFt/LYrE748uGziyBbK2c5W1FGFo8nMJY434ZyichSuF8+ucgqwzunnHSoV3uqFYKvkVey/ERFmianZTZ80WsqiLW8/vZS+reP+A31aq1dTpwg== 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=8nWoDMl5VOvjzc4SgroRs1FM4zRRVAwaOsTS/I20V4M=; b=fX3ZAqPe+RiPWXjn6M8CNN/BG0/DvB6yT3uqsn3PwN+80pG1j5Kq+GJ2y37L1Ni55ZeptXd2AZf9NXGgp+8d4AGB/NlVNInO7/BNVxbqf28xWKXqUFOKlG/V2SpNXvsEEMsQRzCmOALvrp8Qmh3Xl1UI6EbxY6BOcJ8yfM+evnPNeKnnnORfSjDmAw4k/2TvkGcPs4qrCy01/vQdOHs9/WVXSdKW7Quyu4lfPVmkAeBPmiHz6JLkstSddzSwY6somaLb1dmDh/SCE2CIWLU/ts7UhzZMLoEYBkvZfrekKrUwtfG7rrhv4vGsCFSTE9oP6n+HPEv+1nZJAi2r3aF87Q== 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=8nWoDMl5VOvjzc4SgroRs1FM4zRRVAwaOsTS/I20V4M=; b=naBbbxdIMIQBI7BQHjOogQnUFjWgE5T7SUWOwrXnn+rRE8kbk5z8BfsOU2K6sdPWXvwRdoC9MuOu5i7EnHDuLPmAn3N8MiWivenGCTRZcbwXa++LomEH+pVO4q9o628NJtuH6Zzi/bOmNi+14M6nb8PfmCLF7L3aCSgGUsnpnsU= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by CY8PR10MB6708.namprd10.prod.outlook.com (2603:10b6:930:94::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 11:06:09 +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; Fri, 11 Oct 2024 11:06:09 +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 v2 2/3] pidfd: add PIDFD_SELF_* sentinels to refer to own thread/process Date: Fri, 11 Oct 2024 12:05:56 +0100 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0065.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::29) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|CY8PR10MB6708:EE_ X-MS-Office365-Filtering-Correlation-Id: 4224fedd-4833-42a8-8548-08dce9e4b5da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: TsPOe1b1Ac/jOxpHYw0Q2rWE0jYJd8tfMbi1Xm3pNhpiSAqb+I9t/+90tefProHHJUunWICdW6aMFmtP8O9cEHNrA62mDWi40ftHxudQR3p3oz1YjQj8mzJa4KZtwnrIP5+LAIn0KCM+MHMpkP8fNGhTJgtgvoOf1Q7MUlIz2XGoqT3cGRt+rOKuefnp1vW81pM55T1wCJJgC/oFRIr2HSEjMsL7C245JcpWoqOUKBFx4BWp+IXF8emFdd4KteOP3ZMOFFc/jdPwmqBXyaZO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LI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kA+1xF6FWu/bmKgBRvWg5mBn4upjl1N2KMKGeB7sfAraZUvFV0igalCNwl+gLfLZVPAkMQyOmGw5mKeRA2enQGnoHNd0FN+LTy3HUIQGiLD0abIEf2C1TGU4QqU99wO7XeDfgUsa9sFATERQ96VVeK3BE9DFqv0N3l/KT5sca5CnQZcx5z2PaijRjll6hA/DChMa5HZlwA5B+Bd85v9q193VEK2lv1P6lsRvjKpiWUsSdG5tFXeJJXY+cStFQWeXoTzYSEgXoSqN7qgDrusH63Kz64fdcmFT5/CMMRrXldJqglzDQPj9FR1hamztowsNrVxMF5c5Zlq+fTBRZWroBBdoTR3Lo7nk1Z5bziiaMV2kZQUyjCt20W6/uHz01ncUgsOrztNEodDQz1XRzPoeVyVQKFcZcDNF4pPa6RYl41Qeq1dIhL6WeUCiNbmK6gLTvVip87jKRQHkeUjQ7e9aFM//uxvq7d39DmCCtxGERNXqtm/v4/4HN3ELPyA9KGRfaWd5HjH7pZoTf6s3ikjWwLiI9A7m/uIacbDckM0ehSmOWNJL+qvrvF99hO2MIoKrfW3rMZUSbD2BgEXv6xG6/hVuQ2HryycfuWJVCCYiGeiG4+u470YGoh7BaJqKZJr0OeoxHz31+t+4kzbu9vflQcZv/7hKeTA0jbYjrOOxphqI7DG7EQheI+qQILzNOGcv7Oxe7N+0W0F1fwMzzoVBhp+3WiNnlc4uwDo+dppghsGvdjvuAVkQaOizoUXhj3TTFEC367Z2rElqhqMbe4cgoXP/K6ik9SEb0jquEqH5Kzpwt7/vMmHS4LqV/6AyXSk+k3IN2XUB67rGhWmpmXrDbgrVYkU2ejI6jGx05BF6UntmuADkZ4mKLqvzKV2tpAO7DmODUAXaGcfPJq/NUgk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NwltM0UOhG0SGdIyCTx5QUp++beqUP+h9LiZxRaZLQZIA0WRjjPowoowbiy5DljF+8ocD8rAOIsUlIKvd80Adit+ECp5oirj24xWdbht4G361fslipYJVdswW1Bpby0HK53YF6aSMVuhYLgfGzpw71BD3EBX3ex8XAoijXYq+s5MWcuPT1cpelWjoSYyd7riEjcwUTyYxTTAh/w+Hl14PNp6Bjz0kScrxXWuylQ9jSkb+zFFNmUf5Ig2SKqjCWyiJ/KkOWxT1tiilUP+n8Dz/U7lhICysbcKZS2YbwVppiYcJ1fq4MD2IEYf3yylyLfdQodjs5UXzgJvA7BiqwktWXZ+O8C8qI/2lfWdi6SuKXTGQ0lOCiXy8l9csdMHoSnU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4224fedd-4833-42a8-8548-08dce9e4b5da X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 11:06:09.7659 (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: rRSZSYEdjzI2NVXEyhav1CRSOeYLFjSAdtlhg6/vPs5m6D2wshVbkdEO4XBvhW8PNSCumYOLxe18gTkSU/XPD+xN+/3RokGfhzOlcGdN+cI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6708 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-11_09,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 adultscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410110076 X-Proofpoint-GUID: HA-ExcME-ELBLTV0eFZ4awNQLE-6i32L X-Proofpoint-ORIG-GUID: HA-ExcME-ELBLTV0eFZ4awNQLE-6i32L X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A475E12001F X-Stat-Signature: pz1ahshi67da7bdjpfwxudime6am7d3i X-Rspam-User: X-HE-Tag: 1728644778-403190 X-HE-Meta: U2FsdGVkX19KJ4vPsNOs4EjqMrHNfxjg5vKgMz/macWu8PG3pyqsUTSqcXCcElDfepXUobyEvckNtX1r3npjkNXVaeVt8pRJ9gkkNkSFX25JM6SJIbX+3Q1QMd3HyDTuS2uRvqXGXW5ZHSbsa3cTeVmnMpO66iHlFqk4RNfHnGUWUS66KcrQgJNVOAi0F2X8t0p4StMiU+L3hP+Kco/zuYeZ49q3Lg0XgXRZsArJeiwTATKfrPIMPuid82r3RNJGTTbNJDzpus2DaGodJhcH3Nj/5J5nPLMil7MtZgvfwZiZSMe10grGiEyunA3W0L9vqH04BDGqZtCfJP4wJIpb7lRAqz5RZ2CHDjid98a4lHvZuyNDNNYfy4WcDJoCk/yqHctS6OVPyEI8USC/1Ga3IY4lROaaedi7JOc+EhxOznr/AtGgnqXmkFheZKSnFu/TxxuFpQtvpod7rxL+RFySC+EnrcghTJZyMjeZ5Q4p2nHvCIrHmuduPf7ydy0SeeoD6hT4TPYXW2SlthzXL6Rw7InySQr+TzwVPF5Nt6pOfmG0JdPoFFxIiLH2HOXfH5KmSFsd8CwZVBbDIYWL6UZlHO9TtBTlJTIFt5YXwx+4xn6STQEdr7/uXxUhVz91WCGMa1DAPaiI5LhgWleWy3FS47gVfhDICTv+kTFz8VfuCMLNnjv/AC3F/SufVH2R8qQuJRrRwjOhM3Ix8QoS7YdgrGLzVRFww5nQM3wozAgxf6thY6mceBFU5DV7eJctdilWc9Vdj9BVlI9JI6RaVC59tHT6XSdOnV11RnZh5Bjg4v3RDIJeYoVkOuIetR2uAfMfRItQlY0+HtCeKqbqD7i/gbVkP+P4Pt2SIFj+VdH0Hv6K3qzVU6+M/KOZIMiglXLx7rhn40gD9Ib/ZZe495jAXguegBpFmx2TgKvn5vqw5CrdTq6bImfcIbEO11nttrWMmTT635m8r6gFUthwMz9 ZhUbN2k1 /FRngoPzaN4zl2H1X4Zei5MbuDuHsvS9tVmR0NgYQ8IIfuNLdaG9/U4TUjNa8ElQGhwcS2PpPqg0AJAZltaypFrLj3wkrckMzXV4uDeZvjPc7yrcpF3R/e5VzNb7YHWvtt1N+RTl39FyA09QllreJ2BHHlUBH7AqMWp2C7zbAjtu92Wiw6nfUnvCbDRs9tJs8Vr1Mm3hp+JWyeTgNrRa7gI4SHqUJdYnL5gvDAt/DKeleOGPo4ivIz3dBz8bACBZTDziIubl7QNc5HsYVAwMFl112laJu+VzLSZcGUWvlrURLdH3HG5gCbNHCIUAwkb7rgkryYHHt8tBmK8Jg6LhKpn12UoVyJzA5sey5JADqEiauQalE7Utk4e1Wkj4jmOp2M3o5QOSvkdrsPDhBRIizTxsN05SZpDgDQttD/HcyFtBVriNT5jTrz9lxSQqTrgE7m446IZVjkufkHRvpHARGpd3rNnf0onbszWvWR7SjO/RZBwu7ktUOiY2sBI1JgivWJELjayEyB6A6rHXZ0Fn4hvOMzYUH0ckhoEHQNP1Cap7KPBYVkjW43I54JK+uvcfqtJvPxKRFtNbQZybIm18vZupzbXvvPb9FiFPetopY/3g8ZL/rtorxgPdnOj/6Uz1IaE3Z 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(-) 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; } From patchwork Fri Oct 11 11:05:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13832433 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 0A2C3CFD352 for ; Fri, 11 Oct 2024 11:27:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C8766B00A8; Fri, 11 Oct 2024 07:27:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 774316B00B4; Fri, 11 Oct 2024 07:27:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 579876B00B5; Fri, 11 Oct 2024 07:27:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 310EC6B00A8 for ; Fri, 11 Oct 2024 07:27:03 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2050CAC9EF for ; Fri, 11 Oct 2024 11:26:54 +0000 (UTC) X-FDA: 82661094684.29.F01E259 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf02.hostedemail.com (Postfix) with ESMTP id 1545F80016 for ; Fri, 11 Oct 2024 11:26:54 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Fx5Y6LZ3; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=G89zZ7Bk; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf02.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-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728645881; 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=YXP4oBBbOFFH5eJ5/mE7kNI6rApLZ6pu5Gss4+TGeF8=; b=eLWyCW9nrJMIFnnTYF+vNqaQbUY6NQQkUAfNz+NNj0jVYZVwhRMuMyhvrakf10FhjcV9Zk 3stTSpbnODdzn/9MK5fBKFJgaJ8H+GwXR+J1XdRcEoRdHlSlySBJfbST693ulKN+85wc0R TRZGM0SRT7DJ7bItfcq7BOJydB8ffdE= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1728645881; a=rsa-sha256; cv=pass; b=jMaEWBFY22/fYLstCu22mRMOTMkfus+1npFohQ5idpfvLtCMfPKW1432o1Y9t/hWX1yfwr oA/plJy+NpDA+UjnVnHqZKYRbijzI4i+v7k55nuNqXjYa8muWG8VL+RpfDOm1TP1Rp5gxF 9WPyNy4K/AcZ+up63bx176utrMnjtMg= ARC-Authentication-Results: i=2; imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Fx5Y6LZ3; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=G89zZ7Bk; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf02.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 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 49B8BfSk006323; Fri, 11 Oct 2024 11:06:16 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=YXP4oBBbOFFH5eJ5/mE7kNI6rApLZ6pu5Gss4+TGeF8=; b= Fx5Y6LZ3ATP+G237AJMLART6XsbnQfZu6lwXek9eJs21ssdeFbxxkO8pl19tuh6W /j8VPbtvd4jsYCje6+VtWMMgb3r2arPD9SNIILjXTzn0dMNJVgmNEjLXybAX7+iB FEoF3nCwho1MMoPx/RWuBujAbwPwfPgf7+G+/ITyDKek02oaXO31NYMN/9bsNpcy 46dQMpuKyk6bKA/CDUyVPxy1uiZe4mL8DeyL6yF1xCWlplak/HU0NPeWtIWtkSKE 2Ml4EvxHR/XYsOgri1hIct+blYTKt8y/PAST0dSFfp/Zbd7O+/8Mg/c9HEKIQtIj s3SE3lnG46RMekQC3foLWg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42302pmep6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 11:06:16 +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 49B8sowt020588; Fri, 11 Oct 2024 11:06:15 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2175.outbound.protection.outlook.com [104.47.57.175]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 422uwb96y8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 11:06:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OTZFToNKIM/DdiKK8PMgHpQ3CQGpv3IuL4f4YumhOPy+XBCSZn1fUJMPwB/YFung6DFmIUUjZB3cmcVWy7ObeKQxphRD1HCa7d8riCQ9ndVY0qFp1BPuQuOrLgF3qFs60+JDaFYc8zOrSNWpJIvXYpHO+jDm0Ss4Z3y7f+iRGAH+/XDfQY7LeBfO/MkIwxvzv1e8HvWBVkl3jR+AQtSN7lyWm0mJGYXHrs9S4lHiytz/bbKY7IFaV4CJCexFVdtkcNamD8ZoSUmxnD0wq3rJDcurBUeGn7UtZAE67ldKubgpg4zvKb6FkemHT/0ztE9OW74c+6Ci0LGOQAn2og8DbQ== 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=YXP4oBBbOFFH5eJ5/mE7kNI6rApLZ6pu5Gss4+TGeF8=; b=fxITaIlInh+VDePjoBT9X4zT1J/wCPsuQeUwyILcUgDccFg6pJfDCvFSvwnl/IWuxCgxtBOad3zrM9M/grX9EMlJcu7h/sOHoGzpy2M6OQKym7/rcatmp0bRliAxP0VZGwPXsUBZ8yUnE18Ppm53GnRb7lFCfUC5tJQEZyNuAkSIgVME0tWbOzx18vEsEYfR079bpGA42f6TcrN3HkuVO2r97Fm22xryq5adeVb7o3H/GB0O/Z3m7zWgF/3zkUa7EyfhUcurqfYuTDtyJ4amF4BLCiIKp2yMgZRiLzbOT2Yb4G6KHWVpYh618/PjCg0sXc4ZafTUqCDbJMxfnSRuYw== 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=YXP4oBBbOFFH5eJ5/mE7kNI6rApLZ6pu5Gss4+TGeF8=; b=G89zZ7Bk3PLzwmV2Li+sLT0cT7hr4/H10MgLgU1n4rDw2DCy1PKax6v4jWntXHMa/l/jkAPSLtIkB3dJADyBJbTxnfE0bT+KPLM6Hy2kLvxVYb3x7iaVRAE2Tag8rvpjYoeiPL6E4IhJ25UJXSrc+WRuPeZ1VAKYT+aOST1MrDU= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by CY8PR10MB6708.namprd10.prod.outlook.com (2603:10b6:930:94::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 11:06:12 +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; Fri, 11 Oct 2024 11:06:12 +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 v2 3/3] selftests: pidfd: add tests for PIDFD_SELF_* Date: Fri, 11 Oct 2024 12:05:57 +0100 Message-ID: <993cc7b6493e967c6c90b9944e81848de6deeb85.1728643714.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LNXP265CA0051.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5d::15) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|CY8PR10MB6708:EE_ X-MS-Office365-Filtering-Correlation-Id: b3c713d7-4ccb-4b5c-d4c3-08dce9e4b7b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: SbeuINHiXlmOPNah6ABjp6UHikuH2pgWJGL4dxyOsDNuGZk2ysdwESiZoDcou2V993te51+zBceLKT5uxzjuK2PQDfhE1TZK46oQlWMd2VsXdMAs6SiHJfgmJjlTBR3bQatqsNFHYZipnpsmYYkbVU9AyQC8UFwsce/xoNp/LY97WgM8a2W+uorYyZFdDudCEoUan9EXERHCqmlq4cCXaUrNVCyw3VQIdR5HXWAN5AUOKpe3Pms1SIqNArPCy86LgcxUhNt2KHyqgGPX9SLLlf8qlP5bpW/birekfRI47kKv6cjFGIdcMYl26ERafiNirD16kGJ8m/qmFIkJi89zCDSrkdBtcc6/TolhE5sANOqPoINrga0+IqeorMTOV0YDRqz3S+osGbFTma2id63f/F8305SS8IVEw9lM5niO1YEaCJo9T9b8x+B0rJ/tM2ACLgCqli9C1YhOMz4T1ikkZ1EzalwJPx/hBbat6qLmIOhXRmq/7KEQdci7oR7awIvKHkWvQ4Vy4fCa/HiEQGs87f5bOv0j3f7pARUuwXMxL6r4albM7OksNMWDig8oxCIUnWyk5LqwL9HtwqdvhfDK0iYPFG+4y+khMWm9PnSShRdXBzF/Uwlkq8Voe1Fnt3mkf/CcY8aHWKM4I2Dp7+WevggBxBKbdWUY13VPguWkBxqJ/EKTRABtfqJOflz4K6eBxSY0opYAX08lMlZFcFWPo6qLNUJMzStZ3xyADyrDw7a/34sWecwby8GWKuPSiUdxa2X7clKL73hKArbthP17vFM+ITpK4ZoMwx/yBNOLIB7lcFTLH/4lhcA8mDbh9kayV57YCEqutFf+GT6YDu2ozESjCNP+1eGzQS85C190TBISLJ2bVDf+JWEHkhnddsZxr+nseJ8i4YLwk1iqnszIaaE3mXrQNKUWwqKtC/+g3GVal21Imds+T76SDTCHd+a7jDhZQQfo07DtR/1FcON7pAGccNNsKZyOjlhKnoO4FVcOCyyv4FUHooZNrbvWs2zUj2T/4Onx0H8BOehuW6a4haweztmyu2Pk8OL5zyNNyzpy/2YzGiFFDtJC+lviOclHykxnWNhNfv582w1/T2gaewJtO15NGgcwqS8vFXl4CWudUgvXF+imDj9jAUOByG4yXsLghAS93Li3mvlmlbot0r/wv2Z2GGcevtQKJRbw0QuXtbl1QsEFuODbgxoUFPj2Pmf1nDSeYcu3bx4tj05lQDGd9HMWsLUnWEftDkwc4Q85UvC8kH1XrgtMW7swM0WI 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)(10070799003)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xevkg9mlV7VzeNfd0HkLdVBRxlUTuZ1yni+E9wyuLi4hplyFJ2LuyPZ+wAziRuPxCVRCn/6LGJtVvMGxIhjBqaOiE9NTdvlVecbGuopbGbhpPcT7iGw+olyXDReF2vI1nvAXZMgJBS8kJ8toG+AfUErvTSd59yEWmmAvT30Yit+hPwskaAD2ZwI4Cqafd9Et5mzAjRzpwMrv6jTxXms4lpE4B8nV7pXcbhFVADWQRy+Gjw6L+zYk0umhPhMKzVAXTL55rsh4KV51ts1rap33WVg4ovP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Lyh3py+E9T3bJEKydOkx/Nmqd7mrElMVcHw5mlmJXyFGy3aEYa9P3ZGR9LSGOCUCNK7wVLIAUb5mmnqQeGi/aa/RUGayAcL1qMmGUDyTjYT1yCSxhdZReHuJoVP4BAXugLD+i22UgQ6kWtphCIIFAacPjG7DnE7+qIHDbvf166dhLcvWZgRG0r9lYYgvhC6fLQLmJYOPn1xCWGqgtZFC8AMJ4y8ZiuJU1efEgz0csNJGosQMVVN4INEouBwTO+7LjmkUqZgCE3aj3+w2aB854RJwGOMmQb0xRxM7GQ+D4dWr1OJXe4eWo6ECA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: uZS+x+G0xlLJYN14e+oqks9lYvPZIgE1QC+CWMduK90XK+tlb1XLPIbj6jsEpzJLvQk5AoD1GWed8d5snsqFgLIzAEHNX5lK19VhlMLXsQ+z6TuDKL20PR/SPJ/Xfb8n0+1bZY9qjvN1yqI2olV0hkhaAwontqqxh4itoEaNb9IWvyO87BxsIQUF7pRz1fVtQEV0+HSi8JF//oFoprPkUHZDETufxtzbWYCm31qinw9ovy7hJwH3FsPjApBgj+rvH4cuazicHLN6+sov0+UWiNrjjlz4HHJAvin+kL2TZirXs8GRaHr2gJ0t2LI9WDLlJgft1ImgneCTDinrwp8fkley8r72JbC3f1Pup0KNHP2n/xzj67qCq9uxyn1V0StvNal//BAeXT/Fd9r6qivRcnG2hXpwqfpmXS+6c4bHtICLKRfIV3gG/DuzBFR9xQWkRIeeoNp+eihpwla2YofGy6zWRry2uIulyJWYP/kg9VXtbSmgMKWxIUImYKda/4fHtuJ2LvOmgm4jnKhHBfZ3s79zw1vc7dS7ezpnZilpZEQuXr+8Xxn2MKFhJ9TEOIKi9I/+QVZKxRDgQAHSVdDXI7/M7YmXdBpHsWVXLsOCRyk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3c713d7-4ccb-4b5c-d4c3-08dce9e4b7b5 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 11:06:12.5804 (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: xU/rlA8EuXSvxsiVolwpdCuCfT+701sSsR/fr0elFrwGZaC3PzDG7JaNXxhsTMDJhQe8lEmpNjc8a7GqDpNWodqmi6DSa9AQ+HKQTcKQMG4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6708 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-11_09,2024-10-11_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-2410110076 X-Proofpoint-ORIG-GUID: qZY_x49ofLCaMb_UVUjzXTk0QA5ljD72 X-Proofpoint-GUID: qZY_x49ofLCaMb_UVUjzXTk0QA5ljD72 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1545F80016 X-Stat-Signature: aajg8unj79ct1nkj4phtabiaq964p8qq X-HE-Tag: 1728646014-657702 X-HE-Meta: U2FsdGVkX19XAeEf3kelV9wEBwpmvCo0x6zlTWKfHwxonVqCpD7JxY+i2tvakW6Ckzo5tTrbByNnM3R9PvVWcMPrkvm0BlwgxuSQebr4YskZYge9wcpqArWbozB6KlkWwWqg32oyhQGS6WioMPTBO7jnV6T/GTm76JsO6kc4PjkhEe7tws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Er2jk4GcpFSQxPXmnqdDTt1NPo1PMkdWrg2NdRsMP6J5S27Pak79cNU+vNxazxZte11z2aTSWvDkw3uMwnhZ9mS63f4Lumw5wOrkvWjSMQQr17vFRpEaOnQRjhStl8nyMFWyMjy8r6lGD2gbyiA3d0TJAijfwo6wQzRfy9+37ohErLmPPF5SnMrZd5JR7T4HI8Bu7+41nMVznd9vPkbCHGcM3SXIlWn6rzjdOEoRSBg9TiyWQpSF3MC/1pkVUFBhtnVRFXvESve63Pnxm8piva5x1Y5xALOTmzHALdX01LD6xnQTFJcHjO6yNxpCqsRpqQROCLiTXvYm5H+Rivzaee7VL00uVZElbZ1KFM2He/B+K+o+fo7Z6Vqu9ZuuYfg8A= 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: Add tests to assert that PIDFD_SELF_* correctly refers to the current thread and process. This is only practically meaningful to pidfd_send_signal() and pidfd_getfd(), but also explicitly test that we disallow this feature for setns() where it would make no sense. We cannot reasonably wait on ourself using waitid(P_PIDFD, ...) so while in theory PIDFD_SELF_* would work here, we'd be left blocked if we tried it. We defer testing of mm-specific functionality which uses pidfd, namely process_madvise() and process_mrelease() to mm testing (though note the latter can not be sensibly tested as it would require the testing process to be dying). Signed-off-by: Lorenzo Stoakes --- tools/testing/selftests/pidfd/pidfd.h | 8 + .../selftests/pidfd/pidfd_getfd_test.c | 141 ++++++++++++++++++ .../selftests/pidfd/pidfd_setns_test.c | 11 ++ tools/testing/selftests/pidfd/pidfd_test.c | 76 ++++++++-- 4 files changed, 224 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/pidfd/pidfd.h b/tools/testing/selftests/pidfd/pidfd.h index 88d6830ee004..1640b711889b 100644 --- a/tools/testing/selftests/pidfd/pidfd.h +++ b/tools/testing/selftests/pidfd/pidfd.h @@ -50,6 +50,14 @@ #define PIDFD_NONBLOCK O_NONBLOCK #endif +/* System header file may not have this available. */ +#ifndef PIDFD_SELF_THREAD +#define PIDFD_SELF_THREAD -100 +#endif +#ifndef PIDFD_SELF_THREAD_GROUP +#define PIDFD_SELF_THREAD_GROUP -200 +#endif + /* * The kernel reserves 300 pids via RESERVED_PIDS in kernel/pid.c * That means, when it wraps around any pid < 300 will be skipped. diff --git a/tools/testing/selftests/pidfd/pidfd_getfd_test.c b/tools/testing/selftests/pidfd/pidfd_getfd_test.c index cd51d547b751..48d224b13c01 100644 --- a/tools/testing/selftests/pidfd/pidfd_getfd_test.c +++ b/tools/testing/selftests/pidfd/pidfd_getfd_test.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #include @@ -114,6 +116,94 @@ static int child(int sk) return ret; } +static int __pidfd_self_thread_worker(unsigned long page_size) +{ + int memfd; + int newfd; + char *ptr; + int err = 0; + + /* + * Unshare our FDs so we have our own set. This means + * PIDFD_SELF_THREAD_GROUP will fal. + */ + if (unshare(CLONE_FILES) < 0) { + err = -errno; + goto exit; + } + + /* Truncate, map in and write to our memfd. */ + memfd = sys_memfd_create("test_self_child", 0); + if (memfd < 0) { + err = -errno; + goto exit; + } + + if (ftruncate(memfd, page_size)) { + err = -errno; + goto exit_close_memfd; + } + + ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, memfd, 0); + if (ptr == MAP_FAILED) { + err = -errno; + goto exit_close_memfd; + } + ptr[0] = 'y'; + if (munmap(ptr, page_size)) { + err = -errno; + goto exit_close_memfd; + } + + /* Get a thread-local duplicate of our memfd. */ + newfd = sys_pidfd_getfd(PIDFD_SELF_THREAD, memfd, 0); + if (newfd < 0) { + err = -errno; + goto exit_close_memfd; + } + + if (memfd == newfd) { + err = -EINVAL; + goto exit_close_fds; + } + + /* Map in new fd and make sure that the data is as expected. */ + ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, newfd, 0); + if (ptr == MAP_FAILED) { + err = -errno; + goto exit_close_fds; + } + + if (ptr[0] != 'y') { + err = -EINVAL; + goto exit_close_fds; + } + + if (munmap(ptr, page_size)) { + err = -errno; + goto exit_close_fds; + } + +exit_close_fds: + close(newfd); +exit_close_memfd: + close(memfd); +exit: + return err; +} + +static void *pidfd_self_thread_worker(void *arg) +{ + unsigned long page_size = (unsigned long)arg; + int ret; + + /* We forward any errors for the caller to handle. */ + ret = __pidfd_self_thread_worker(page_size); + return (void *)(intptr_t)ret; +} + FIXTURE(child) { /* @@ -264,6 +354,57 @@ TEST_F(child, no_strange_EBADF) EXPECT_EQ(errno, ESRCH); } +TEST(pidfd_self) +{ + int memfd = sys_memfd_create("test_self", 0); + unsigned long page_size = sysconf(_SC_PAGESIZE); + int newfd; + char *ptr; + pthread_t thread; + void *res; + int err; + + ASSERT_GE(memfd, 0); + ASSERT_EQ(ftruncate(memfd, page_size), 0); + + /* + * Map so we can assert that the duplicated fd references the same + * memory. + */ + ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, memfd, 0); + ASSERT_NE(ptr, MAP_FAILED); + ptr[0] = 'x'; + ASSERT_EQ(munmap(ptr, page_size), 0); + + /* Now get a duplicate of our memfd. */ + newfd = sys_pidfd_getfd(PIDFD_SELF_THREAD_GROUP, memfd, 0); + ASSERT_GE(newfd, 0); + ASSERT_NE(memfd, newfd); + + /* Now map duplicate fd and make sure it references the same memory. */ + ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, newfd, 0); + ASSERT_NE(ptr, MAP_FAILED); + ASSERT_EQ(ptr[0], 'x'); + ASSERT_EQ(munmap(ptr, page_size), 0); + + /* Cleanup. */ + close(memfd); + close(newfd); + + /* + * Fire up the thread and assert that we can lookup the thread-specific + * PIDFD_SELF_THREAD (also aliased by PIDFD_SELF). + */ + ASSERT_EQ(pthread_create(&thread, NULL, pidfd_self_thread_worker, + (void *)page_size), 0); + ASSERT_EQ(pthread_join(thread, &res), 0); + err = (int)(intptr_t)res; + + ASSERT_EQ(err, 0); +} + #if __NR_pidfd_getfd == -1 int main(void) { diff --git a/tools/testing/selftests/pidfd/pidfd_setns_test.c b/tools/testing/selftests/pidfd/pidfd_setns_test.c index 7c2a4349170a..bbd39dc5ceb7 100644 --- a/tools/testing/selftests/pidfd/pidfd_setns_test.c +++ b/tools/testing/selftests/pidfd/pidfd_setns_test.c @@ -752,4 +752,15 @@ TEST(setns_einval) close(fd); } +TEST(setns_pidfd_self_disallowed) +{ + ASSERT_EQ(setns(PIDFD_SELF_THREAD, 0), -1); + EXPECT_EQ(errno, EBADF); + + errno = 0; + + ASSERT_EQ(setns(PIDFD_SELF_THREAD_GROUP, 0), -1); + EXPECT_EQ(errno, EBADF); +} + TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/pidfd/pidfd_test.c b/tools/testing/selftests/pidfd/pidfd_test.c index 9faa686f90e4..440447cf89ba 100644 --- a/tools/testing/selftests/pidfd/pidfd_test.c +++ b/tools/testing/selftests/pidfd/pidfd_test.c @@ -42,12 +42,41 @@ static pid_t pidfd_clone(int flags, int *pidfd, int (*fn)(void *)) #endif } -static int signal_received; +static pthread_t signal_received; static void set_signal_received_on_sigusr1(int sig) { if (sig == SIGUSR1) - signal_received = 1; + signal_received = pthread_self(); +} + +static int send_signal(int pidfd) +{ + int ret = 0; + + if (sys_pidfd_send_signal(pidfd, SIGUSR1, NULL, 0) < 0) { + ret = -EINVAL; + goto exit; + } + + if (signal_received != pthread_self()) { + ret = -EINVAL; + goto exit; + } + +exit: + signal_received = 0; + return ret; +} + +static void *send_signal_worker(void *arg) +{ + int pidfd = (int)(intptr_t)arg; + int ret; + + /* We forward any errors for the caller to handle. */ + ret = send_signal(pidfd); + return (void *)(intptr_t)ret; } /* @@ -56,8 +85,11 @@ static void set_signal_received_on_sigusr1(int sig) */ static int test_pidfd_send_signal_simple_success(void) { - int pidfd, ret; + int pidfd; const char *test_name = "pidfd_send_signal send SIGUSR1"; + pthread_t thread; + void *thread_res; + int err; if (!have_pidfd_send_signal) { ksft_test_result_skip( @@ -66,25 +98,45 @@ static int test_pidfd_send_signal_simple_success(void) return 0; } + signal(SIGUSR1, set_signal_received_on_sigusr1); + + /* Try sending a signal to ourselves via /proc/self. */ pidfd = open("/proc/self", O_DIRECTORY | O_CLOEXEC); if (pidfd < 0) ksft_exit_fail_msg( "%s test: Failed to open process file descriptor\n", test_name); + err = send_signal(pidfd); + if (err) + ksft_exit_fail_msg( + "%s test: Error %d on sending pidfd signal\n", + test_name, err); + close(pidfd); - signal(SIGUSR1, set_signal_received_on_sigusr1); + /* Now try the same thing only using PIDFD_SELF_THREAD_GROUP. */ + err = send_signal(PIDFD_SELF_THREAD_GROUP); + if (err) + ksft_exit_fail_msg( + "%s test: Error %d on PIDFD_SELF_THREAD_GROUP signal\n", + test_name, err); - ret = sys_pidfd_send_signal(pidfd, SIGUSR1, NULL, 0); - close(pidfd); - if (ret < 0) - ksft_exit_fail_msg("%s test: Failed to send signal\n", + /* + * Now try the same thing in a thread and assert thread ID is equal to + * worker thread ID. + */ + if (pthread_create(&thread, NULL, send_signal_worker, + (void *)(intptr_t)PIDFD_SELF_THREAD)) + ksft_exit_fail_msg("%s test: Failed to create thread\n", test_name); - - if (signal_received != 1) - ksft_exit_fail_msg("%s test: Failed to receive signal\n", + if (pthread_join(thread, &thread_res)) + ksft_exit_fail_msg("%s test: Failed to join thread\n", test_name); + err = (int)(intptr_t)thread_res; + if (err) + ksft_exit_fail_msg( + "%s test: Error %d on PIDFD_SELF_THREAD signal\n", + test_name, err); - signal_received = 0; ksft_test_result_pass("%s test: Sent signal\n", test_name); return 0; }