ANDROID: fuse: Support errors from fuse daemon in canonical path

Previously errors from the daemon in FUSE_CANONICAL_PATH were simply
ignored. In order to block inotifys, it is useful to be able to return
errors from this opcode.

Bug: 238619640
Test: inotify no longer works on /storage/emulated/0/Android/media but
      does on child folders
Change-Id: I1c65814f4ad0ccef330bca9764c2db15c71bf2be
Signed-off-by: Paul Lawrence <paullawrence@google.com>
This commit is contained in:
Paul Lawrence
2023-03-17 12:09:16 -07:00
committed by Treehugger Robot
parent 30c810b809
commit 44a94ece47
4 changed files with 26 additions and 7 deletions

View File

@@ -1941,7 +1941,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
err = copy_out_args(cs, req->args, nbytes);
fuse_copy_finish(cs);
if (!err && req->in.h.opcode == FUSE_CANONICAL_PATH) {
if (!err && req->in.h.opcode == FUSE_CANONICAL_PATH && !oh.error) {
char *path = (char *)req->args->out_args[0].value;
path[req->args->out_args[0].size - 1] = 0;

View File

@@ -416,13 +416,18 @@ static void fuse_dentry_canonical_path(const struct path *path,
fuse_canonical_path_backing,
fuse_canonical_path_finalize, path,
canonical_path);
if (fer.ret)
if (fer.ret) {
if (IS_ERR(fer.result))
canonical_path->dentry = fer.result;
return;
}
#endif
path_name = (char *)get_zeroed_page(GFP_KERNEL);
if (!path_name)
goto default_path;
if (!path_name) {
canonical_path->dentry = ERR_PTR(-ENOMEM);
return;
}
args.opcode = FUSE_CANONICAL_PATH;
args.nodeid = get_node_id(inode);
@@ -437,10 +442,15 @@ static void fuse_dentry_canonical_path(const struct path *path,
free_page((unsigned long)path_name);
if (err > 0)
return;
default_path:
if (err < 0) {
canonical_path->dentry = ERR_PTR(err);
return;
}
canonical_path->dentry = path->dentry;
canonical_path->mnt = path->mnt;
path_get(canonical_path);
return;
}
const struct dentry_operations fuse_dentry_operations = {

View File

@@ -712,7 +712,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
struct fsnotify_group *group;
struct inode *inode;
struct path path;
struct path alteredpath;
struct path alteredpath = {0};
struct path *canonical_path = &path;
struct fd f;
int ret;
@@ -765,6 +765,11 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
if (path.dentry->d_op->d_canonical_path) {
path.dentry->d_op->d_canonical_path(&path,
&alteredpath);
if (IS_ERR(alteredpath.dentry)) {
ret = PTR_ERR(alteredpath.dentry);
goto path_put_and_out;
}
canonical_path = &alteredpath;
path_put(&path);
}
@@ -776,6 +781,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
/* create/update an inode mark */
ret = inotify_update_watch(group, inode, mask);
path_put_and_out:
path_put(canonical_path);
fput_and_out:
fdput(f);

View File

@@ -102,10 +102,13 @@ static inline int fsnotify_file(struct file *file, __u32 mask)
if (mask & FS_OPEN) {
if (path->dentry->d_op &&
path->dentry->d_op->d_canonical_path) {
struct path lower_path;
struct path lower_path = {0};
int ret;
path->dentry->d_op->d_canonical_path(path, &lower_path);
if (IS_ERR(lower_path.dentry))
return PTR_ERR(lower_path.dentry);
ret = fsnotify_parent(lower_path.dentry, mask,
&lower_path, FSNOTIFY_EVENT_PATH);
path_put(&lower_path);