From nobody Sun Nov 24 20:37:46 2024 Received: from fout-b3-smtp.messagingengine.com (fout-b3-smtp.messagingengine.com [202.12.124.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE80E1A4E70; Fri, 1 Nov 2024 13:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730469322; cv=none; b=QS8G54SserF0p/FNU2o8rHI1Xm3jiaMVbuSYsKcgWaKGxlBL3dn5RwpwR8U9OyLFq1xIim+ummjUxyk3JqVS9ApB+d13IbkkXcEhCocW6RuifXEOkAOJSJ+qmeVpBHCCswcxjnHPUxYoodiCF7X0cU4ehBKMojR5BlOgeNELR6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730469322; c=relaxed/simple; bh=mgPZr/2l3Vdj4PWdgnHmZvjQV6jfJRSwzIH8IQQ/Fzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PPKqtYOZlb9kOptit67ddotmEKtkHQ6oMEra7HyiOzdGWsfF9Dn4wLU8pOt+OcvQ4+2P/HPoGUFC3B0K3cg8RcjvHLH6MmV5ILp9WocauQkCc9PmpMuJkRxDduI9wW/h5azs2BU2uWZJVrMOwXgEtUsZZOi0RlJXG4fqVmGj8EY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=e43.eu; spf=pass smtp.mailfrom=e43.eu; dkim=pass (2048-bit key) header.d=e43.eu header.i=@e43.eu header.b=guDDIzi1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UbwuWuXH; arc=none smtp.client-ip=202.12.124.146 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=e43.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=e43.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=e43.eu header.i=@e43.eu header.b="guDDIzi1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UbwuWuXH" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.stl.internal (Postfix) with ESMTP id E09FC1140115; Fri, 1 Nov 2024 09:55:17 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Fri, 01 Nov 2024 09:55:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=e43.eu; h=cc:cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1730469317; x= 1730555717; bh=BlFQzpSaBBPnijLCt7o+tl9i1lAU4R5ZjW5of+lcDtU=; b=g uDDIzi1BzeL9Y+TnlBGQJ87tEz3wKfHUufV0HOL3RPMh776Jt/fD0iO3Q8SbMUVe PR4keUGR1C+26lHcMP76xhP4Z0zjxf1fCBK3PIC4C1tboswJh63i+Bqp/R/Mw+z1 38XerA6a1yVx2RTXxvv3U6K8NGnYACVALSq51GBzrMUIKrhn1w8zJ5gAGr9k5MgC uxwlYMxc+5O3lswstc00PWBqB9aKb8zm0IKJ1Dltj86dZUhgl76XoIR7OUrvmCRj LCX17LVUceRmX1ZDRyS8B6UZc6Id2yAbNXsPdXN1E7ZOtavNJfSrelVOu/ATc8Ej qdT4FP5AIXu64XtSyzsMg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1730469317; x=1730555717; bh=B lFQzpSaBBPnijLCt7o+tl9i1lAU4R5ZjW5of+lcDtU=; b=UbwuWuXHS5Ja1ZR72 UIGH/Jt2/n9fQqG60gcXcu+N0QSdwwMUBddmgN9Iu/W+QP4hKiHuvKBwCnBo5OwM f3NJba+Gm1yd8gkrhVWSqGZ2nPVjvbrPDO6n9XwjNictjEJc6uTQL4RZspHhYjgZ lCD9HjS3JX7cPN6W/Z9t2N14x3PTIJGY7cws396clThP3QgsLFoecLe+dehxrOSS ytYmc4Lq0LWOx0ta87RW2HvMUjHqpQvV67U26M4nWlfsc8HroCjOTpN1cTXtJOpT 2FgJ7rwosxfVxayrENgYT5yHJGKkI9jeoCQOWbRYt4aYwYRid3aETjsss4XqW3wT bpTLA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdekledgheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefgrhhinhcuufhhvghphhgvrhgu uceovghrihhnrdhshhgvphhhvghrugesvgegfedrvghuqeenucggtffrrghtthgvrhhnpe eggedvkedtuedvgfevvdehieevveejkeelieektdfggeevgfeiieejtdffledtieenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegvrhhinhdrsh hhvghphhgvrhgusegvgeefrdgvuhdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhht phhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqfhhsuggvvhgvlhesvhhgvghrrdhkvghr nhgvlhdrohhrghdprhgtphhtthhopegthhhrihhsthhirghnsegsrhgruhhnvghrrdhioh dprhgtphhtthhopehprghulhesphgruhhlqdhmohhorhgvrdgtohhmpdhrtghpthhtohep sghluhgtrgesuggvsghirghnrdhorhhgpdhrtghpthhtohepvghrihhnrdhshhgvphhhvg hrugesvgegfedrvghu X-ME-Proxy: Feedback-ID: i313944f9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Nov 2024 09:55:17 -0400 (EDT) From: Erin Shepherd To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: christian@brauner.io, paul@paul-moore.com, bluca@debian.org, erin.shepherd@e43.eu Subject: [PATCH 1/4] pseudofs: add support for export_ops Date: Fri, 1 Nov 2024 13:54:49 +0000 Message-ID: <20241101135452.19359-2-erin.shepherd@e43.eu> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241101135452.19359-1-erin.shepherd@e43.eu> References: <20241101135452.19359-1-erin.shepherd@e43.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pseudo-filesystems might reasonably wish to implement the export ops (particularly for name_to_handle_at/open_by_handle_at); plumb this through pseudo_fs_context Signed-off-by: Erin Shepherd Reviewed-by: Amir Goldstein --- fs/libfs.c | 1 + include/linux/pseudo_fs.h | 1 + 2 files changed, 2 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 46966fd8bcf9..698a2ddfd0cb 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -669,6 +669,7 @@ static int pseudo_fs_fill_super(struct super_block *s, = struct fs_context *fc) s->s_blocksize_bits =3D PAGE_SHIFT; s->s_magic =3D ctx->magic; s->s_op =3D ctx->ops ?: &simple_super_operations; + s->s_export_op =3D ctx->eops; s->s_xattr =3D ctx->xattr; s->s_time_gran =3D 1; root =3D new_inode(s); diff --git a/include/linux/pseudo_fs.h b/include/linux/pseudo_fs.h index 730f77381d55..2503f7625d65 100644 --- a/include/linux/pseudo_fs.h +++ b/include/linux/pseudo_fs.h @@ -5,6 +5,7 @@ =20 struct pseudo_fs_context { const struct super_operations *ops; + const struct export_operations *eops; const struct xattr_handler * const *xattr; const struct dentry_operations *dops; unsigned long magic; --=20 2.46.1 From nobody Sun Nov 24 20:37:46 2024 Received: from fout-b3-smtp.messagingengine.com (fout-b3-smtp.messagingengine.com [202.12.124.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 577C01A4F19; Fri, 1 Nov 2024 13:55:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730469323; cv=none; b=D8wsiTwrkVZpR80+UuTvwaYK1n6/EeWyH4hBpbvvAo5IN3dLOOep5Wem+k44ru33o1pFuQwJbNh5wwe3JB8PwNjaeRYOokLXdQUjBmqz7mDb0KTNEeXMSBRChzDn1mkjZgPsy0dsDsbXBIY8SDmt0cri2lIh3ZvNsWRy20uF/sU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730469323; c=relaxed/simple; bh=5Do7ib1t9wQVq/1iPe/AkeFeP/J3/r4KeqETrfO42PY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jQJrC/gzaHc7nJzaREiT+vHQySU2AUSgro10A3OSfsawXT3lzIsJJXHtGjLC03HEbpNkk0XoAYrVSa6HgHbaHoZ7f2uGfI8mPbxVHfWp0J4ub+wmAu2WnAKhlyooEbbpl/iU4KlYqFIeDQNtCDYisPpVDWvU9sUxYku8WePxz6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=e43.eu; spf=pass smtp.mailfrom=e43.eu; dkim=pass (2048-bit key) header.d=e43.eu header.i=@e43.eu header.b=JkCUprLn; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UjRKYQ1I; arc=none smtp.client-ip=202.12.124.146 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=e43.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=e43.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=e43.eu header.i=@e43.eu header.b="JkCUprLn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UjRKYQ1I" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.stl.internal (Postfix) with ESMTP id 6C43F11400F5; Fri, 1 Nov 2024 09:55:20 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 01 Nov 2024 09:55:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=e43.eu; h=cc:cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1730469320; x= 1730555720; bh=vbcRh1xLMXs6D1grY6D0p73XgEN+cd/HL4E330kHx6c=; b=J kCUprLncek+LzEggD0igyOs90C6oSDpQBlltIfHM9SMjdv8LisciQqMXyjH0mOzJ HkvzzemqzpCsda8hkOTzDjXuiLsWrv7K+CJPnrQNPBzG+I45sByYeXyY+NmuUTUg QAxV+/Snd+QOkmnJS90Dp6CfgsvZk96DLjQcVkRcmPXTwu4BaomPlMUKgNnzuxHm WrTJ0tPSF9rLl8AuHWsLiguZ20/Yghz8df0/As8MpAotcyUadpzui2H0xzpRTzxT iEjpyLNTyq4bj7IDCXjwBBQgRVPNL7pCSwNlDdp3kpP8O79ESZN9mNSSaQuVkEcP kgecCAg7jjpUQxyEGJ5rQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1730469320; x=1730555720; bh=v bcRh1xLMXs6D1grY6D0p73XgEN+cd/HL4E330kHx6c=; b=UjRKYQ1IkwohDzR9L aHu8pJB4lnMgSEGyLkLSQNRSsd6QzeRa68z4qEPLxQLlr4ylCcsPqkhvKa88hxxX aMIhlKbMcCIl4JaRtqC3USypyreQXkh1pYqE6vDmkSBezwlkd+tJ8/5Z9bLrrWQC sfYjIA9krug06IgF6yoihGN2477d6C0WK/lwHMFysloa0Da+eMyN6JuizzaraMz5 K2+l26Uv5YOcc2RO54yzG55qNou1C3vhLGevMb+bimsb9ZGXMzDPNTHDIbP9i0EE koNz8OY+CJmGFK95A0XwaoNsqD20sKQqIHfUpO5cMjvMFyKOABrCQ0D5SQO10Gfy G3/1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdekledgheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefgrhhinhcuufhhvghphhgvrhgu uceovghrihhnrdhshhgvphhhvghrugesvgegfedrvghuqeenucggtffrrghtthgvrhhnpe eggedvkedtuedvgfevvdehieevveejkeelieektdfggeevgfeiieejtdffledtieenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegvrhhinhdrsh hhvghphhgvrhgusegvgeefrdgvuhdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhht phhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqfhhsuggvvhgvlhesvhhgvghrrdhkvghr nhgvlhdrohhrghdprhgtphhtthhopegthhhrihhsthhirghnsegsrhgruhhnvghrrdhioh dprhgtphhtthhopehprghulhesphgruhhlqdhmohhorhgvrdgtohhmpdhrtghpthhtohep sghluhgtrgesuggvsghirghnrdhorhhgpdhrtghpthhtohepvghrihhnrdhshhgvphhhvg hrugesvgegfedrvghu X-ME-Proxy: Feedback-ID: i313944f9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Nov 2024 09:55:19 -0400 (EDT) From: Erin Shepherd To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: christian@brauner.io, paul@paul-moore.com, bluca@debian.org, erin.shepherd@e43.eu Subject: [PATCH 2/4] pidfs: implement file handle export support Date: Fri, 1 Nov 2024 13:54:50 +0000 Message-ID: <20241101135452.19359-3-erin.shepherd@e43.eu> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241101135452.19359-1-erin.shepherd@e43.eu> References: <20241101135452.19359-1-erin.shepherd@e43.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On 64-bit platforms, userspace can read the pidfd's inode in order to get a never-repeated PID identifier. On 32-bit platforms this identifier is not exposed, as inodes are limited to 32 bits. Instead expose the identifier via export_fh, which makes it available to userspace via name_to_handle_at Signed-off-by: Erin Shepherd Reviewed-by: Amir Goldstein --- fs/pidfs.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs/pidfs.c b/fs/pidfs.c index 80675b6bf884..c8e7e9011550 100644 --- a/fs/pidfs.c +++ b/fs/pidfs.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -347,6 +348,25 @@ static const struct dentry_operations pidfs_dentry_ope= rations =3D { .d_prune =3D stashed_dentry_prune, }; =20 +static int pidfs_encode_fh(struct inode *inode, __u32 *fh, int *max_len, + struct inode *parent) +{ + struct pid *pid =3D inode->i_private; + + if (*max_len < 2) { + *max_len =3D 2; + return FILEID_INVALID; + } + + *max_len =3D 2; + *(u64 *)fh =3D pid->ino; + return FILEID_KERNFS; +} + +static const struct export_operations pidfs_export_operations =3D { + .encode_fh =3D pidfs_encode_fh, +}; + static int pidfs_init_inode(struct inode *inode, void *data) { inode->i_private =3D data; @@ -382,6 +402,7 @@ static int pidfs_init_fs_context(struct fs_context *fc) return -ENOMEM; =20 ctx->ops =3D &pidfs_sops; + ctx->eops =3D &pidfs_export_operations; ctx->dops =3D &pidfs_dentry_operations; fc->s_fs_info =3D (void *)&pidfs_stashed_ops; return 0; --=20 2.46.1 From nobody Sun Nov 24 20:37:46 2024 Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5D571A7273; Fri, 1 Nov 2024 13:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730469325; cv=none; b=CcEC0oul6q3edPN4P+xa4NDKkwBPabDF80YJBk2WC3+e43PvByZ1oRulCAddQbr6fiR2acJtyt7QfnE6hYK2hspjOvs7zD1R7XxOg2W6YWkrmUcGCs3PbnTpljwA3+tn7+K+r9JZs03PuY0TA8p1zHO8jActGcMB3TzVDSJz9TY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730469325; c=relaxed/simple; bh=T0nDQFuEZwra84gxPs28eZs6BJBZo7mX8bcIGbUZRUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=igCmVVf+iImySHZZpXjJ5qBTp0CL1UE/QSBRiOzNmGeRQocP/DkMGgfRmHPFVurs8c0MPvktfozX8dM8kdV/Womc8hqbc/QjkRhx5Z5OihqsUPrLZ42GhfHAdw+fDSpPNedo6wR6kgdEGwZMQ8OvFL6xe3EmSaLQb0raWERacqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=e43.eu; spf=pass smtp.mailfrom=e43.eu; dkim=pass (2048-bit key) header.d=e43.eu header.i=@e43.eu header.b=REahKJe3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=B5gfoaWL; arc=none smtp.client-ip=202.12.124.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=e43.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=e43.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=e43.eu header.i=@e43.eu header.b="REahKJe3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="B5gfoaWL" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id ACCC3254010F; Fri, 1 Nov 2024 09:55:22 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 01 Nov 2024 09:55:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=e43.eu; h=cc:cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1730469322; x= 1730555722; bh=cw7NL9F9LsI3qVysaim2aItN+y15bcgyhI4NNmXxdLg=; b=R EahKJe3qrw1iA/s52c1uUt4Onojem0oW/32rhKY/ZEm2rAjHKhKCCf4E9q01ptwT fP3QU8usMMfKKnbI0dGgMPrFavtAWr+6x/SKpm2b1di/wA2dZosHR34u5o0B6kEM OrH9VSP20MYPmjP/pz9NyoQOt9sZ6rxiDcTa32PA8YSHoOAsdqp6TuJKRNRdzAfl PxRUiscoQBEo+UOZnCtGFdThuGzUHDVY1DauJ23pejIr6E6zuASMv4WX6mtf6VRZ 2zWGqrPygzB8n+JR98bpHzWSuAeEzUq4a/BIuYdD9rlC5QBDZiT44noLlknrpWne TL3EnvLfYNWec8i86QGvA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1730469322; x=1730555722; bh=c w7NL9F9LsI3qVysaim2aItN+y15bcgyhI4NNmXxdLg=; b=B5gfoaWL/1uOkWMGy XOk+6bzqWX8zFlGcu72k2biPJaMu1WveKY0++pF75m4YlhQmDf645KXNN57x7GLu R20o5T7r0k3YeGuyGzEnRmyXZoOLm5TUBs0oBbae7WZeBnha0fwbLm6D++yw7Wxa LNck4OxNrYO2+4Xa6wUAv2jwE9YPKzLbcF9XmHjjK6A/hNNyqmNg1uoSLUbs5vHd PIeseknVNjrukvPj3ihXj8gq7whLkx+RVXH2bwu2wpATAFrRCnwvL5q9tqNeusvu tEePeCk3IV/PoAK11mx6TUVxJAurY1iogjIF+Qs4Suby3cvyPLj0PpkF5M3OCaUa T+ZGw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdekledgheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefgrhhinhcuufhhvghphhgvrhgu uceovghrihhnrdhshhgvphhhvghrugesvgegfedrvghuqeenucggtffrrghtthgvrhhnpe eggedvkedtuedvgfevvdehieevveejkeelieektdfggeevgfeiieejtdffledtieenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegvrhhinhdrsh hhvghphhgvrhgusegvgeefrdgvuhdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhht phhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqfhhsuggvvhgvlhesvhhgvghrrdhkvghr nhgvlhdrohhrghdprhgtphhtthhopegthhhrihhsthhirghnsegsrhgruhhnvghrrdhioh dprhgtphhtthhopehprghulhesphgruhhlqdhmohhorhgvrdgtohhmpdhrtghpthhtohep sghluhgtrgesuggvsghirghnrdhorhhgpdhrtghpthhtohepvghrihhnrdhshhgvphhhvg hrugesvgegfedrvghu X-ME-Proxy: Feedback-ID: i313944f9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Nov 2024 09:55:21 -0400 (EDT) From: Erin Shepherd To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: christian@brauner.io, paul@paul-moore.com, bluca@debian.org, erin.shepherd@e43.eu Subject: [PATCH 3/4] pid: introduce find_get_pid_ns Date: Fri, 1 Nov 2024 13:54:51 +0000 Message-ID: <20241101135452.19359-4-erin.shepherd@e43.eu> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241101135452.19359-1-erin.shepherd@e43.eu> References: <20241101135452.19359-1-erin.shepherd@e43.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In some situations it is useful to be able to atomically get a PID from a specific PID namespace. Signed-off-by: Erin Shepherd Reviewed-by: Amir Goldstein --- include/linux/pid.h | 1 + kernel/pid.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/pid.h b/include/linux/pid.h index a3aad9b4074c..965f8b3ff9a8 100644 --- a/include/linux/pid.h +++ b/include/linux/pid.h @@ -124,6 +124,7 @@ extern struct pid *find_vpid(int nr); /* * Lookup a PID in the hash table, and return with it's count elevated. */ +extern struct pid *find_get_pid_ns(int nr, struct pid_namespace *ns); extern struct pid *find_get_pid(int nr); extern struct pid *find_ge_pid(int nr, struct pid_namespace *); =20 diff --git a/kernel/pid.c b/kernel/pid.c index 2715afb77eab..2967f8a98330 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -470,16 +470,22 @@ struct task_struct *get_pid_task(struct pid *pid, enu= m pid_type type) } EXPORT_SYMBOL_GPL(get_pid_task); =20 -struct pid *find_get_pid(pid_t nr) +struct pid *find_get_pid_ns(pid_t nr, struct pid_namespace *ns) { struct pid *pid; =20 rcu_read_lock(); - pid =3D get_pid(find_vpid(nr)); + pid =3D get_pid(find_pid_ns(nr, ns)); rcu_read_unlock(); =20 return pid; } +EXPORT_SYMBOL_GPL(find_get_pid_ns); + +struct pid *find_get_pid(pid_t nr) +{ + return find_get_pid_ns(nr, task_active_pid_ns(current)); +} EXPORT_SYMBOL_GPL(find_get_pid); =20 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns) --=20 2.46.1 From nobody Sun Nov 24 20:37:46 2024 Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6E261AA7BF; Fri, 1 Nov 2024 13:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730469329; cv=none; b=Ukf870L9D13uuReckUBM5oWxPNgm2M9lb/mkgo+Qb2yUFoxe39zeT6pu6Fz5eI3cIYmmLu0GWZyr0g5AO+P2ZlmocaU8FNlo4zNvcnlZp+mRnQpOEOkEt2Ju+dO3whCbXnurvd+a9n69+F8G+2K4Bp9vWLyFfxUTSD9L5GQGfWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730469329; c=relaxed/simple; bh=pFDhFHLBfdJwuTqHyN06kE8QojwExhKmomKGiOhi49U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cPX2dG+ou/Nai/XdJN4PKILpc7o+admasyGrVFz9BgMcsAhRX0mWzrTSy4nF91f6m1QM0CA/p45DU+9rnq/dE01KpCkGvfC9rYKq0YkZzfgUx8zyNezOmqE9M8NegUr6hfGWuZpwHt6XRhnydclESyy4vqPEufUSgh6NloMJ+wk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=e43.eu; spf=pass smtp.mailfrom=e43.eu; dkim=pass (2048-bit key) header.d=e43.eu header.i=@e43.eu header.b=LeA5WwjD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ajIH0dX4; arc=none smtp.client-ip=202.12.124.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=e43.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=e43.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=e43.eu header.i=@e43.eu header.b="LeA5WwjD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ajIH0dX4" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.stl.internal (Postfix) with ESMTP id 0963A2540115; Fri, 1 Nov 2024 09:55:25 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Fri, 01 Nov 2024 09:55:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=e43.eu; h=cc:cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1730469324; x= 1730555724; bh=192szHnbj9c+YbJkI7hF7+bUn60M5dnEdOqJzMxTjAU=; b=L eA5WwjDCwvlDLjMxLIfH9dZ+fSRij5Nu9nUJlsRQyTz/KXJSTP16bRBUaTkh4+6U xSNu+EafJMCnAi4USPy34rYAZFQuPQH5H1PK9vU3oqlQRRfM9yS9EZrdS4fmI33f DrFSrsdseBBUJVZdNEF7EeK+d/K6f3y0551CjfTxYlkHXem18jxTdCC+5yqVxK3G C3gI6VMpyb1A3UJr6oeQOpNsxM0ukgXLaGQTYm/PwYA/dUf4Ba9vRZdqVNveyACA B92v/x35TFYiSbPKHFnJbRFCEK1dvQ753J2ADiDOD12Ui1EZOPSt2EpoSHDns/l/ BLjy+i8eTUmtger1JFB8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1730469324; x=1730555724; bh=1 92szHnbj9c+YbJkI7hF7+bUn60M5dnEdOqJzMxTjAU=; b=ajIH0dX4GPtrgiqcT 2lnWzwSV43zhKoN3MdVl4a7Gi9Lp2eEZvfH2AFRyWsZxKBHTv7csxIEzsaKHaNlg EZbBLqHqoK3WGfblZOP6aFaIrV/VHOCVtMYM9HYsCpjeudbvb5DlRwAuflbMaQyK 4WWoSgXEfLUAJEcRwM0Gg0jQAwXsxjc6JqgnXYHSeo7hWGYJvIvRwM3SJSc+p2wt +2RICQArNsHFMmh1Y6Tqb6p0As79T36iSnoUHrPkE58jteswJoVw0l7agVrdXOvo U8xqHOazfm7NI1AgBA8Kg57twtdVXHNKJsdt67xFe5+wTZTqz0O+/YN6ESvhBJFG UbLxA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdekledgheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefgrhhinhcuufhhvghphhgvrhgu uceovghrihhnrdhshhgvphhhvghrugesvgegfedrvghuqeenucggtffrrghtthgvrhhnpe eggedvkedtuedvgfevvdehieevveejkeelieektdfggeevgfeiieejtdffledtieenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegvrhhinhdrsh hhvghphhgvrhgusegvgeefrdgvuhdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhht phhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqfhhsuggvvhgvlhesvhhgvghrrdhkvghr nhgvlhdrohhrghdprhgtphhtthhopegthhhrihhsthhirghnsegsrhgruhhnvghrrdhioh dprhgtphhtthhopehprghulhesphgruhhlqdhmohhorhgvrdgtohhmpdhrtghpthhtohep sghluhgtrgesuggvsghirghnrdhorhhgpdhrtghpthhtohepvghrihhnrdhshhgvphhhvg hrugesvgegfedrvghu X-ME-Proxy: Feedback-ID: i313944f9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Nov 2024 09:55:24 -0400 (EDT) From: Erin Shepherd To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: christian@brauner.io, paul@paul-moore.com, bluca@debian.org, erin.shepherd@e43.eu Subject: [PATCH 4/4] pidfs: implement fh_to_dentry Date: Fri, 1 Nov 2024 13:54:52 +0000 Message-ID: <20241101135452.19359-5-erin.shepherd@e43.eu> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241101135452.19359-1-erin.shepherd@e43.eu> References: <20241101135452.19359-1-erin.shepherd@e43.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This enables userspace to use name_to_handle_at to recover a pidfd to a process. We stash the process' PID in the root pid namespace inside the handle, and use that to recover the pid (validating that pid->ino matches the value in the handle, i.e. that the pid has not been reused). We use the root namespace in order to ensure that file handles can be moved across namespaces; however, we validate that the PID exists in the current namespace before returning the inode. Signed-off-by: Erin Shepherd Reviewed-by: Amir Goldstein --- fs/pidfs.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/fs/pidfs.c b/fs/pidfs.c index c8e7e9011550..2d66610ef385 100644 --- a/fs/pidfs.c +++ b/fs/pidfs.c @@ -348,23 +348,59 @@ static const struct dentry_operations pidfs_dentry_op= erations =3D { .d_prune =3D stashed_dentry_prune, }; =20 -static int pidfs_encode_fh(struct inode *inode, __u32 *fh, int *max_len, +#define PIDFD_FID_LEN 3 + +struct pidfd_fid { + u64 ino; + s32 pid; +} __packed; + +static int pidfs_encode_fh(struct inode *inode, u32 *fh, int *max_len, struct inode *parent) { struct pid *pid =3D inode->i_private; -=09 - if (*max_len < 2) { - *max_len =3D 2; + struct pidfd_fid *fid =3D (struct pidfd_fid *)fh; + + if (*max_len < PIDFD_FID_LEN) { + *max_len =3D PIDFD_FID_LEN; return FILEID_INVALID; } =20 - *max_len =3D 2; - *(u64 *)fh =3D pid->ino; - return FILEID_KERNFS; + fid->ino =3D pid->ino; + fid->pid =3D pid_nr(pid); + *max_len =3D PIDFD_FID_LEN; + return FILEID_INO64_GEN; +} + +static struct dentry *pidfs_fh_to_dentry(struct super_block *sb, + struct fid *gen_fid, + int fh_len, int fh_type) +{ + int ret; + struct path path; + struct pidfd_fid *fid =3D (struct pidfd_fid *)gen_fid; + struct pid *pid; + + if (fh_type !=3D FILEID_INO64_GEN || fh_len < PIDFD_FID_LEN) + return NULL; + + pid =3D find_get_pid_ns(fid->pid, &init_pid_ns); + if (!pid || pid->ino !=3D fid->ino || pid_vnr(pid) =3D=3D 0) { + put_pid(pid); + return NULL; + } + + ret =3D path_from_stashed(&pid->stashed, pidfs_mnt, pid, &path); + if (ret < 0) + return ERR_PTR(ret); + + mntput(path.mnt); + return path.dentry; } =20 static const struct export_operations pidfs_export_operations =3D { .encode_fh =3D pidfs_encode_fh, + .fh_to_dentry =3D pidfs_fh_to_dentry, }; =20 static int pidfs_init_inode(struct inode *inode, void *data) --=20 2.46.1