From: Jan Kara <jack@suse.cz>
To: Christian Brauner <brauner@kernel.org>
Cc: Erin Shepherd <erin.shepherd@e43.eu>,
Amir Goldstein <amir73il@gmail.com>,
Jeff Layton <jlayton@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
Chuck Lever <chuck.lever@oracle.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-nfs@vger.kernel.org
Subject: Re: [PATCH RFC 5/6] exportfs: add permission method
Date: Mon, 2 Dec 2024 17:04:52 +0100 [thread overview]
Message-ID: <20241202160452.2pg3qe4jymugp3su@quack3> (raw)
In-Reply-To: <20241129-work-pidfs-file_handle-v1-5-87d803a42495@kernel.org>
On Fri 29-11-24 14:38:04, Christian Brauner wrote:
> This allows filesystems such as pidfs to provide their custom permission
> checks.
>
> Signed-off-by: Christian Brauner <brauner@kernel.org>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> 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 <linux/types.h>
> +#include <linux/path.h>
>
> 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 */
>
> --
> 2.45.2
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-12-02 16:04 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 13:02 [PATCH RFC v2 0/3] pidfs: file handle preliminaries Christian Brauner
2024-11-29 13:02 ` [PATCH RFC v2 1/3] pidfs: rework inode number allocation Christian Brauner
2024-12-02 15:15 ` Jan Kara
2024-11-29 13:02 ` [PATCH RFC v2 2/3] pidfs: remove 32bit inode number handling Christian Brauner
2024-12-02 15:18 ` Jan Kara
2024-11-29 13:02 ` [PATCH RFC v2 3/3] pidfs: support FS_IOC_GETVERSION Christian Brauner
2024-12-02 15:35 ` Jan Kara
2024-11-29 13:37 ` [PATCH RFC 0/6] pidfs: implement file handle support Christian Brauner
2024-11-29 13:38 ` [PATCH RFC 1/6] pseudofs: add support for export_ops Christian Brauner
2024-12-02 15:59 ` Jan Kara
2024-11-29 13:38 ` [PATCH RFC 2/6] fhandle: simplify error handling Christian Brauner
2024-12-02 15:58 ` Jan Kara
2024-11-29 13:38 ` [PATCH RFC 3/6] exportfs: add open method Christian Brauner
2024-12-02 16:05 ` Jan Kara
2024-11-29 13:38 ` [PATCH RFC 4/6] fhandle: pull CAP_DAC_READ_SEARCH check into may_decode_fh() Christian Brauner
2024-12-02 16:01 ` Jan Kara
2024-11-29 13:38 ` [PATCH RFC 5/6] exportfs: add permission method Christian Brauner
2024-12-02 16:04 ` Jan Kara [this message]
2024-11-29 13:38 ` [PATCH RFC 6/6] pidfs: implement file handle support Christian Brauner
2024-11-29 14:52 ` Amir Goldstein
2024-11-30 12:22 ` [PATCH RFC 0/6] " Amir Goldstein
2024-12-01 8:43 ` Christian Brauner
2024-12-01 12:09 ` Amir Goldstein
2024-12-01 12:44 ` Christian Brauner
2024-11-29 14:27 ` [PATCH RFC v2 0/3] pidfs: file handle preliminaries Jeff Layton
2024-11-29 14:34 ` Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241202160452.2pg3qe4jymugp3su@quack3 \
--to=jack@suse.cz \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=erin.shepherd@e43.eu \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox