[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAOQ4uxjTN5rXqAgR-ovfEuo7gSYY6Wig1-4QV6a5BXFkfqge6A@mail.gmail.com>
Date: Tue, 12 Nov 2024 16:55:52 +0100
From: Amir Goldstein <amir73il@...il.com>
To: Erin Shepherd <erin.shepherd@....eu>
Cc: linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
christian@...uner.io, paul@...l-moore.com, bluca@...ian.org
Subject: Re: [PATCH 2/4] pidfs: implement file handle export support
On Fri, Nov 1, 2024 at 2:55 PM Erin Shepherd <erin.shepherd@....eu> wrote:
>
> 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 <erin.shepherd@....eu>
Reviewed-by: Amir Goldstein <amir73il@...il.com>
> ---
> 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 <linux/anon_inodes.h>
> +#include <linux/exportfs.h>
> #include <linux/file.h>
> #include <linux/fs.h>
> #include <linux/magic.h>
> @@ -347,6 +348,25 @@ 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;
> +}
> +
> +static const struct export_operations pidfs_export_operations = {
> + .encode_fh = pidfs_encode_fh,
> +};
> +
> static int pidfs_init_inode(struct inode *inode, void *data)
> {
> inode->i_private = data;
> @@ -382,6 +402,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;
> --
> 2.46.1
>
>
Powered by blists - more mailing lists