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; From patchwork Wed Oct 16 10:20:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13838132 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 C012BD1AD42 for ; Wed, 16 Oct 2024 10:21:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DDF46B008A; Wed, 16 Oct 2024 06:21:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 466E36B0092; Wed, 16 Oct 2024 06:21:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2454D6B0093; Wed, 16 Oct 2024 06:21:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id ED29B6B008A for ; Wed, 16 Oct 2024 06:21:04 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 477B781925 for ; Wed, 16 Oct 2024 10:20:56 +0000 (UTC) X-FDA: 82679072070.07.4D1E372 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf18.hostedemail.com (Postfix) with ESMTP id DFA071C0003 for ; Wed, 16 Oct 2024 10:20:57 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=MysW88e+; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ufN+7XIc; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf18.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-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729073917; 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=QXR574ro8thuG7ssaJT/JSxWpZmz/l/gl9eUXKSg6xcMJ/COxFxSagcKrdAhVy1kxfLdWu 5DAvQKY0QM+xAZSDBI2FI18EMrv89Eju0o0R/jGS/CMQNL7/1Phb/SNr5OgC8MtcPQcxpV tYlzE5vQcipOKI8kcDpErS1hj3XucmI= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729073917; a=rsa-sha256; cv=pass; b=tRY3jFU6/NooBwLuIW2ep1Kyn1J7oR/MPOr8gECbTKBg1XgkXwlj81hNHBLrSzAtFrq+IU 94OpkmBegzwocA7QBeQxICgxAyvsnLtu7iBTTlwj0A3Bj5WXNIygHdpkSDNS5da1xzUf3N uZ9HsnviT0L+//8P0GVwH22TStBqaiU= ARC-Authentication-Results: i=2; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=MysW88e+; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ufN+7XIc; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf18.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 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49G9tbo1012919; Wed, 16 Oct 2024 10:20:53 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= MysW88e+HNI+h6lG219aPoawrP4ud9/NiRLhCqSmqoGhWBAgViBdD1g09bSYCG8V N9hdIs6eRGGyBg78umVTUjGt/QucaK7Ge85VHqmGP2K53gtPp9Z3FZBqmUy39AvD +lXjmff1AcM9260Y4JVnN1z0zGEekSW9IrgzcnhV3z1ZPI226TSTtthoDQBbfazG hXghnVLfdy0wymXfTmzHiGqa7DC3RhnpTjCBGBUj2otoM+9vUNOJTLdbLx/3Gu5G IpzIo+s1JQ/cn41qBHX+EFsRf+AHjcQZ4ug/lgTZx/A2Yez00jgK1z+Mwi5vJijH Oqffg+p0mHsIikb6N2J2eg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427fw2kg7m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:20:53 +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 49G8w0Zh026232; Wed, 16 Oct 2024 10:20:52 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2049.outbound.protection.outlook.com [104.47.56.49]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 427fj8n3k8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:20:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TvWVO2XSdGhB9JY1xd7yX6Wf+ix1sVKJc+seT+BtTpn2ggRn2GId9FgOunB9y7USg0CQX84876iebEMFtYjnio2y+vZPUTa1qGGvzd6kXQtY/Ei2H6GrYz5jt2o/FFnri751kZVo7cWtxlKo90c/6i6DpYD8QiQPu7v3xdSBw3B8U5CinS0btIB4xnI2kBc8Nmw9ffO/4prxIgyn/n1NLykbFExfzYY/NS8Rp5/NlXTlRwx4Ts6yC+3vrhz1VEqjyF5o7UH940+b0YhJsJwVcN47fkRX8o9Xi3eJs8xLRZfkhpC7nWZqZxd9bgN2mL3EIQvolSuGPMtuWR1hWm5qpg== 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=nsUGb8+ubeYpuitSjliwc4VmOH40V3wGpGxf2qn/gTRyyjwBqEInU/ygf/mwoUMcWOrVA6DA8iZO/boQmbFm+R/Xi62f9ieBMnanrNEsiAr4E7TKzdywJEpqpQvYfnBtYHpuq0rkV0Bm0WbPOkEjsscgexLjhNSy31Ts50Fto/c2hDxMZ9xrSrr4TNyFnI/NYGODfxh8RnNXs2CvrrF4LepiW36cTfgl3Sk4QM/gxLD5x1Tl4AGIHZlXO+LiHSpYG52sgDXMaxK8a3j//lZI0tGCtquNZRo1dD928imGP7Q8rrxPUkC9/eqJpNj69BXk/lBJpKZRaYAAeYS98vuDXg== 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=ufN+7XIcYMaIFn/s+HRG6pZxOVu+Fz35mxo0oXNJyOQrhdF0fGf+Y5C+pjoiaYBBNDY7wCBHjng3eOAZbWpw1IIOKPLU3XNjR2QXMFJlfg71fV/PtR+mwEYflhXZiJH3HsZjUpHRXTwtxWKoKvVlDA7g2v2DWui2KPl3EFx0h6s= 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:49 +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:49 +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 2/3] pidfd: add PIDFD_SELF_* sentinels to refer to own thread/process Date: Wed, 16 Oct 2024 11:20:38 +0100 Message-ID: <92f2d057b2861b837f37fae31ccb1d64712539ef.1729073310.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0485.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13a::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: db10af17-3078-4c5e-d758-08dcedcc34ad 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: 1LZeJ3GXQ7nTjt6PnuyCuOlsb+x1l+yLFkgX8kpPjAbH+wwG7Xp/8UC+1YYCmxWHOYeDj6XLSujuhRhFHvF+PTgc5Jxky8ACOB0fCdvP2s22woDaUVsTR5jiBLhbCeX+b9bo83qPGtQi0KS7E4QSHZwT5Y2h780MHNf07I0WPRLaczjT54MHVf7V3GmgOWu4CtgJlsEIc/Wy4jec8MjHQVbNtlPO2X4GF24xRjEqPyrbLEyTbMqTAT+6w4DEHGA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;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: EyRGdDa9RdSc4LJvWDmoA36aRU7S1sWVlrYm85z6Yw+P++oOPAERsNJskEeioWZHb9n4lls9oS5zmsMQOi4OCCLL+arnvAPHPMXVvGWZ0aglgNtPp4Ny4Fu5vavvXPEiy5zh0BAuNv19aJq5kHtdUQ78xOE0hrso509OVjtu36dKdzRdKVnZcQZ7dNt6ge5gZEX1ri8Zxp/xo2J1leT6frT7zg918lN919Z2rALAzAtaq3NA7j4tkpJcdv2CnngAfCfXDfLHY2kYD0CihbCJbKzP/ooPKVQM2Ixd6B+XH7dnwnuFqhSnZzRHKmoZEpa3EBze7/0nc/1buhUKzfY2I+Yjk4/XMA9f0TApez8U+0aHnTSbXuSnNr7rydt1mLo2A2m4q9WjIurtgszq2r2TgDGyfpZgydvEkpbw6aRgnBBBZymWKCd0FGB/v95vw2LOARGjGFft32kCJ0PEn8RV6H0lOAiBvsHwRmPd5zCywOuAqAFZ1P8MtDP6e8hpTsmNn6DEfMk19ijkdDBAH/rynz77Rg8FBYoeXufrDBSy0C5ilxxKMVyA7U9y3S3BTjYwkWd5bexnF1RkPymab2umLPX7wCEjK+tT4a8I57btIyaqtsFAy6z9CuhAv6Wz0euaauejV3n3h619BeaO1gO+7/P2kGxuKodudi+IeoO39h8S1cWJK5nrGuXYgKxkGOswM6rwN5nDhckWHp5oSiY2fVRENqCmpqCb1w1gN3xokNS1rdDO3pM4g4Cbhu4XFXPGoxjBa680TU4SLqEi15uvgU34o9tWjaftj3dcLOu1YtxIzuyb/FAL3LPMFzcowzqPah92kRs1a8LGNvCCET6KLv+BnwWyTgWm6fBXg9hy6UNuCiWmFDk33NFNRgV4k2VwSERtSJM7QG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RjmrLdPprKWYMYpOkA2+iSAzXpnmhT1hxaLylI+btGYZIWpp+qAIpadcJv42b8VvmGEkPFm9FmTY+O2snh48ccGQTUINGYYn0dYOmUjLM6UwHqq2j5SbhC7iIfF0u8ptxr4gXLyy8TLXVQf0Aw1vSEFy9Mu9WGzdiuNNBee2r86OV9lS7A5YMNhqioehXEsA3nO3Jat+NesmInndf3jsx1JUp6w0oWO1+yphx+FJxOmH+Q+YZShW1l28h+p5ASJ5GCNWXzbtbI5BpI33e/BD1MfDHG77QUUe8b2UmRgfj47NyZvjld+5zlWr1MheL1q0oFIeIHCXMgUVVeXRK7XvF84SsaHgkB/AqMQPv4Vy4L20Tz6NeKVU3TD5jcEwIy+ZaNpxVAA5ICDJQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: db10af17-3078-4c5e-d758-08dcedcc34ad 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:49.3393 (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: vGsuK6CknPrB13Hb9yLo2clemJsGU8Bni8w69SsK/wQpCm2BT7Se3A6glzbzAe+0cBGZLDFIfUgBiMABLIkjv6Ia7/uT1gArdC/TM/TzH64= 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 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-2410160064 X-Proofpoint-GUID: trbmcBb_Qmwwh1SdZsMn3avQT4-amXZx X-Proofpoint-ORIG-GUID: trbmcBb_Qmwwh1SdZsMn3avQT4-amXZx X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DFA071C0003 X-Stat-Signature: bw9c3wwstj8ekuwy6kx5f36o99bhhawp X-HE-Tag: 1729074057-427411 X-HE-Meta: U2FsdGVkX1/OXPQAicuvsVYDeA8LBCzw3uNzfSf3TJ8AAnk5nbhl0lLmXgbRcZKHI+0IftIoafwzHWyMAQKfj6QX1zg3Iz3KAwfbzMh2VQFaXJzSJM9VQ5L5VGN87OZFpoeoh/iGmwJ+ZJQMtEIkgKSslFOpWEPDMuSincL/99XXCkEeGxisvc3Q1AejtW/4GofRAfD+Uq5h5YkFALb/VoYqWnQza8Eh17QsTLqBJKnAjDWq+0yuFYinl07AqfwX3AR6Eull+h+gXUnKBLU1OuBkvPy2B5qw4UpiyqVUo3J+YAa+uWL7p3u27saIyLe4o93HLyiLZsmKkJexyqh0GQ+6Lcxrfp3XTD3fDT85DjgOvEN0ObTKMGCkjeWXwM+sV0m8xFAlPbkWYgwes1Dqsks29aLgJidekpHegGXz8D2HcYQiZScMu4Aws7HeqDdO3eWeh3MyFohv8kN6SmfFpQGnM0bhn6bCSPfF1UgigAG+uLx+P6zlH+FOmiIWA8klpVUHSPa2S2iMqkpspb71shgYXWAM7dMM1+vvSKT0RNlctI/t1mbgS+O6+K/2YhtpiLEL3j1eRFUffRsuiVqcyDrFRjAJyr4wZjjrbvBmIYEjrSIfBWfUMj0gDqucwix8OS9pdJae5EGjSCTOnkGrqy9VLvDRUu4wit5cuACpYpkbi5BXJxqdWCbuG5zw/8NAeV7MerZ5G3PJ9E19BojiJLA6vTAQBAMr6adlATD+M1wutJis+7D69B6iljfYNwL+cDtu8sUQbp7Zmo9QRTDirEm5I8SpCxbeWeOTk34VRcFYKWTKv0emsOawYK+SJ1z+BLGlli7LQcLdD7rvGYtJMM9sKgnE8JIEvtaiHfwLmhcUsLg9JQTuwPXrHL/W3v/m9tEt/pU5WCesMPZKd0eRt/iIGPirdHYKLaAUcDe9FLzP1B3t0pb+SaDHgd2YTyDnZKHibjiMaDLvT1LU8qj GjvSRIpS 1IPxX4UvRDMbkWXIRUGscNiXr7lNkxom+LL5c4tjFgxSRgD6vWda7sIu41Gm0W19TfcI2elV0ad2Zk4TceHuuXmgmBgbpYR64aG7/ruHAj28M+HjkzSWbErFCsQ2glZhQhaZ2Ei14YQRCKC+nK/dvajqLaynn2gfCAYMqy78Fgba/LD2vXsKFr8b+0QIW5cuSV7RtuzgmF1YmyqvZhHDtHYHw9AXJ6yBixogI7p9UlJPg2ZRoXbbWMGAfrM4xlOBy+VfePBRkeIh8a9x43A4XQXzK44Q0XTdU+xP2DoPwFC+ny4ntgTyf/x31NQ9mXbz0KKWS1t24i9ch5oanPcux4Fd6GJYVxhsTCsT711yrE5sahtLae6Y3ng5UWPVY5n5Ed0AJacliQCTlyE0G8oTe53ZhkwN3Ybjczpz0t+DyN26CsSBvxZTZYw+kE/lVI/mem3ZWO5OB/dNxzAr8tzxyTVNyFGs4lFk1l6u9fR9c9v/kN7uQF86W0bokw2tpVMYRzfHCbt/0BYATfseaMNWH/VUf7PuoXS+7JV0XRrFxEaxMwmN+Gy3yFQo8LDQaekzkCwt2T7NRRvGXQkXOBmJx552Gn0Qg8xBA3Sk2q1MC1Ws+8cVE78B7t55QqYg/vaQnIoFbuko0n+RD6C1EMv+TakaORH9okNrN8Lb78qXHxwK8Q9Lx/Gx+8yfCBOviH0oLaWHSpBXAq/Vn9JE= 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 Wed Oct 16 10:20:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13838133 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 BED08D1AD40 for ; Wed, 16 Oct 2024 10:21:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2C5F6B0092; Wed, 16 Oct 2024 06:21:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D8F6E6B0093; Wed, 16 Oct 2024 06:21:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6AFE6B0095; Wed, 16 Oct 2024 06:21:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8FBAD6B0092 for ; Wed, 16 Oct 2024 06:21:06 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C9824C01BD for ; Wed, 16 Oct 2024 10:20:55 +0000 (UTC) X-FDA: 82679072112.09.C141D16 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf20.hostedemail.com (Postfix) with ESMTP id B55E71C0025 for ; Wed, 16 Oct 2024 10:20:52 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="Zn/X7IVk"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Xv0TLHqu; spf=pass (imf20.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=1729073871; 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=8OMscRhM1e5UeUz9mTjB1wU0KrTs062PdbrayFnbb4aL3uvmJkiciJ8C+ZunxiwwrFuG8L 2jSSBFfxyD0wjgej7vFT8rSAyaFVPSxYenCB5F+DHZbiedbhTQdlvCnNHZxBax7CrAsslm A3rb5dA7qweWtqSzVlCNF4YNqW6XnQs= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="Zn/X7IVk"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Xv0TLHqu; spf=pass (imf20.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=1729073871; a=rsa-sha256; cv=pass; b=zMjQ2mYSj4FxCtvrQUYRQp5696BLzUK0tsaz+JIshBd08mbX/7ra96Se6xCnGjMo7gYHov rsOWzQmzBLuo7KKT/W3aH3u3flOy8jzyWwW6ke2d+Kp8PyWSLZrnTyY82N34M+agT1kl4x rBLMJuvGaZFw9nh4A4OWWpbEvUB4Kds= Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49G9tjaR022244; Wed, 16 Oct 2024 10:20:56 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= Zn/X7IVkbdv2SjFSFumlCBhE8eISKx5Ae3Hx5X0Ugz1jY/JA0n711JICv/MUV0lR JKEtrMyC8r5jBG7JV2xYvAlK/q7zVpDXrcfbMhsXlPvVeQqbstsWHiP8BQkyBBmY hV+tFFBSEn51lCSlZoktU23ztlDUW0lL0m0MoXNbZMPM/VBZN8kOlBfnQgRiNW5Y KwXThAVgkv+PYwMmbZMXniFgIbnnNbT9n658MwMgbp1+q856KbvuI7On8V/cGCqA 1aPM5Vsy3sC7HOW49v05wpxLhl0yaovncMMv0eQul6DCg477LlchizehQcxoAz6z VTH5afPCVWRwhQ7U7zrS/w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427fhcjyuk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:20:56 +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 49G9xbWS026283; Wed, 16 Oct 2024 10:20:55 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2040.outbound.protection.outlook.com [104.47.57.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 427fj8n3mv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:20:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AioKK+OdMVSWIvLcnKlQIHFpxT7OFgiy8qiEvnaime1oMl5EuZyEVAWfwHpCkSQVwuL3Wwzli+1f8LgkU9yMUaQyo+FjmleVH4lbiazusotwGWC3Y9ZXA+lcuwKQVJW3+CTPXcM7SRK2l5imKxo4OvS9esiFW+fKK5/HTnacI1gbLpf42yBPox4c9EXAaJ9ucFgyy/9gN8bHmHgxarEZiy2Gufv0TxdMTI+cyBvsIHuNfdPY4zbtdH6SF27rZFTZ9nV0IanaMfP8U3etlscGGSugm6BgHBqlJ/RDu8AFNjCj2wkGfmWduDk9xKhfiH9/tchDaFkD2iXPjzUU32kbWg== 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=neBy2bjgrUnpNq1Hd0eTi1c67M/B3DhZ+2f/Z6WMsjCWZ6sxcD5LkhXzjkX9b3EG1WNM/5W6N+51CSc7d9xB83jlMmvjwwcPJ+A+XNY5Xo+UO2ooV5K++7ZnyEJMXt6Ku26Pz7nVnp86qer4QKsmaL/RaG4kVb6ni1PJdW1nWJW9ei/LOnp/nxQDWxJLrT0LCN43Iv0ZUz4/iGEsZcxUbIEVEBRLtod98LLhz1BYlfR1NeSMX+/O+KMAPoWM91K37A/M6aTxBmcvj7CUYL4u0Zv72Tih7fne41j6tEVlUhurMC+Z1ujeMzDgWFa3HvGMQcsQ/N3p135JT+IAXV3sjQ== 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=Xv0TLHquU3wWssdegp9KsRrXTgFIJBIlOJE9oimEFtSy5wcIPlsIdzZQLGX6rPsgHO59tcYdbIs5s4CvDDSeVhhXG2kzaZ3sa727FG8R3FkTAbbQJc1S2am1d43ydjr0apCvlQJLF9a3HAMExxYwT+fktDCRmQ34aAXyscTlOc8= 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:52 +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:52 +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 3/3] selftests: pidfd: add tests for PIDFD_SELF_* Date: Wed, 16 Oct 2024 11:20:39 +0100 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0307.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::31) 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: c5e32e5e-505e-459e-8d66-08dcedcc3669 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: y4AIyedOtj5y2VuKxnJ/23cFJuaa4VKLD1PF/pFhBc6hcR5zcKjqDQmq/w2oquVkJeEtKShIOVe8ueAtK4+9ZB3FdxLlot6LZ7u4kGQGrh1pbvZTqUkbk3/Bpi0C/bBD61egiU/QVMEWfagnPFumTK13Y7Y0qB+8KECFbRCfamdONU8atdOOrMJu4QAG5FDYi0JLSzU0MOQ7/rQ0LEgCxhsiIKYAkGWraCE6/TjtgvRDChWzWCir7kl/zhC5hSrkujo/tjYY/RBJyZ/CUN3NAjGx19ollAtKk9AMhnI4wgeG8NBRgPIl3OD81fz8bwlDohKtryz4G1ReCXaWiM3vPC9w1yQGoT8JMn4eADOXJW6T9DsAnlkBaFr2MCfVOZ5zxn175nHKptGzGmQneRF3buYxwcw079rwxZryKGvFkUzq1n32GFzNo/4GqRJA1UFRKIxh8sIneJ79xQojdNjuymM6ObY8ig+C2R2HkYyezZOgOlVDden9Sv8AXfQx/efPwuelfpIGo4TqlmKOb++j40H6G7/PUhZHxmMziIvMqlmMZnRuf11DBV6uno6cDoeqyxhgy0xaVEzFx54DtuHSaTKAeD443T79ageoJubybdyZJtFMC+9rgi11xIvhwg1HLja3q0dslPpPGU2nRQpXYhciv8p/g/MzJIU19WjF8phP64OMQ+ks5NVwOEJO1Z1l/eiPu24Iv6M1MqPZbj9Xu3WmQMVe0pMMdztZGU1vGlDhG3PsB8om6f9I+k4K5+/yNpjEElbmAjFgbqn4pkoaTwGx6xD9huxit5nRZ34Zu0ivcWiAw96Zbs2qwAQdjjzMv7JDJOTSQFHqbSd0YF4NWD5KyWhNszYYGyU+wTpWwrYoBgnFUvmEeK4bJ2Juc9OGkAR1OKOvZ7YcnoF/xyVXeEIBIGDCxKpv1q/83AcIMjJQNYbGaHqZTA/2ez96y3O3Uk4vAuc0Bi295Tc97cW/IHzfsrg34cqmlkSz2rfYpg4p0mfcMqaNZw+BPJ++LWiqWc1qUABbCAFQ46pnIw+UCThw5rbaLQBtvO0rJkh1udNyFInMF7iyrp52cSB+NHJFDuLoCiKuAy0uvSB2dEnOMsN87VK+EPzX1o/dcZBhpPCqVKZ6QisnmcE/98Dle+Mw7hArEE1fUjekn9nnHTc4kQXVVzpfz84ol3+yBH2/RN9ClVG7HrQLfIlJw9dtDOxfHfyA3vYfhu0UjpeikJ82JKxJ6Dk698ZaCbLxm4i7fZIMvupGOhBHWo3HR2vWTft5 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: dWKbAx/K5gIO8Ff3koqHPh26ggjUr5gE5oZpgKmD/setJLa/iYdCZFcXk9ON4Lm4lEiNmM+KVqwR5HK20PU6Bu2Ft3v18C7tA/iIFKLHKDRaIjTBcHhMMNQJdKBYOzFubBmHxhOQ8qYEPXDKFSbJT8vIdkXqx9n51tJcFeNBJ34b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fGV8zTE3lBvpMZY6pyK8BXxEQIp4R+9rDi+CJRPA+QFXIuVMlLWhYM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c5e32e5e-505e-459e-8d66-08dcedcc3669 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:52.3841 (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: ID9sjXpRpZgYC8h0m9aM7xD7iWyvEDQjNg0VoFDZu3ww7ZaIlgjDjaa2bPsipiOM/AyP5kmJrI9lBjkvYfUlZuQ1A+Aa9PuQrW4ZyPvKqJk= 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 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-2410160064 X-Proofpoint-GUID: AaFJVgT3LBv58RGyEibGWiA7zZPvlh40 X-Proofpoint-ORIG-GUID: AaFJVgT3LBv58RGyEibGWiA7zZPvlh40 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B55E71C0025 X-Stat-Signature: ycruj8easgf8o5ky8qjc6nxz15q6q1it X-Rspam-User: X-HE-Tag: 1729074052-386312 X-HE-Meta: U2FsdGVkX1/ihimJdLsqW271Ua1pOviKUoVp29f5Kpxp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ZmYA4R2xAZpGuazLS/jkiWSwQpTWOyNIJuLvs4MgUqJxLvfTtLD0tr9cxaxX9Yz/GD9U7MmM9jgSSvPkiFpUtmIC5Z/1OoBLxO5fssz10AFcL3Jz5NVi+HbNbbPNsLS/llOfSQry2KOO6A0ITFqGc1gSWaKAAZ2F8j2QZtnm5aT+ZKt5VPftZy0rU9W3JB4LMFVPFyvlw1J4KIFncMEpRZT65vpIYC3IfCVo19I6TVrp3dNpMNWFkk7BvlI1WmxDgc2ErCDQMeH/GdFKvv+96dgJj9kPEf47ohLIu997ezPKE5lIqK0QYSskrma2BdrwveQrstf9KsiEDnz3C0/dZBOg3Ir2QluJRaR/bO//+LwvR4ginOBnC7/YhZrDQ0GY4CnBwSbOJNdWR4fX7UUU6d1p1/g3HKixjl896ksTCnC0U1RRXTu4y+9Zq3PwXypV3rnosiW2PDv/wXIU4sgUl4Y978gD4DvTX5byvG7qGyMUfZJAfKC1BnPf 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 Reviewed-by: Shuah Khan --- 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; }