Skip to contentSkip to conversation

fuse: allow O_PATH fd for FUSE_DEV_IOC_BACKING_OPEN

PATCH In review Miklos Szeredi 3 participants 4 messages Sep 13, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fuse: allow O_PATH fd for FUSE_DEV_IOC_BACKING_OPEN

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.

---
 fs/fuse/passthrough.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/fuse/passthrough.c +1 -5
index 9666d13884ce..ba3207f6c4ce 100644
@@ -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)
Signature · 1 line
2.46.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Miklos Szeredi

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.

Agreed.

Quoted 12 lines
---
 fs/fuse/passthrough.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/fuse/passthrough.c +0 -0
index 9666d13884ce..ba3207f6c4ce 100644
@@ -228,15 +228,11 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
        if (map->flags || map->padding)
                goto out;
 

fs/fuse/passthrough.c int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map) · line 239

Quoted 10 lines
fs/fuse/passthrough.c +1 -5
-       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.

maintainer
#2 lore raw
Quoted 8 lines · Amir Goldstein

fs/fuse/passthrough.c int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map) · line 239

Quoted 4 lines · Miklos Szeredi
fs/fuse/passthrough.c +0 -4
-       res = -EOPNOTSUPP;
-       if (!file->f_op->read_iter || !file->f_op->write_iter)
-               goto out_fput;
-
Quoted 5 lines

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

maintainer
#3 lore raw
Quoted 14 lines · Miklos Szeredi
Quoted 12 lines · Amir Goldstein

fs/fuse/passthrough.c int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map) · line 239

Quoted 4 lines · Miklos Szeredi
fs/fuse/passthrough.c +0 -4
-       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

Quoted 8 lines
Quoted 1 line

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.