From patchwork Thu Oct 17 21:05:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13840818 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 8F6FFD3C533 for ; Thu, 17 Oct 2024 21:06:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A3306B0082; Thu, 17 Oct 2024 17:06:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22C366B0083; Thu, 17 Oct 2024 17:06:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0086A6B0085; Thu, 17 Oct 2024 17:06:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CF2E66B0082 for ; Thu, 17 Oct 2024 17:06:29 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D26E91401C1 for ; Thu, 17 Oct 2024 21:06:17 +0000 (UTC) X-FDA: 82684327236.01.85FB415 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf20.hostedemail.com (Postfix) with ESMTP id B921B1C001D for ; Thu, 17 Oct 2024 21:06:13 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=e6TPyDPw; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=DbAlvB+O; spf=pass (imf20.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"); 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=1729199138; 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=lnHUS4UIhYyR8R1+WVfMLZVb1cNLjoWfDTQTYj+KaEI=; b=naF6f+pDswZt6k2ZRa6LJ3NN98LG1Nw5TbNuKAaGHvotgh3+G4Or2d+B4eTnFI4Wbu1Yvy XJ87/iznMYAqiQ9W5L4r/tnnNvraRt1KNy5BJ9Dsn4p8Sidktpv0MPA4zVXXAZqO6BzSTi M9qbn/U+kU4a8Kei1kXsO55cl9S+AcQ= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=e6TPyDPw; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=DbAlvB+O; spf=pass (imf20.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"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729199138; a=rsa-sha256; cv=pass; b=exIGWIps7FKjOHD9k2O7LJKOVb692XKCml7AQQu9LPUsFsHB8xV1Yklp/ma1ADHYtrFF39 D62sx1f2jOzW6vjBiZMJ+qgHuT3CNBJOioH/aLU8u6mU7CBH641puBkD0Ki/NSexJSbn9z FjrW0eb7JwYP+VdKkHSa5CS75u6TkTI= 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 49HKtkgS010328; Thu, 17 Oct 2024 21:06:18 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=lnHUS4UIhYyR8R1+WVfMLZVb1cNLjoWfDTQTYj+KaEI=; b= e6TPyDPwjCgI7hdpv9nuZ2S2mBnLulhSRqLxXYOHY+bNd5vHM18q1bEilIrwTRgU ZT+Uw7H9k9kGFMp6bmwEm/WT18aB1IGy18YpvDnWTvJFSezVT11mxeuvhQCwn+eG MmOjjtrDfCTUfFTySRFqShtJDME31FLvC6Ev1ajtknA/kaiECETY5ME4DvkGah2z QQWS2Tq0kI5c7a/PWU2Fl27KrVXuo6OzpPED+c86LpMoI0xB+KUHf313pZ3fr/qj hfP7h4GxuQrtGM8QlxjXzphSdSYrhLHHkKyOdNLPuvuHLWepcgF3R5su5v8Lcybu hOukwL0aLV3qiKSvdlpaEQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427h09purd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2024 21:06:18 +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 49HL0Jbf026190; Thu, 17 Oct 2024 21:06:17 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2176.outbound.protection.outlook.com [104.47.58.176]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 427fjasv2c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2024 21:06:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bMq7mOCu9gKE774KrwkpxKsvMVnQ6Df760IrBxSLWN7PO7QW2m+eYreVNOeB4kVrG6pKOjz/GaPEKtaoOL1SP2sWcVrUWaMQTwL0hPAQTm2FH9BGVNKmOtTFqBqYA7WpRyY33o99BWdASHEl+4qnv6jPDP3PLO0m9Jxj3vY4MJAWmoz8Y0wwnCExZNYYlbTQCwP5acu6MK3IMFTvAfRBH3s0zOUv30iwPjKecULrltXyq81GWCsX8QyLDC5x1+MgqnTxg0+wfmV7OzRpiqVzp1BTsfHSwY4CVTm4z+s8rK8/zyDcJilXksD8tgCqCzTMtTBDJ3kZw4W9xcgTQje2gA== 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=lnHUS4UIhYyR8R1+WVfMLZVb1cNLjoWfDTQTYj+KaEI=; b=IiqYNLv/ssmqDizv84IV07RQA/tnAKWOGDCSv8qikuuOEWXAxEzWkiOFQ4p9yZcaZsc61DUtwQvtpRdsA1P936ZzLbkyaMhttpTw0iYO6l28xIWmZ4LMNSC1dS+S+PPODhd6X+eCN5XiFy0apNL1S6W0WF2uJ4BVFncxTL6DX2wQcWJbKM5v+PtsaMxlhgtvA5GnBGUfk+DJA7QysYpv6xr/KdTKKNhoxWoULl9hNxOsrDkUT8VP6vaCe8edSQ4uGirnxQMctl2ZOHC1auVwR6xL0JOofdHIEFiCKmmE4nXBcuHNNjdVxxm3rqXud7LgpMqC6vX74kbGtytnO0CRNA== 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=lnHUS4UIhYyR8R1+WVfMLZVb1cNLjoWfDTQTYj+KaEI=; b=DbAlvB+OpBs1L51Ix6htdjDPE9+/rqq8X0Do4DsBCh7G+cq6Ynwri+A9tYfixbBu8VYkOLKsW+dXyBm7IQ84DbpwhRc3lm7AflZrQxA+R9FfBmIFV3Y8X3iKdo87QNorrVn3hy7bxHwgKIwp5O0Ot54kb8iRgNJ2zPinoBYd/XA= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by MN0PR10MB5981.namprd10.prod.outlook.com (2603:10b6:208:3cb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Thu, 17 Oct 2024 21:06:14 +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.8069.016; Thu, 17 Oct 2024 21:06:14 +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, Oliver Sang , John Hubbard Subject: [PATCH v4 1/4] pidfd: extend pidfd_get_pid() and de-duplicate pid lookup Date: Thu, 17 Oct 2024 22:05:49 +0100 Message-ID: <94a3210afe96c9d1d6f9460d7d37a43e5bc5f550.1729198898.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0049.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:310::9) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|MN0PR10MB5981:EE_ X-MS-Office365-Filtering-Correlation-Id: ad521fb5-85cd-4c1d-a1f9-08dceeef88e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: 2dexafrH2TmATgSjllgaG6rOliHvpff+AezMXr8dejFupOMQFuU9Zu8DwWvHrBiU6RPERtWLi7MuUySFCUibxZFV/c+aJhu3xC3hNzUCtMtSDskamhZKiWoh/KhhZNQnzNi0vkDi0Zywb2gbQgYWeVdPoMC5zEtYsWHH9Q9HxMjDFDFmE939SW2e0sYpVq0hVYbbvPOg1ohpwwGMLszoC9itY6aeB6l4QeuEwGFVNWg9nd30SupxmsWpKyKFYgJe0yJbUmXyvxO9ayefSK2jkVFbg/xU37oFkT09u4K+bwV6xvD4vtyUFunK+zmlWMeZKXTjRNiQi/v5YHI1hLkKGcaseLd3bB2HQxSYTqesBuF/kg+DcGIpMwgJt/OEbqy2fl2NRepS9cJZMJH38AQF7/eTPf/DJ/W6k7g4gqj3JpFEGkh2uTunpQCb9/RIX2ImIj2T6OZecc9xFV69OaE01AeAqQaYftd+IVmEVxkJiqzmq5z0kQUIRuCO1q7+vpld6agv54NVzfvuLgy1R8B2sLhXi7cB3Z/UyUMw2uFDwrlJI8Jaf0AxP41TW7SyfC8bR7k/xCy63ncpc9ZQUi8zjTa5cLOMEI2CRRv3CdjWA3rRQer+iAgGpDgA7UaHUUi/K9SDChfNjaak2RVISoSqFPrWahwcVQrVkLzTmG3esyWTVgsCMGWZfHZyinrKbfRRT8FShsqs97RDjlliXc6jfEwBHVI/ibsxjxeH/OCTgFSmic7rPU+1sJc1sjazYnMsAKxfI85dLqJtesdT4W1HUp5ILMnAPqnaMi4cTO/fSZB4A/a9i0CBuiJnIjVRPzWgI9LU+X6JmtlaIKQTAzzLsX/vu6Rus9w0K8Fe8FZE69lnaZNBQLcQESAHtD8r8Jsqbx3sF0NOai1SG0T2TzYtr/MFyQqUXCb/Z31lgIBewanoMEnVX0kUNIFyt0fxMmQVPva6G4D0bsZ5JJw95b4YJFbVkEnmI+anwjCwd3SWQJkDENLJu0C0vEyQ+qo1wLCIuh0mYQ1/9gdLbGGOa3Bgr+Tfp8+kL96V72CG8JUU2jy/PAqgVzF5O3XtVbm/3bAOABPOF9uUnAgXkC6mnsVdkpM6wa6NwUxQM5OD3tiIAnEX327gNUl+Pw2QRQRgGyK6XOIIB4JwUX0lYzWVTqUhKMNLuuSvJK9VU57twvNLycXYPf2Mn4Nv5Yw/NwJSMC7LDd9vGBi7WAmC8mULLWiyfYF7q8qoA4pmFum38PfbTPddT3MNGuAa1rzv2Ja/haR8v+kXt7XMY+4nfjF5vFJIIj+A4bTLAOxFot7Y+EgqSgbRu7tfa44VwoIZSaxgQDN0 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)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sVsPPMk9ZfaI5ExrhAxmeoN4T6RPs9ikZ3y4JGooGHoNq7X2FsE9acC4fnQ2sSDCnkAc5zUaL/ij2gJAZOTTYBmumFRuC9u0oR/shWKWB6MrawbOlzhRoHnKxgDNs48DIwO2WVIlQwC6f2KhnvCFhARBRa+ks7bb0Lg4g/fWjpLD+A00DMmkMO8FE3GhEPD63pgwRaSwCt+cBiHMYwv2Aiys59Kk4Lqrel58YLv6NELhOOhuxSKEnxeb+oOmH4KKij2v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1gQS+LgZK3L+dbU0KshtmABkLDNdrHpcBW6HYs52m6tOpI02jXOHPDbba5GLzsj+HWTW9I/hKvH6wQ8xV3XEPN1lwygWjxQLBiCfxmXZjnCuQvsVzcoZnCigk6dhr4kU+0i/N9eSXeG8vG8a173J5194Dv6/6fd8ux/Egfc0q3yUW6VEPBuvGEwC5DGtHoT67OW1Vopa9XwIu86EtwDHgmJCHfjYmOsLB+v6s6udvj3TlsxOVv6iQrF/M74v69SSL8gg7JXF0kLlanh8EoOKK4PKrg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Udt6YFq67GMgkbxBTjAI5IdMr8aVVVh1p3mHaJhUqnHjlo5BA/kEmpM3WysuQP1I8G8yCsXLu7snK7WrRwm+ykwROl2F/tkU3NaA+EXca2uOYQ+3eFXe2HcG/Y4NnEJ7J9F51yx7ZzhELSSviG4DhdXtbwD1BycEYp3DYXdpQlY7DoyI+RcBcQLxCCqhTYW+idtUFNEKAwkl5Uhol/GzfCci8Ox6GNY674LYoZaRJ085L46wEyC0cBS3OjNNbE8Ge6QfA51RXWFM5jAovd/pX3EY6lw1dmLAzp42c/3KUVDIddTxWddHAOqYLpzaM0fTyv+vWm0Qodp1DleNB5esWqGROyugTXlgxRaUGmwFOsQtE3l75tfN2CunxCepghWE90vj6fhlEyQKFXXddrhVQenOI4IKicwMlvX3UDjt4gDqPioh9wuupp/WVewXET95sF02CQPL6nz5iagycSAd+CGNhvWu/VXDUk5Nw0kIpcAECkRxC9tQ877x8DoVnyx/36x357AHKdNjXdzScOtnCh8w4A/tv0enhCvktJfmUuLy2sQRWjBBL8LgsegwwMaTobTl+Aut1nK88PZum0WQZVhBTkZmgBvjWVfpkc8DuP0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad521fb5-85cd-4c1d-a1f9-08dceeef88e0 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2024 21:06:14.3611 (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: ZdijfGn2cMsc9tezCRVFdptYYAieBtsWdJMBzOYsuA8b8dGSbjCMAmdJxKxfnLnxFpHOECgXCHJJQDtmYoM+O1TwbQml9Wp2ErOWLsqIkgo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR10MB5981 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-17_23,2024-10-17_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410170142 X-Proofpoint-GUID: lmNZHbo8Z2WfyRHnObzRSjPJRcNJaBA5 X-Proofpoint-ORIG-GUID: lmNZHbo8Z2WfyRHnObzRSjPJRcNJaBA5 X-Rspam-User: X-Stat-Signature: gqza9q4nrexm4x4e9gfzq6dc1pt1y4r7 X-Rspamd-Queue-Id: B921B1C001D X-Rspamd-Server: rspam11 X-HE-Tag: 1729199173-451698 X-HE-Meta: U2FsdGVkX19Y/e7GH1Ch5EF6Ds51FJ14W6D9Ej7fNni7COPra6tBgcgOF0njVBCm1kZAouC/CrErTixGr+HqnriSWJAW7gEq2ncYti0lDsyBycUEWC1tYZf0mZbd0nsq6FHJl+fpnbBPiciNQbElAJdwwi5cXDE4QpXpHshbvd1Js3Okca4cq/t/LegYCWejaFqomqFbbSsOw2kcLom4wg39v2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dUA1fPcoVjUjEK4FBxJh0Q2LgpzYQv7v+Teq3NfPIVoeJQ0Q2GxyxAJQEhYCxuFXCLfAId6ycxOQlIrjwYAzbT/UzLXq4ttNZ1kvRu1suf37bPKuAo4FzJvfWe4dnPYxtUx2mozEmgo5On1ZedRA4NmNkETci3x5FR0RqkLcT3bdPSv/nSZ1Oes5AIicoy3sLJDF55PMeybBAmCArUojBptmrj9GcfSRSqSJ+Y3gNjuDBVGO5XofmLZPEMo9Pdf0VmOvK/G85UQUfou9Ms32vW9qIF7LfwJ5YEgTQOY1INIS2p5jCWtzetgW05ZbEufwwAdY5EH5ogtHnqMrSvsNGVh/n/wtVvb8XvrV 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 narrows this to one approach of pinning the pid, with an optional output parameters for file->f_flags to avoid the need to hold onto a file to retrieve this. 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 Reviewed-by: Shakeel Butt --- include/linux/pid.h | 30 +++++++++++++++++++++++++++++- kernel/pid.c | 42 ++++++++++++++++++++++++------------------ kernel/signal.c | 29 ++++++----------------------- 3 files changed, 59 insertions(+), 42 deletions(-) diff --git a/include/linux/pid.h b/include/linux/pid.h index a3aad9b4074c..d466890e1b35 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,35 @@ 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. + * @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. + * + * Returns: If successful, the pid associated with the pidfd, otherwise an + * error. + */ +struct pid *__pidfd_get_pid(unsigned int pidfd, bool allow_proc, + unsigned int *flags); + +static inline struct pid *pidfd_get_pid(unsigned int pidfd, unsigned int *flags) +{ + return __pidfd_get_pid(pidfd, /* allow_proc = */ false, flags); +} + +static inline struct pid *pidfd_get_pid_proc(unsigned int pidfd, + unsigned int *flags) +{ + return __pidfd_get_pid(pidfd, /* allow_proc = */ true, flags); +} + 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..94c97559e5c5 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -534,22 +535,32 @@ 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 allow_proc, + unsigned int *flags) { - struct fd f; struct pid *pid; + struct fd f = fdget(pidfd); + struct file *file = fd_file(f); - f = fdget(fd); - if (!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; } + /* Pin pid before we release fd. */ + get_pid(pid); + if (flags) + *flags = file->f_flags; fdput(f); + return pid; } @@ -747,23 +758,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..9a35b1cf40ad 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,10 @@ 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; /* Enforce flags be set to 0 until we add an extension. */ if (flags & ~PIDFD_SEND_SIGNAL_FLAGS) @@ -3921,16 +3910,10 @@ 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)); - if (IS_ERR(pid)) { - ret = PTR_ERR(pid); - goto err; - } + pid = pidfd_get_pid_proc(pidfd, &f_flags); + if (IS_ERR(pid)) + return PTR_ERR(pid); ret = -EINVAL; if (!access_pidfd_pidns(pid)) @@ -3939,7 +3922,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; @@ -3978,7 +3961,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, else ret = kill_pid_info_type(sig, &kinfo, pid, type); err: - fdput(f); + put_pid(pid); return ret; }