From patchwork Fri Nov 29 13:38:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13888707 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D5F001A0739; Fri, 29 Nov 2024 13:39:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887563; cv=none; b=WjtWIvpAu+KBczv2A2Qxvy2eW6KTJcdn45Lo3muZ0lMGGUGBCuzqzO927FF9mtRKbqA3hgTglHFtZagGIp3f2KIuempJTeTKVSLWCnTvHFtUfch4LbiWcrgv0Eh/ttm44MQWtVc/mGCQWdetfzSHXtpk4/1vPD8ly9bJQJNu+Aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887563; c=relaxed/simple; bh=78FWMXwHgkAge4U3uiflgkNmg1SNR5mVwKYGgc3VpOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BkBYj9T0bOmF7SJk+F5n450LZ8r3Xnr+OW64RbcnLjiRpcrHDKYGasjL3rzhr8GT4I8lsoZk6uag8fX91T7Cp8X6eWUsHYDn2Sc3tO9nPjrVVLUygOBanySj4C2PGN8IwWKQM1m4Nts1bo8sz5fAJoUMglzMEwiHWBhyzjs9gZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dia4x6uX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Dia4x6uX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13657C4CED7; Fri, 29 Nov 2024 13:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732887562; bh=78FWMXwHgkAge4U3uiflgkNmg1SNR5mVwKYGgc3VpOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dia4x6uXxqhkjc3HJrbianIpD2citF4JNVr14TvxN9YMIQKJitaR1COnmHUfV6qoi fa1/dbWohRWPKwT35c8/jzBqrSDULP0mUtsmKVXC8KgIpjgj27+KRXEzx3679zmzBx ZkhhhWndf9Of8MGIGmxlNFXWJNlN97/NakNR6e4RUrtLmz2dK2zofo+4Sqywga46x7 fIejAwfBtRS8p+LDmpETCRDjcN5IQh8RGH2+yHRKcc8VE/cmnsx1wQoatBPlQv6H6B JX0lb2m9GovWTl7jnP+HjtoiO440m3vQoSd/hefem52HUe7+aTnuKrPXqgRCzzmvMd XVW0nnnklkIYw== From: Christian Brauner To: Erin Shepherd , Amir Goldstein , Jeff Layton Cc: Christian Brauner , Alexander Viro , Jan Kara , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH RFC 1/6] pseudofs: add support for export_ops Date: Fri, 29 Nov 2024 14:38:00 +0100 Message-ID: <20241129-work-pidfs-file_handle-v1-1-87d803a42495@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> References: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-355e8 X-Developer-Signature: v=1; a=openpgp-sha256; l=1489; i=brauner@kernel.org; h=from:subject:message-id; bh=M0fgsqn/CebFxcPKkzyrf+owSKApWHVZ3/j7hOlekWk=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaR7Ht4f8EK3Y3VmgdbZH5y7RTRlNyqvj2u9+/rISeP4u /2L5z2q6ShlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZhIYhAjw443PVMbglhvP51R fDDK0HD92/aabEfPRv6NAq8lVXNf7WZk+Be8/AaDwVerd5tfTu+7FOQVU/WyY0FI4vczjr/+uYn M4QcA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 From: Erin Shepherd 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 Reviewed-by: Amir Goldstein Signed-off-by: Erin Shepherd Link: https://lore.kernel.org/r/20241113-pidfs_fh-v2-1-9a4d28155a37@e43.eu Signed-off-by: Christian Brauner --- 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 748ac59231547c29abcbade3fa025e3b00533d8b..2890a9c4a414b7e2be5c337e238db84743f0a30b 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -673,6 +673,7 @@ static int pseudo_fs_fill_super(struct super_block *s, struct fs_context *fc) s->s_blocksize_bits = PAGE_SHIFT; s->s_magic = ctx->magic; s->s_op = ctx->ops ?: &simple_super_operations; + s->s_export_op = ctx->eops; s->s_xattr = ctx->xattr; s->s_time_gran = 1; root = new_inode(s); diff --git a/include/linux/pseudo_fs.h b/include/linux/pseudo_fs.h index 730f77381d55f1816ef14adf7dd2cf1d62bb912c..2503f7625d65e7b1fbe9e64d5abf06cd8f017b5f 100644 --- a/include/linux/pseudo_fs.h +++ b/include/linux/pseudo_fs.h @@ -5,6 +5,7 @@ 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; From patchwork Fri Nov 29 13:38:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13888708 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A100E1A0BDB; Fri, 29 Nov 2024 13:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887565; cv=none; b=Muj9Phe9ltrc8CW9QEliEfYV4bjEWEQkqiNkR6wIhlxiQYMRSYS7MVrI46dnMRajSVaS/AgHuXujd4UVUISg9Hw3qQ8fe0WnR9jTmxnwH5clLY3BzM4bqjhG6HjXPKkM2HRKhFighnxwMwuJVOzmIgB9sP5zyCYJpcOBR6rA2Ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887565; c=relaxed/simple; bh=0ufmttgp29x3cn0TQa3rd5/zer9AJDWgjU/KvQ526oo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ORDam0xJySMhyyye7fmzVQL/EIPryfYwQMVSiJutQdQzXLW0xMtsUh5sMFHBBuiFeayySSFuSB4ONq5oUxszdtknj3Rbztr+mPtxFeYhr1VeG21H8b79bfX7aVNcTEwcOoJGwYURTAGuxDpKNjk+lB6CEeYTWrWyRAZuObkqfPg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MZ1WXO8h; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MZ1WXO8h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE2A9C4CECF; Fri, 29 Nov 2024 13:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732887565; bh=0ufmttgp29x3cn0TQa3rd5/zer9AJDWgjU/KvQ526oo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MZ1WXO8hR0dY1joxKqSe0XRno+dmoQNbuQQT0xqx8+l0GnrwBMk3XNxiYRvZ5K0is smfIp/Vn1IIYqmTnclmquCv0ciAniY+NvTNUFgZjcz0w3EWl9H4ynQ5ULo0A6fB7i7 XreOj1OceRA+viTtDF89etFJLzCWkitMs7BXmKsk6gIQ4QNgaXFfG//WqtMBs9cEpy g/EEs2pExRSLQtJmbGe8GwFPCmqSAvbjPz63p8y8CtTha9wCMg03jrKiBvmzhxcpUM AwPm9dnIkPsrNLOmLlpjUqYSWdaPkA6sWSUzDEvaXW9WNbkHA+KiTjfjuOFw/zpPTY OLDD9swM7dEkA== From: Christian Brauner To: Erin Shepherd , Amir Goldstein , Jeff Layton Cc: Christian Brauner , Alexander Viro , Jan Kara , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH RFC 2/6] fhandle: simplify error handling Date: Fri, 29 Nov 2024 14:38:01 +0100 Message-ID: <20241129-work-pidfs-file_handle-v1-2-87d803a42495@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> References: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-355e8 X-Developer-Signature: v=1; a=openpgp-sha256; l=2177; i=brauner@kernel.org; h=from:subject:message-id; bh=0ufmttgp29x3cn0TQa3rd5/zer9AJDWgjU/KvQ526oo=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaR7Hj5go3bx9Pm14b/6Be3cpD3t/RUXTAoraOw3XMFmN Znj9CSTjlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgImsd2H4K6xe7yCjxHaE+4TV x936N+yvJZtuFROYM1lqc4KRw3Lp5wz/K4XNql7fOhX64GRS5g2eTzODzUQO2NqXXhZkXnGkP1S PHwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Rely on our cleanup infrastructure. Signed-off-by: Christian Brauner --- fs/fhandle.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/fs/fhandle.c b/fs/fhandle.c index ec9145047dfc9d25e109e72d210987bbf6b36a20..c00d88fb14e16654b5cbbb71760c0478eac20384 100644 --- a/fs/fhandle.c +++ b/fs/fhandle.c @@ -261,19 +261,20 @@ static int do_handle_to_path(struct file_handle *handle, struct path *path, { int handle_dwords; struct vfsmount *mnt = ctx->root.mnt; + struct dentry *dentry; /* change the handle size to multiple of sizeof(u32) */ handle_dwords = handle->handle_bytes >> 2; - path->dentry = exportfs_decode_fh_raw(mnt, - (struct fid *)handle->f_handle, - handle_dwords, handle->handle_type, - ctx->fh_flags, - vfs_dentry_acceptable, ctx); - if (IS_ERR_OR_NULL(path->dentry)) { - if (path->dentry == ERR_PTR(-ENOMEM)) + dentry = exportfs_decode_fh_raw(mnt, (struct fid *)handle->f_handle, + handle_dwords, handle->handle_type, + ctx->fh_flags, vfs_dentry_acceptable, + ctx); + if (IS_ERR_OR_NULL(dentry)) { + if (dentry == ERR_PTR(-ENOMEM)) return -ENOMEM; return -ESTALE; } + path->dentry = dentry; path->mnt = mntget(mnt); return 0; } @@ -398,29 +399,23 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh, int open_flag) { long retval = 0; - struct path path; + struct path path __free(path_put) = {}; struct file *file; - int fd; retval = handle_to_path(mountdirfd, ufh, &path, open_flag); if (retval) return retval; - fd = get_unused_fd_flags(open_flag); - if (fd < 0) { - path_put(&path); + CLASS(get_unused_fd, fd)(O_CLOEXEC); + if (fd < 0) return fd; - } + file = file_open_root(&path, "", open_flag, 0); - if (IS_ERR(file)) { - put_unused_fd(fd); - retval = PTR_ERR(file); - } else { - retval = fd; - fd_install(fd, file); - } - path_put(&path); - return retval; + if (IS_ERR(file)) + return PTR_ERR(file); + + fd_install(fd, file); + return take_fd(fd); } /** From patchwork Fri Nov 29 13:38:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13888709 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5F8511A2625; Fri, 29 Nov 2024 13:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887568; cv=none; b=YwvcHrh1pOfJktqXxn8CrmBJsTGUr5FvkgkX8FrlnhhaEVhmFVk3ltLgNvCRAamOHUCEhlUDQXX+pQ1aeOAKtMnf2PFEKabUOvwoZjrtnyhbDM4pbrB6lL8maBRFDKOBKBlOQylihl0Yo12NdVklAXsDdOtnYUQYN1Ux+I53W7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887568; c=relaxed/simple; bh=IzT13zirsd9Il47+VcD309SeoUwtTzDUSJ/JlVEGVNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uGcicuvlfDmRi7Te1pxytAALfCoFp231vWcelvnwrXpK99I3zUXk1LJmkkENqIAO1viBQP89KO+jDuU8NJmlF4k1B2LsRgtzJ/jcQpp1D57qdFT0IuIc4VJHs3BSWDoytKSdRLd3hYdUSCzHNlbQXsy51oB01pLvDBo22rmStB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hTJDgEWu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hTJDgEWu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98C62C4CED2; Fri, 29 Nov 2024 13:39:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732887567; bh=IzT13zirsd9Il47+VcD309SeoUwtTzDUSJ/JlVEGVNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hTJDgEWucqUR1qFpViySZ7Qzicq6ESW08Io2vHC9FPDCpWkMTe7dNTRFDE8W/EnHF jtPjGGqxGBCGDpx5dVGsIRJaauwmiyE/keSnly+wJeMEyNJXdVz62o+F8niE6c9hOA DMT0WADrvvY3BXu3EI0j/QI+60WuuP4zLR7kqzetoKzxKZtY71iFaIUMBxtMbf4ktU SNkXfZVUblrENas2eumChFKjDF7i3ae38+p1igUNkTYOGmWdTxw+vZxQyUA/cYPSIO V5cY1J/OvOeW5rAwu3aKAhtO6iV0J93Wj0CrMa5uNqr2+7rzTKj002YygirYhGX3Y8 /qoRzd1Xj+1gg== From: Christian Brauner To: Erin Shepherd , Amir Goldstein , Jeff Layton Cc: Christian Brauner , Alexander Viro , Jan Kara , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH RFC 3/6] exportfs: add open method Date: Fri, 29 Nov 2024 14:38:02 +0100 Message-ID: <20241129-work-pidfs-file_handle-v1-3-87d803a42495@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> References: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-355e8 X-Developer-Signature: v=1; a=openpgp-sha256; l=1482; i=brauner@kernel.org; h=from:subject:message-id; bh=IzT13zirsd9Il47+VcD309SeoUwtTzDUSJ/JlVEGVNA=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaR7Hj7QJe5ayRURojW5qHMNs9mU4m/e1rVnF1zjW7P47 inROn62jlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgIkcvMDIMO9z+/pip71T+zXf WbyUNGHeWRQRuel735xLL57Pv/GtfiEjw+UN3z3/Pi15crzp2uFJcxas0l1f+X+CV+uOmT/lLv9 lieMFAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 This allows filesystems such as pidfs to provide their custom open. Signed-off-by: Christian Brauner --- include/linux/exportfs.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h index 4cc8801e50e395442f9e3ae69b6c9f04fa590ff9..c69b79b64466d5bc32ffe9b2796a388130fe72d8 100644 --- a/include/linux/exportfs.h +++ b/include/linux/exportfs.h @@ -10,6 +10,7 @@ struct inode; struct iomap; struct super_block; struct vfsmount; +struct path; /* limit the handle size to NFSv4 handle size now */ #define MAX_HANDLE_SZ 128 @@ -225,6 +226,9 @@ struct fid { * is also a directory. In the event that it cannot be found, or storage * space cannot be allocated, a %ERR_PTR should be returned. * + * open: + * Allow filesystems to specify a custom open function. + * * commit_metadata: * @commit_metadata should commit metadata changes to stable storage. * @@ -251,6 +255,7 @@ struct export_operations { bool write, u32 *device_generation); int (*commit_blocks)(struct inode *inode, struct iomap *iomaps, int nr_iomaps, struct iattr *iattr); + struct file * (*open)(struct path *path, unsigned int oflags); #define EXPORT_OP_NOWCC (0x1) /* don't collect v3 wcc data */ #define EXPORT_OP_NOSUBTREECHK (0x2) /* no subtree checking */ #define EXPORT_OP_CLOSE_BEFORE_UNLINK (0x4) /* close files before unlink */ From patchwork Fri Nov 29 13:38:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13888710 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0C5CA1A3A8D; Fri, 29 Nov 2024 13:39:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887571; cv=none; b=q7Z6ErOatd8Kee3OVMAcj7zreDU8WPTRLusS4DHZEqTcaVl7dQhIQ5YXSCD+IWEZ8xdlM/QoHN91Ar12hJHPj0vEsUbo0rg3a6RMPdABhme/8AVIaY1zyZKbroBUN89xFZJGx78LmzKP8UlQfewCLEMdte0v5lBAYjtq7miHUaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887571; c=relaxed/simple; bh=MbJKDBcZ0ddGFSB0evIr2caQuD86w7k3PwTvETORd2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kpvYJFLoMIIi7a/aZinegr2ga0C7iXwjzv0Wg9KeuUc2FxKGdgWR/QzEaXskHk3PGBH5MxgR/Metb8U3M3w7pzsoCgHS3CMZvBv5evmWH0rtyQcJl71QqNOeXPsCGpZFx0dy4vmA1ufddZ59YVh3B3iq6gjUVK+i7v2T8f7fwWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ptsf66kg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ptsf66kg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70BF3C4CED3; Fri, 29 Nov 2024 13:39:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732887570; bh=MbJKDBcZ0ddGFSB0evIr2caQuD86w7k3PwTvETORd2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ptsf66kgpx7grHugaR6QWoO01Rr9p1R+dSgN8EPlZdnlNJ1YEAy0trh+SvxA/oK88 E+uhV1yUdieg9ytE/XnzVoZKkgwgmRKzFm52f31AggpFY9krgmJwN7dcU+2aoL000s UfiDpH9RLSZ51rQXTvpqSV1wMpi32XJWP/uOOLEqZY9TQfGbUNnmxHWOrcDpOkDUoL IM5/+dK62FUBxl/Z89Hch0oZMxFdBTEyuZQR70C84C4b94HsJYRUNzM6e0AZ50CwbG a/tWGrN8lHqvDDJGzJ1Y6eRLYbrDzQbgWkjecbkfw3ZhQcebCPDi6+qBKCw9nFeEZ2 cxlgL7uOqAqkw== From: Christian Brauner To: Erin Shepherd , Amir Goldstein , Jeff Layton Cc: Christian Brauner , Alexander Viro , Jan Kara , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH RFC 4/6] fhandle: pull CAP_DAC_READ_SEARCH check into may_decode_fh() Date: Fri, 29 Nov 2024 14:38:03 +0100 Message-ID: <20241129-work-pidfs-file_handle-v1-4-87d803a42495@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> References: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-355e8 X-Developer-Signature: v=1; a=openpgp-sha256; l=1067; i=brauner@kernel.org; h=from:subject:message-id; bh=MbJKDBcZ0ddGFSB0evIr2caQuD86w7k3PwTvETORd2c=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaR7Hj64M6Hgtdm8KPvSJbdnX47QCHvct3dtZOeO9GXVh 4QURdkyOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACYy7RYjw8dcBt6NqqrMzeab bipkPX3CXPpeU6DVoXN92gFT2yV8nxj+F39JrJljtPO+r8g6Jy5l42N6yUf5c+ZGaU280HJT434 9BwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 There's no point in keeping it outside of that helper. This way we have all the permission pieces in one place. Signed-off-by: Christian Brauner --- fs/fhandle.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/fhandle.c b/fs/fhandle.c index c00d88fb14e16654b5cbbb71760c0478eac20384..031ad5592a0beabcc299436f037ad5fe626332e6 100644 --- a/fs/fhandle.c +++ b/fs/fhandle.c @@ -298,6 +298,9 @@ static inline bool may_decode_fh(struct handle_to_path_ctx *ctx, { struct path *root = &ctx->root; + if (capable(CAP_DAC_READ_SEARCH)) + return true; + /* * Restrict to O_DIRECTORY to provide a deterministic API that avoids a * confusing api in the face of disconnected non-dir dentries. @@ -337,7 +340,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh, if (retval) goto out_err; - if (!capable(CAP_DAC_READ_SEARCH) && !may_decode_fh(&ctx, o_flags)) { + if (!may_decode_fh(&ctx, o_flags)) { retval = -EPERM; goto out_path; } From patchwork Fri Nov 29 13:38:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13888711 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 47ABF1A7274; Fri, 29 Nov 2024 13:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887574; cv=none; b=G7v9kXjoT/TwYE+PE8J5wiDmkX2EgbTsE20lk87BQeRddC4Q9lSlaMoRuJ129YV2iN1D1A+8N6AnLBT0BVK8Zxw5Bmi4Q0uJ2shdWeCnizjNE9Lv/ZjaUNE5w0t2hYNGNs6qG1qTVxP75mnxyno1QL+htfFGwY6d03dXaUTOK6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887574; c=relaxed/simple; bh=mZfbHs4mNu6U8OuHnn6AHXjPoepY5hOvawaSJo/awdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UmKw2otBJvEdJghiY01xw35EGeFDJpD2/5o9+eYxtjTrMVx2X2umhGLZRBv6c9UcW3JuiLXIq0+qKDKAgs1v3pjzrGJHsBlbvn6BrhSm72d59krcxhDtzm0/KgA/UW6JGFHy7BICvOUUQZ2ZaEg1FMJd4tBN6dcS+A5f5MFa+Sc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WJbYnNsW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WJbYnNsW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D465C4CED2; Fri, 29 Nov 2024 13:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732887573; bh=mZfbHs4mNu6U8OuHnn6AHXjPoepY5hOvawaSJo/awdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WJbYnNsWr8gAk6kku4/yzZo9cZRyG0eQqJlnfXRYA4BD4UPtgnBk3rjjq+YA6dr4/ 7PTi1cxghYMPERjCq1NIVnfrpcf95uC/g3gtzSMRK33s1yp3D+Lf3DtKK5AHrId8u9 ZfExURO96dLLn92ODwKFZzwfcW9Ywzvzc6i5uLcnIxObppCowfsU/wSOs8FzYK65BA dFxxbroGNLk8/q9P97Y3m18Iw/9Tt3hxA4W5rzedUmMfZPYdPM64OT+gcpT66Ic8oD lREfy345wtMt34fejmX/gur5M54adEgnXYXxjfCkxqo4TtmVFcum+EZCJsOx8NKbOV xkZn2mKMNOiFQ== From: Christian Brauner To: Erin Shepherd , Amir Goldstein , Jeff Layton Cc: Christian Brauner , Alexander Viro , Jan Kara , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH RFC 5/6] exportfs: add permission method Date: Fri, 29 Nov 2024 14:38:04 +0100 Message-ID: <20241129-work-pidfs-file_handle-v1-5-87d803a42495@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> References: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-355e8 X-Developer-Signature: v=1; a=openpgp-sha256; l=3542; i=brauner@kernel.org; h=from:subject:message-id; bh=mZfbHs4mNu6U8OuHnn6AHXjPoepY5hOvawaSJo/awdo=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaR7Hj7IHNIUIFB0X+vnw6L4CXP2Phe1bhGK/P5+AaOhq /ma3lmnOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACaywZ+RoX+bcZzqxJ9uj89Y JAWekPebccBm2oa1Cx+78+eu3M4wV5CR4cf2yrO/1JIqz07ZlbP3YtzvV1o3Fu8w3nv18+aunLD +Wm4A X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 This allows filesystems such as pidfs to provide their custom permission checks. Signed-off-by: Christian Brauner --- fs/fhandle.c | 21 +++++++-------------- include/linux/exportfs.h | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/fs/fhandle.c b/fs/fhandle.c index 031ad5592a0beabcc299436f037ad5fe626332e6..23491094032ec037066a271873ea8ff794616bee 100644 --- a/fs/fhandle.c +++ b/fs/fhandle.c @@ -187,17 +187,6 @@ static int get_path_from_fd(int fd, struct path *root) return 0; } -enum handle_to_path_flags { - HANDLE_CHECK_PERMS = (1 << 0), - HANDLE_CHECK_SUBTREE = (1 << 1), -}; - -struct handle_to_path_ctx { - struct path root; - enum handle_to_path_flags flags; - unsigned int fh_flags; -}; - static int vfs_dentry_acceptable(void *context, struct dentry *dentry) { struct handle_to_path_ctx *ctx = context; @@ -335,15 +324,19 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh, struct file_handle f_handle; struct file_handle *handle = NULL; struct handle_to_path_ctx ctx = {}; + const struct export_operations *eops; retval = get_path_from_fd(mountdirfd, &ctx.root); if (retval) goto out_err; - if (!may_decode_fh(&ctx, o_flags)) { - retval = -EPERM; + eops = ctx.root.mnt->mnt_sb->s_export_op; + if (eops && eops->permission) + retval = eops->permission(&ctx, o_flags); + else + retval = may_decode_fh(&ctx, o_flags); + if (retval) goto out_path; - } if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) { retval = -EFAULT; diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h index c69b79b64466d5bc32ffe9b2796a388130fe72d8..a087606ace194ccc9d1250f990ce55627aaf8dc5 100644 --- a/include/linux/exportfs.h +++ b/include/linux/exportfs.h @@ -3,6 +3,7 @@ #define LINUX_EXPORTFS_H 1 #include +#include struct dentry; struct iattr; @@ -10,7 +11,6 @@ struct inode; struct iomap; struct super_block; struct vfsmount; -struct path; /* limit the handle size to NFSv4 handle size now */ #define MAX_HANDLE_SZ 128 @@ -157,6 +157,17 @@ struct fid { }; }; +enum handle_to_path_flags { + HANDLE_CHECK_PERMS = (1 << 0), + HANDLE_CHECK_SUBTREE = (1 << 1), +}; + +struct handle_to_path_ctx { + struct path root; + enum handle_to_path_flags flags; + unsigned int fh_flags; +}; + #define EXPORT_FH_CONNECTABLE 0x1 /* Encode file handle with parent */ #define EXPORT_FH_FID 0x2 /* File handle may be non-decodeable */ #define EXPORT_FH_DIR_ONLY 0x4 /* Only decode file handle for a directory */ @@ -226,6 +237,9 @@ struct fid { * is also a directory. In the event that it cannot be found, or storage * space cannot be allocated, a %ERR_PTR should be returned. * + * permission: + * Allow filesystems to specify a custom permission function. + * * open: * Allow filesystems to specify a custom open function. * @@ -255,6 +269,7 @@ struct export_operations { bool write, u32 *device_generation); int (*commit_blocks)(struct inode *inode, struct iomap *iomaps, int nr_iomaps, struct iattr *iattr); + int (*permission)(struct handle_to_path_ctx *ctx, unsigned int oflags); struct file * (*open)(struct path *path, unsigned int oflags); #define EXPORT_OP_NOWCC (0x1) /* don't collect v3 wcc data */ #define EXPORT_OP_NOSUBTREECHK (0x2) /* no subtree checking */ From patchwork Fri Nov 29 13:38:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13888712 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1BC851A9B2A; Fri, 29 Nov 2024 13:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887577; cv=none; b=dDaZn3BC8pjB6xLnhh3kNQC6VimiEkloYDr+EmZ4xQlhBfPZFsGpLJJ3gdCufnH+/zxnEvzMXDhdp5whNApzyqXvl9Mk9x0b/F8Tde49l+b/0/2cxnyd7z6bx9YO2/GYJbrWNGPGWAoJkuB0cv4ovJQOqDsaEmPBVX9eNVydvvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732887577; c=relaxed/simple; bh=WEQD5GD1MRTw0uQNZQTK0HL8w7OgRdr07MVKxiGGaVU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GQmLMmYOiXN9LchzHwW/elg8Jt4mP4sLD+0t6MNxgDcleGZCBS7ekARnc+ZxhfdsjnHz9Ve+2c9hC99sSKDmHJYfoLIN6SOhEz1o73ggZEJV8bQt/AloUGwbeXF+d5R8cfANQJ+xwpy0oeiqCp+TnI1PkPIA/qIDSN4JGHmCAvc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hnbMI3Hh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hnbMI3Hh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 528E4C4CECF; Fri, 29 Nov 2024 13:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732887576; bh=WEQD5GD1MRTw0uQNZQTK0HL8w7OgRdr07MVKxiGGaVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hnbMI3Hh65KedCuSDpx1x/cPkl0mAhCkn/nu2JShAr8jMYY678SDVxkUd+89fxbQd NNZQKDegYEf0hbQkMFSs3IEL0kpM+h6AbZQ0Z3ULUkYYLWleVH5PjHozlX2ty6kkF3 v1HSmI+jZRd3kA37N6C33CGN1PgLhPMgx4WgajwgF8W7jEGCAlHPYYji6pDRwNgA1T 5f2Cjy8O4VdQwaWaxfs4upTu/V6PjNsCbj2dCjlv1YGyrVgynmda7i9JIlBwf4jred whHUsRi6Vur+9v/O2zeZLQk8kfMKLo7bCWWYhDIBEy0xN6odJOyKR0ITqLWIQXqmzP 6I2NA+4DKQLLQ== From: Christian Brauner To: Erin Shepherd , Amir Goldstein , Jeff Layton Cc: Christian Brauner , Alexander Viro , Jan Kara , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH RFC 6/6] pidfs: implement file handle support Date: Fri, 29 Nov 2024 14:38:05 +0100 Message-ID: <20241129-work-pidfs-file_handle-v1-6-87d803a42495@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> References: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-355e8 X-Developer-Signature: v=1; a=openpgp-sha256; l=6382; i=brauner@kernel.org; h=from:subject:message-id; bh=WEQD5GD1MRTw0uQNZQTK0HL8w7OgRdr07MVKxiGGaVU=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaR7Hj5kuS/k0ZmFdU8Fzod/z0yvli1vL6m226l/lM9n9 mvxYP4vHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABOZvJ6RYZHprYiLbcsWptXF XkmbdbQxkre2ojnt3/5YMVeuZY/5kxgZ1p2JcJj6gq8gdlmU/ISSWIXLn6p3ck+snOFd0+/2Wew QCwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 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. In addition we implement fh_to_dentry, which allows userspace to recover a pidfd from a pidfs file handle. Signed-off-by: Erin Shepherd [brauner: patch heavily rewritten] Co-Developed-by: Christian Brauner Signed-off-by: Christian Brauner --- fs/fhandle.c | 34 +++++++++++---------- fs/pidfs.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 15 deletions(-) diff --git a/fs/fhandle.c b/fs/fhandle.c index 23491094032ec037066a271873ea8ff794616bee..4c847ca16fabe31d51ff5698b0c9c355c3e2fb67 100644 --- a/fs/fhandle.c +++ b/fs/fhandle.c @@ -268,20 +268,6 @@ static int do_handle_to_path(struct file_handle *handle, struct path *path, return 0; } -/* - * Allow relaxed permissions of file handles if the caller has the - * ability to mount the filesystem or create a bind-mount of the - * provided @mountdirfd. - * - * In both cases the caller may be able to get an unobstructed way to - * the encoded file handle. If the caller is only able to create a - * bind-mount we need to verify that there are no locked mounts on top - * of it that could prevent us from getting to the encoded file. - * - * In principle, locked mounts can prevent the caller from mounting the - * filesystem but that only applies to procfs and sysfs neither of which - * support decoding file handles. - */ static inline bool may_decode_fh(struct handle_to_path_ctx *ctx, unsigned int o_flags) { @@ -291,6 +277,19 @@ static inline bool may_decode_fh(struct handle_to_path_ctx *ctx, return true; /* + * Allow relaxed permissions of file handles if the caller has the + * ability to mount the filesystem or create a bind-mount of the + * provided @mountdirfd. + * + * In both cases the caller may be able to get an unobstructed way to + * the encoded file handle. If the caller is only able to create a + * bind-mount we need to verify that there are no locked mounts on top + * of it that could prevent us from getting to the encoded file. + * + * In principle, locked mounts can prevent the caller from mounting the + * filesystem but that only applies to procfs and sysfs neither of which + * support decoding file handles. + * * Restrict to O_DIRECTORY to provide a deterministic API that avoids a * confusing api in the face of disconnected non-dir dentries. * @@ -397,6 +396,7 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh, long retval = 0; struct path path __free(path_put) = {}; struct file *file; + const struct export_operations *eops; retval = handle_to_path(mountdirfd, ufh, &path, open_flag); if (retval) @@ -406,7 +406,11 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh, if (fd < 0) return fd; - file = file_open_root(&path, "", open_flag, 0); + eops = path.mnt->mnt_sb->s_export_op; + if (eops->open) + file = eops->open(&path, open_flag); + else + file = file_open_root(&path, "", open_flag, 0); if (IS_ERR(file)) return PTR_ERR(file); diff --git a/fs/pidfs.c b/fs/pidfs.c index f73a47e1d8379df886a90a044fb887f8d06f7c0b..f09af08a4abe4a9100ed972bee8f5c5d7ab33d84 100644 --- a/fs/pidfs.c +++ b/fs/pidfs.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -454,6 +455,100 @@ static const struct dentry_operations pidfs_dentry_operations = { .d_prune = stashed_dentry_prune, }; +static int pidfs_encode_fh(struct inode *inode, u32 *fh, int *max_len, + struct inode *parent) +{ + struct pid *pid = inode->i_private; + + if (*max_len < 2) { + *max_len = 2; + return FILEID_INVALID; + } + + *max_len = 2; + *(u64 *)fh = pid->ino; + return FILEID_KERNFS; +} + +/* Find a struct pid based on the inode number. */ +static struct pid *pidfs_ino_get_pid(u64 ino) +{ + ino_t pid_ino = pidfs_ino(ino); + u32 gen = pidfs_gen(ino); + struct pid *pid; + + guard(rcu)(); + + /* Handle @pid lookup carefully so there's no risk of UAF. */ + pid = idr_find(&pidfs_ino_idr, (u32)pid_ino); + if (!pid) + return NULL; + + if (sizeof(ino_t) < sizeof(u64)) { + if (gen && pidfs_gen(pid->ino) != gen) + pid = NULL; + } else { + if (pidfs_ino(pid->ino) != pid_ino) + pid = NULL; + } + + /* Within our pid namespace hierarchy? */ + if (pid_vnr(pid) == 0) + pid = NULL; + + return get_pid(pid); +} + +static struct dentry *pidfs_fh_to_dentry(struct super_block *sb, + struct fid *fid, int fh_len, + int fh_type) +{ + int ret; + u64 pid_ino; + struct path path; + struct pid *pid; + + if (fh_len < 2) + return NULL; + + switch (fh_type) { + case FILEID_KERNFS: + pid_ino = *(u64 *)fid; + break; + default: + return NULL; + } + + pid = pidfs_ino_get_pid(pid_ino); + if (!pid) + return NULL; + + ret = path_from_stashed(&pid->stashed, pidfs_mnt, pid, &path); + if (ret < 0) + return ERR_PTR(ret); + + mntput(path.mnt); + return path.dentry; +} + +static int pidfs_export_permission(struct handle_to_path_ctx *ctx, + unsigned int oflags) +{ + return 0; +} + +static struct file *pidfs_export_open(struct path *path, unsigned int oflags) +{ + return dentry_open(path, oflags | O_RDWR, current_cred()); +} + +static const struct export_operations pidfs_export_operations = { + .encode_fh = pidfs_encode_fh, + .fh_to_dentry = pidfs_fh_to_dentry, + .open = pidfs_export_open, + .permission = pidfs_export_permission, +}; + static int pidfs_init_inode(struct inode *inode, void *data) { struct pid *pid = data; @@ -488,6 +583,7 @@ static int pidfs_init_fs_context(struct fs_context *fc) return -ENOMEM; ctx->ops = &pidfs_sops; + ctx->eops = &pidfs_export_operations; ctx->dops = &pidfs_dentry_operations; fc->s_fs_info = (void *)&pidfs_stashed_ops; return 0;