From patchwork Wed Oct 16 10:20:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13838131 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 E7992D1AD40 for ; Wed, 16 Oct 2024 10:21:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D9086B0088; Wed, 16 Oct 2024 06:21:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 663736B0089; Wed, 16 Oct 2024 06:21:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F13D6B008A; Wed, 16 Oct 2024 06:21:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1A2156B0088 for ; Wed, 16 Oct 2024 06:21:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F0D31121B69 for ; Wed, 16 Oct 2024 10:20:51 +0000 (UTC) X-FDA: 82679072196.14.BE6AA2D Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 07DF540006 for ; Wed, 16 Oct 2024 10:20:48 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=KxKoo3cS; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=K26Mndjd; spf=pass (imf27.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.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=1729073983; a=rsa-sha256; cv=pass; b=psI9i5W+UIb393lpHExt4b8q+DWkcuN6KxBBZV1+opm/MVDPluzV6sdn7OmtCfg6fZaPS1 zoRgThe949lLu7Xb2sxz2Mb6ggiIHRZaHvZQDKTsW8Pj6K1JwL+6POPpucxFG4dwFOmrEg jWAg+6Ukz7gL1Mlbh7TZGfVoXoNOF30= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=KxKoo3cS; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=K26Mndjd; spf=pass (imf27.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.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=1729073983; 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=JHJgtDsWIsDsEYWeq5BH9WNV9u/wLw2axBkIj7l9KrU=; b=l98XE8rMqydamBjIUHoyZXJqz09w9Obj8rd8inAAvC8LhKpmoqVYy/C5sBb+5noL7GQ5AO G9v7eGg8l61XGBdd23Gs4Zh9n3mGQsPMwEYSaVJt7ORCjRGu1daBe59cEMlWTldHoEI09+ iO1K43F2JezCYhSXUw7gj52si9hYycA= Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49G9tdpR001094; Wed, 16 Oct 2024 10:20:51 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=JHJgtDsWIsDsEYWeq5BH9WNV9u/wLw2axBkIj7l9KrU=; b= KxKoo3cSivDumOMk1/twXMM6lUKRh/h5XEesTLxhYjDpjg1O+agHRvRj5NCMfm/h 9X3ln9XQHhFKJmheqE1BENB+OJw63+DnujiPfvUm1j4hjyqYuhtdAd5zVzQohwha OitD8pUC6THcuOsL9761B/PqxS0V1nfdGpyHdrl2zdVeCDGDc1rqYPeBv/wDR3vV Bvp4w0yGShPOpWli0mOW9Y1u2V+XUtBLhLOiGRNMhs7sQNnvMpqy5TtKipGH4+7w OJga0+LIJL895/Fu80rZ9OFeF8Jh93IPOsoQWr2ZvvVy3ju4PNB1ohekFXi1OOWK MquTTEBGJohGXf/9W1GaoQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427h5ckqms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:20:50 +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 49G8hKuJ019983; Wed, 16 Oct 2024 10:20:49 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2048.outbound.protection.outlook.com [104.47.56.48]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 427fj8naje-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:20:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p+JYv9guearlTL7SVwq+v5/g2KKRCyuC9DswEnIJfWrX2OVd87hqELPX9eZgc9dJtaydMX0kGhBFyKDWakHzwUyTiAEA00Yz/EJhuxMQnC98mDpCht+YcIwnaDrMOd/3qF1t/jhK+bZ3S7ujqyOtcInXdEsoC0sWAsAyivnhI3ObxikT1kxNcFrE9diFCrnMrEn2AaD95zwSVc1qh/Cjx15QVPqWSHWCDyWD1pdYdQ3abIz+A1BMINlOwmceFZ+W7FpLg9fLRMGelTZKdr0DCaL907A4KX3cXqtvSKha3ardBZo/1tpCs3x9VkDILTpL/WTi6tXq/nSPQdH0o3gHYQ== 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=JHJgtDsWIsDsEYWeq5BH9WNV9u/wLw2axBkIj7l9KrU=; b=Vukgd+/p437s3+d3TQCYVexjCGgw/L/UJOiEkC8zKYXp6WWDq7JZxEQkOJ9dp7pt9YxcGsEx4I1TwUarbGni0Dl/58vP8CtUuYEk/fVrRQegTQItcP6TzNdtiXGMcnp3AVEUv0rUDAHscEIjcZC8/mp8Kqgqbk9fTEvJnBZjPpXiqukoR1cmTUZZEbXz9e7IlYI6ZMhe0mzCYG22a5jIa7Cd5EAMqmSdfxRnCG6DaEAd2lUv8mRyz6n7bOsgV5L1o5WLHyBIZLlD/FN/+Ea/3WjtYR5pudM24lftqCJxP8CnY1EndDoMpbbbJllISuic76qDnj778jCArsaaFJwWYQ== 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=JHJgtDsWIsDsEYWeq5BH9WNV9u/wLw2axBkIj7l9KrU=; b=K26Mndjd5pXcZSwcsIYsrE1HUSRQbNRj+AwR6HHMAPwvAG2NpEQe7bva5FQCybGVkd90VZRTCcHkWyLl1H/hLtUe7GI3KlI+11ahIzvl44NKiNX/fApkPDQoyFUtRRMpZ1n5LslnDWWOwvQ3nyNS6WhnzuLwQ0KZKJbJxYZlcAk= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by IA1PR10MB6172.namprd10.prod.outlook.com (2603:10b6:208:3a4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17; Wed, 16 Oct 2024 10:20:46 +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; Wed, 16 Oct 2024 10:20:46 +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 Subject: [PATCH v3 1/3] pidfd: extend pidfd_get_pid() and de-duplicate pid lookup Date: Wed, 16 Oct 2024 11:20:37 +0100 Message-ID: <308d25458297a859e514132dfbe5c28a338ba63d.1729073310.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0113.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:192::10) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|IA1PR10MB6172:EE_ X-MS-Office365-Filtering-Correlation-Id: c597b00e-a428-4853-1af1-08dcedcc331a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|10070799003|1800799024; X-Microsoft-Antispam-Message-Info: ATKJ3BIUWRe7MMAq+ZtmnrsQ0LJdLUX88zBAHoOlaZe9+5/MKTa8v4y3jWe45CSfTp+UgzuXJRp90iYubbb4mNkRt3HLXpIl/mqm2MYJzwr8mchuRcmT33QRb0fX5r/umXbSxBY1zrlNzsr0DBmgj51opIQUH4UEQwinogSQbsQwDVBR1oCS+aPKP7TgdeEfWzgSkSwaT5d6WOL9tidUGA00ONdpEDL3R06BvAbKLF55wuzGsuLqf2DsYMGOGPZgxRKYR+iISqFHqx4PAt0Azxhpr3vQaLdgww7rP2m80D+LXodclfQCEh0I64IIL1tm+T1di73174XMkMr45iWeY0UZYVTdRbySqWyXfBTDw+H88JIgeesvwNLhAwoE7Iy6hFv0q+/G+R59G5QrkET9bLxDJLf+H1GIcmvxErhsQSvwHfGSME61rBPbCxFSyix3d1l2gGPmKU7iDb5Gw3RUl5k4NSBRP/t6sNs8l/PVShyxUQC9RS+eQ9Mu8BAODomC/qd9Vba9aJRGsh8BngkmDwl8iOMYe8gjQLd01ulkwuMTfssSjTOBl0oEPmUkdE6r3tqtcMqYFKhmItANAyfxGTmjqL3BjP6VscXpVPa++dCxdPwYFONf4B+bXjyvMygO03scDbxGeY7ipj2sMIUwQFCD08MyXLInM+sfNJm0ru2WGV+9qzNSghBdcl/Zy6zPMJmV5aaw7NdTL0vtVKeVOT3Fa9lTaL5gVA2BIICCq00fF0JRpXz6TNp+RR1/6nyt5XXDMiAOO07z6r+UWLZwR53qgcj2YKAXb5Md9BDQ6VA2FFEW+kl5HqVMe2KaoL8opssMwcbJJQIv8ILPGGlHK8jX4BmRmlzWmZHEAZD1S1Tc7r5V7vptFzFi2tbGDP1vpq6DHZ6hd8RDNvXSwOQnQJ2jvueVOxJ3DGdatoUgUa0Ir0/YnwNEX0kT6gFgC9MDEYtDErsm3V4YrExuxAwG75atcRirf36LCYE9fLF+K/ZdepVanN8U/UbGSxwZk5iJI1p01UkS9uJaeZoD0zloe9PgSMFEtE9UHSqPGZZinvpMDuLIzBcM8QALNnPUkXlIChvd4AsemBUffFxvdiE1vA8w6UQB1vQsHG7GRzqztyhzicgOIpX3mL8iHKP7gCPIeO7ldzzMvdSDtHR23efMxPZlbGcP9dDdxEpXGt258eN2xWjjfgdFiRmc9bgRkhRAmihzZKYwxjkIzgb9xUDXb6HvzxxIhbCKqhq4MPfHUgxaXYvrQnQhuzTXgxdJHEljB4aI5Mx9cLP8GpRurFKjXg== 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)(366016)(10070799003)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: awlMvH82YoA5zBti/3uL6PG+/j75pS2+0DVC31Hz6VXFFhyqhlO9o55W6M+2x4S5wSMOO0E2di/y6M5HfcyQklHdK88iaFOEyK8h4XWVksi8cczKsDVLEKUt5HBHL0YVbnABnPn3+9o/ZTXnFpnTW0FC2OwkM2FLZstCalJld6Es2FTZEE0Kz26rmUZYWqr0PvvdSjgGkDTtV6HtoACzqgRfeogKHimZANKfESDUDFNdF+CxtKrh8H3GExVUCbqwzf/JeqyPtH4+hD+1YinONYlGmfFUqBQogqxIbxJ9NRwMxq8GkZXuKf2C/FOai+BP6TcwjLirIrqPwZYgUerVuupCMipBYz8f0F6pRFabDPmj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K4tN7yzFr9EWL2jGXairXkN1+BWAYrtn4TT27NPKJm1qJ5vm3yWCOuYCuahCtseQaUmOnZjv00vQty/kaDx9Q+osd8FZyWiXNwdb04hnHRIHx9BHGWn9HlssCOc71aYz0bkDD1xjd//9VbqPjvvlLHuFXoJLkZ4Qm+P9S9LRYeoGRke07Z6O/35cIDp7zM9dtYepR3Fo3OQxfa7AQOJdbOXNPbB+Bb4LXupcjE9AA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: c748uBcxPmK4+ky1qNX4TfJFKW1YgsDo54FrLxbV1v3ke13zjsazE6Y7REO37lu6FLe2aHLNAKATLR5Aj0dwc3f3jCv0Lpcp2QLB1tdVC3kcANvguX2xxHVvNFNQ13reIikzQJylcLHeTHJXc4VLKrx/ZWaWMXve/XN77DQTRW+zjiZkSb1xhHqYoFUrlhrZxtvO2g9eVSrn2DRJVzumlE0HtpEhDfFPx2feiPeuw3CmK2ygOPq5i9AaZcU5US95jLahrHrlSU/YxC25mBdRuXSYr9WyiJEsdAsNVCvea32CkJhViuObHd13+aOv0EtCMnlM51dPPY+vhoauoFmechrIAr4u4DPYQygPHZJWbPfQyfGnuc2nW0wuWbGI5q5KOwYI3KfdOuhlcp3zKXdhiCUc8a1dJXgIIeSJdQ9GC1rRfWM5jv/j8JvUIhDqk8yUCt22dCfp4gv9dT0WDCU+yXkr7mjCYyZj1HSvQAlyH6Wuywhtx7O26c46qKf0avdrK1Wd9KFli+BRsp7ypwrAZHDowjmhXvaqFU35RLEBbj3drBrITEQOAKeCAo6ilutNpg84LiSw0sL04QgyicesFt40P596y0EWf++gakFxkOc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c597b00e-a428-4853-1af1-08dcedcc331a X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 10:20:46.6940 (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: CHLtQlUSDWpukzs9fGPZaEAgnHtBIyWmf01s3sF4ze0KmDbvvlR0MVpYvesiHTToupa4nc+ErDSZTLWCRvcCvU1gFZ49gH48H1d15lhnuwA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6172 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-16_08,2024-10-15_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 phishscore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410160064 X-Proofpoint-ORIG-GUID: Zjm7jSMIl3mRK6LCXShV_4m-KTrK6dDf X-Proofpoint-GUID: Zjm7jSMIl3mRK6LCXShV_4m-KTrK6dDf X-Stat-Signature: 4iae7xwa6ndtjait7owpyufd1azxj1ys X-Rspamd-Queue-Id: 07DF540006 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729074048-112767 X-HE-Meta: U2FsdGVkX19E01dmjwsi/o+NMMzLNpsdr4hmFlkB6cILj0JCNmfk4nMLP46Sa5x4qzUnUNfncWBRp5a2DaZ2IG394+u6PiTlPnwvIH9Lokyey+CmDbmdR3oysI8eqt7mFmwXdCq6q1rzeaDc5qYLJD1vuTr79pDDji4z66SXQ3zLBoiH4zCD7TV5MARkjkyA3b8sAoJqOVY4ALbXJq+dHmT6LKIWAWAbck2SUZX9XOs07xylkhtrRSD3aKPpuCQzWEOvuo2PZ0iPoJf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9lSwg2TPG8o1BG2pHdL6Pb6BKWzHsd2WI0YkS80InFtNcfKPYwGT/AkSFtH1pNniHwSks4dbsk1HFJugoXbnMWoW9RWBtZWvX/KC3MdT4pETHTjDIOs0R+yZkBvaDxaELTkxoSouPyIDFpK9c5+0bRGEjYDLF9TVQJFFBcNAFsF9uLkVWW5YPdRNWWysVy+kx85NBEQ/Ws733ZyNdSep8+IC/sg+UOxReXNdf6G9TCT2H6AfarFx+Q6Dj/yVTR3AmEP91iKgNT 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 | 26 ++++---------------- 3 files changed, 85 insertions(+), 41 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..e64da346a90b 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) @@ -3912,6 +3901,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, 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 +3911,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_to_pid_proc(pidfd, &f_flags, &f); + if (IS_ERR(pid)) + return PTR_ERR(pid); ret = -EINVAL; if (!access_pidfd_pidns(pid)) @@ -3939,7 +3923,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;