fuse: Allocate only namelen buf memory in fuse_notify_
authorBernd Schubert <bschubert@ddn.com>
Mon, 16 Dec 2024 21:14:06 +0000 (22:14 +0100)
committerMiklos Szeredi <mszeredi@redhat.com>
Mon, 31 Mar 2025 12:59:27 +0000 (14:59 +0200)
fuse_notify_inval_entry and fuse_notify_delete were using fixed allocations
of FUSE_NAME_MAX to hold the file name. Often that large buffers are not
needed as file names might be smaller, so this uses the actual file name
size to do the allocation.

Signed-off-by: Bernd Schubert <bschubert@ddn.com>
Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/dev.c

index 4e4c2bcabdcad693a2de23952e7b9c0aff48c99b..45d15db3878772ba8a2fb80e6ed594e512378921 100644 (file)
@@ -1644,14 +1644,10 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
                                   struct fuse_copy_state *cs)
 {
        struct fuse_notify_inval_entry_out outarg;
-       int err = -ENOMEM;
-       char *buf;
+       int err;
+       char *buf = NULL;
        struct qstr name;
 
-       buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL);
-       if (!buf)
-               goto err;
-
        err = -EINVAL;
        if (size < sizeof(outarg))
                goto err;
@@ -1668,6 +1664,11 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
        if (size != sizeof(outarg) + outarg.namelen + 1)
                goto err;
 
+       err = -ENOMEM;
+       buf = kzalloc(outarg.namelen + 1, GFP_KERNEL);
+       if (!buf)
+               goto err;
+
        name.name = buf;
        name.len = outarg.namelen;
        err = fuse_copy_one(cs, buf, outarg.namelen + 1);
@@ -1692,14 +1693,10 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
                              struct fuse_copy_state *cs)
 {
        struct fuse_notify_delete_out outarg;
-       int err = -ENOMEM;
-       char *buf;
+       int err;
+       char *buf = NULL;
        struct qstr name;
 
-       buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL);
-       if (!buf)
-               goto err;
-
        err = -EINVAL;
        if (size < sizeof(outarg))
                goto err;
@@ -1716,6 +1713,11 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
        if (size != sizeof(outarg) + outarg.namelen + 1)
                goto err;
 
+       err = -ENOMEM;
+       buf = kzalloc(outarg.namelen + 1, GFP_KERNEL);
+       if (!buf)
+               goto err;
+
        name.name = buf;
        name.len = outarg.namelen;
        err = fuse_copy_one(cs, buf, outarg.namelen + 1);