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.

[drosen: I've combined this patch with a few others that fix dealing
with error codes (mostly ENOSYS) to make it harder to lose these again
in the future:

ANDROID: fsnotify: Do not notify lower fs of open when ENOSYS
ANDROID: fuse: Skip canonical path logic if ENOSYS
ANDROID: fuse: Fix the issue of fuse_dentry_canonical_path ]

Bug: 238619640
Test: inotify no longer works on /storage/emulated/0/Android/media but
      does on child folders
Bug: 326995824
Test: cts-tradefed run commandAndExit cts -m CtsOsTestCases -t android.os.cts.FileObserverTest
Bug: 330136711
Test: ./cts-tradefed run commandAndExit cts -m CtsIncidentHostTestCases -t com.android.server.cts.ErrorsTest#testTombstone

Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Icb15c090c6286c174338471a787712f8388de316
This commit is contained in:
Paul Lawrence
2023-04-04 17:04:55 +00:00
committed by Daniel Rosenberg
parent 3ca8e9b706
commit badfc4d005
6 changed files with 40 additions and 15 deletions
+1 -1
View File
@@ -2041,7 +2041,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;
+14 -4
View File
@@ -333,7 +333,7 @@ static struct vfsmount *fuse_dentry_automount(struct path *path)
* look up paths on its own. Instead, we handle the lookup as a special case
* inside of the write request.
*/
static void fuse_dentry_canonical_path(const struct path *path,
static int fuse_dentry_canonical_path(const struct path *path,
struct path *canonical_path)
{
struct inode *inode = d_inode(path->dentry);
@@ -343,9 +343,12 @@ static void fuse_dentry_canonical_path(const struct path *path,
char *path_name;
int err;
if (fm->fc->no_dentry_canonical_path)
goto out;
path_name = (char *)get_zeroed_page(GFP_KERNEL);
if (!path_name)
goto default_path;
return -ENOMEM;
args.opcode = FUSE_CANONICAL_PATH;
args.nodeid = get_node_id(inode);
@@ -359,11 +362,18 @@ static void fuse_dentry_canonical_path(const struct path *path,
err = fuse_simple_request(fm, &args);
free_page((unsigned long)path_name);
if (err > 0)
return;
default_path:
return 0;
if (err < 0 && err != -ENOSYS)
return err;
if (err == -ENOSYS)
fm->fc->no_dentry_canonical_path = 1;
out:
canonical_path->dentry = path->dentry;
canonical_path->mnt = path->mnt;
path_get(canonical_path);
return 0;
}
const struct dentry_operations fuse_dentry_operations = {
+3
View File
@@ -773,6 +773,9 @@ struct fuse_conn {
/** Is bmap not implemented by fs? */
unsigned no_bmap:1;
/** Is dentry_canonical_path not implemented by fs? */
unsigned no_dentry_canonical_path:1;
/** Is poll not implemented by fs? */
unsigned no_poll:1;
+9 -3
View File
@@ -783,10 +783,15 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
/* support stacked filesystems */
if (path.dentry && path.dentry->d_op) {
if (path.dentry->d_op->d_canonical_path) {
path.dentry->d_op->d_canonical_path(&path,
ret = path.dentry->d_op->d_canonical_path(&path,
&alteredpath);
canonical_path = &alteredpath;
path_put(&path);
if (ret != -ENOSYS) {
if (ret) {
goto path_put_and_out;
}
canonical_path = &alteredpath;
path_put(&path);
}
}
}
@@ -796,6 +801,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);
+1 -1
View File
@@ -150,7 +150,7 @@ struct dentry_operations {
struct vfsmount *(*d_automount)(struct path *);
int (*d_manage)(const struct path *, bool);
struct dentry *(*d_real)(struct dentry *, enum d_real_type type);
void (*d_canonical_path)(const struct path *, struct path *);
int (*d_canonical_path)(const struct path *, struct path *);
} ____cacheline_aligned;
/*
+12 -6
View File
@@ -137,13 +137,19 @@ static inline int fsnotify_file(struct file *file, __u32 mask)
struct path lower_path;
int ret;
path->dentry->d_op->d_canonical_path(path, &lower_path);
ret = fsnotify_parent(lower_path.dentry, mask,
&lower_path, FSNOTIFY_EVENT_PATH);
path_put(&lower_path);
ret = path->dentry->d_op->d_canonical_path(path,
&lower_path);
if (ret != -ENOSYS) {
if (ret)
return ret;
if (ret)
return ret;
ret = fsnotify_parent(lower_path.dentry, mask,
&lower_path, FSNOTIFY_EVENT_PATH);
path_put(&lower_path);
if (ret)
return ret;
}
}
}