diff mbox series

fuse: allow O_PATH fd for FUSE_DEV_IOC_BACKING_OPEN

Message ID 20240913104703.1673180-1-mszeredi@redhat.com (mailing list archive)
State New
Headers show
Series fuse: allow O_PATH fd for FUSE_DEV_IOC_BACKING_OPEN | expand

Commit Message

Miklos Szeredi Sept. 13, 2024, 10:47 a.m. UTC
Only f_path is used from backing files registered with
FUSE_DEV_IOC_BACKING_OPEN, so it makes sense to allow O_PATH descriptors.

O_PATH files have an empty f_op, so don't check read_iter/write_iter.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 fs/fuse/passthrough.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Amir Goldstein Sept. 13, 2024, 11:04 a.m. UTC | #1
On Fri, Sep 13, 2024 at 12:50 PM Miklos Szeredi <mszeredi@redhat.com> wrote:
>
> Only f_path is used from backing files registered with
> FUSE_DEV_IOC_BACKING_OPEN, so it makes sense to allow O_PATH descriptors.
>
> O_PATH files have an empty f_op, so don't check read_iter/write_iter.
>
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>

Agreed.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>

> ---
>  fs/fuse/passthrough.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c
> index 9666d13884ce..ba3207f6c4ce 100644
> --- a/fs/fuse/passthrough.c
> +++ b/fs/fuse/passthrough.c
> @@ -228,15 +228,11 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
>         if (map->flags || map->padding)
>                 goto out;
>
> -       file = fget(map->fd);
> +       file = fget_raw(map->fd);
>         res = -EBADF;
>         if (!file)
>                 goto out;
>
> -       res = -EOPNOTSUPP;
> -       if (!file->f_op->read_iter || !file->f_op->write_iter)
> -               goto out_fput;
> -

FWIW, I have made those sanity checks opt-in in my
fuse-backing-inode-wip branch:
https://github.com/amir73il/linux/commit/24c9a87bb11d76414b85960c0e3638a655a9c9a1

But that could be added later.

Thanks,
Amir.
Miklos Szeredi Sept. 13, 2024, 11:12 a.m. UTC | #2
On Fri, 13 Sept 2024 at 13:05, Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Fri, Sep 13, 2024 at 12:50 PM Miklos Szeredi <mszeredi@redhat.com> wrote:

> > -       res = -EOPNOTSUPP;
> > -       if (!file->f_op->read_iter || !file->f_op->write_iter)
> > -               goto out_fput;
> > -
>
> FWIW, I have made those sanity checks opt-in in my
> fuse-backing-inode-wip branch:
> https://github.com/amir73il/linux/commit/24c9a87bb11d76414b85960c0e3638a655a9c9a1
>
> But that could be added later.

This is the wrong place to check the f_op.

We could do it in backing_file_open(), but this isn't going to be a
common error, so I guess just returning an error at read/write time is
also okay.

Thanks,
Miklos
Amir Goldstein Sept. 13, 2024, 11:44 a.m. UTC | #3
On Fri, Sep 13, 2024 at 1:13 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
>
> On Fri, 13 Sept 2024 at 13:05, Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > On Fri, Sep 13, 2024 at 12:50 PM Miklos Szeredi <mszeredi@redhat.com> wrote:
>
> > > -       res = -EOPNOTSUPP;
> > > -       if (!file->f_op->read_iter || !file->f_op->write_iter)
> > > -               goto out_fput;
> > > -
> >
> > FWIW, I have made those sanity checks opt-in in my
> > fuse-backing-inode-wip branch:
> > https://github.com/amir73il/linux/commit/24c9a87bb11d76414b85960c0e3638a655a9c9a1
> >
> > But that could be added later.
>
> This is the wrong place to check the f_op.
>
> We could do it in backing_file_open(), but this isn't going to be a
> common error, so I guess just returning an error at read/write time is
> also okay.
>

Yeh. works for me.

Thanks,
Amir.
diff mbox series

Patch

diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c
index 9666d13884ce..ba3207f6c4ce 100644
--- a/fs/fuse/passthrough.c
+++ b/fs/fuse/passthrough.c
@@ -228,15 +228,11 @@  int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 	if (map->flags || map->padding)
 		goto out;
 
-	file = fget(map->fd);
+	file = fget_raw(map->fd);
 	res = -EBADF;
 	if (!file)
 		goto out;
 
-	res = -EOPNOTSUPP;
-	if (!file->f_op->read_iter || !file->f_op->write_iter)
-		goto out_fput;
-
 	backing_sb = file_inode(file)->i_sb;
 	res = -ELOOP;
 	if (backing_sb->s_stack_depth >= fc->max_stack_depth)