Skip to content

Commit 2412085

Browse files
bsberndMiklos Szeredi
authored andcommitted
fuse: Allocate only namelen buf memory in fuse_notify_
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>
1 parent 9b17cb5 commit 2412085

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

fs/fuse/dev.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,14 +1644,10 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
16441644
struct fuse_copy_state *cs)
16451645
{
16461646
struct fuse_notify_inval_entry_out outarg;
1647-
int err = -ENOMEM;
1648-
char *buf;
1647+
int err;
1648+
char *buf = NULL;
16491649
struct qstr name;
16501650

1651-
buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL);
1652-
if (!buf)
1653-
goto err;
1654-
16551651
err = -EINVAL;
16561652
if (size < sizeof(outarg))
16571653
goto err;
@@ -1668,6 +1664,11 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
16681664
if (size != sizeof(outarg) + outarg.namelen + 1)
16691665
goto err;
16701666

1667+
err = -ENOMEM;
1668+
buf = kzalloc(outarg.namelen + 1, GFP_KERNEL);
1669+
if (!buf)
1670+
goto err;
1671+
16711672
name.name = buf;
16721673
name.len = outarg.namelen;
16731674
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,
16921693
struct fuse_copy_state *cs)
16931694
{
16941695
struct fuse_notify_delete_out outarg;
1695-
int err = -ENOMEM;
1696-
char *buf;
1696+
int err;
1697+
char *buf = NULL;
16971698
struct qstr name;
16981699

1699-
buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL);
1700-
if (!buf)
1701-
goto err;
1702-
17031700
err = -EINVAL;
17041701
if (size < sizeof(outarg))
17051702
goto err;
@@ -1716,6 +1713,11 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
17161713
if (size != sizeof(outarg) + outarg.namelen + 1)
17171714
goto err;
17181715

1716+
err = -ENOMEM;
1717+
buf = kzalloc(outarg.namelen + 1, GFP_KERNEL);
1718+
if (!buf)
1719+
goto err;
1720+
17191721
name.name = buf;
17201722
name.len = outarg.namelen;
17211723
err = fuse_copy_one(cs, buf, outarg.namelen + 1);

0 commit comments

Comments
 (0)