Skip to content

Commit eb59bd1

Browse files
author
Miklos Szeredi
committed
fuse: verify attributes
If a filesystem returns negative inode sizes, future reads on the file were causing the cpu to spin on truncate_pagecache. Create a helper to validate the attributes. This now does two things: - check the file mode - check if the file size fits in i_size without overflowing Reported-by: Arijit Banerjee <arijit@rubrik.com> Fixes: d8a5ba4 ("[PATCH] FUSE - core") Cc: <stable@vger.kernel.org> # v2.6.14 Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 31f4f5b commit eb59bd1

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎fs/fuse/dir.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
248248
kfree(forget);
249249
if (ret == -ENOMEM)
250250
goto out;
251-
if (ret || (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
251+
if (ret || fuse_invalid_attr(&outarg.attr) ||
252+
(outarg.attr.mode ^ inode->i_mode) & S_IFMT)
252253
goto invalid;
253254

254255
forget_all_cached_acls(inode);
@@ -319,6 +320,12 @@ int fuse_valid_type(int m)
319320
S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
320321
}
321322

323+
bool fuse_invalid_attr(struct fuse_attr *attr)
324+
{
325+
return !fuse_valid_type(attr->mode) ||
326+
attr->size > LLONG_MAX;
327+
}
328+
322329
int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
323330
struct fuse_entry_out *outarg, struct inode **inode)
324331
{
@@ -350,7 +357,7 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name
350357
err = -EIO;
351358
if (!outarg->nodeid)
352359
goto out_put_forget;
353-
if (!fuse_valid_type(outarg->attr.mode))
360+
if (fuse_invalid_attr(&outarg->attr))
354361
goto out_put_forget;
355362

356363
*inode = fuse_iget(sb, outarg->nodeid, outarg->generation,
@@ -475,7 +482,8 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
475482
goto out_free_ff;
476483

477484
err = -EIO;
478-
if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid))
485+
if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid) ||
486+
fuse_invalid_attr(&outentry.attr))
479487
goto out_free_ff;
480488

481489
ff->fh = outopen.fh;
@@ -583,7 +591,7 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_args *args,
583591
goto out_put_forget_req;
584592

585593
err = -EIO;
586-
if (invalid_nodeid(outarg.nodeid))
594+
if (invalid_nodeid(outarg.nodeid) || fuse_invalid_attr(&outarg.attr))
587595
goto out_put_forget_req;
588596

589597
if ((outarg.attr.mode ^ mode) & S_IFMT)
@@ -942,7 +950,8 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
942950
args.out_args[0].value = &outarg;
943951
err = fuse_simple_request(fc, &args);
944952
if (!err) {
945-
if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
953+
if (fuse_invalid_attr(&outarg.attr) ||
954+
(inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
946955
make_bad_inode(inode);
947956
err = -EIO;
948957
} else {
@@ -1563,7 +1572,8 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
15631572
goto error;
15641573
}
15651574

1566-
if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1575+
if (fuse_invalid_attr(&outarg.attr) ||
1576+
(inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
15671577
make_bad_inode(inode);
15681578
err = -EIO;
15691579
goto error;

‎fs/fuse/fuse_i.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,8 @@ void fuse_ctl_remove_conn(struct fuse_conn *fc);
989989
*/
990990
int fuse_valid_type(int m);
991991

992+
bool fuse_invalid_attr(struct fuse_attr *attr);
993+
992994
/**
993995
* Is current process allowed to perform filesystem operation?
994996
*/

‎fs/fuse/readdir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static int fuse_direntplus_link(struct file *file,
184184

185185
if (invalid_nodeid(o->nodeid))
186186
return -EIO;
187-
if (!fuse_valid_type(o->attr.mode))
187+
if (fuse_invalid_attr(&o->attr))
188188
return -EIO;
189189

190190
fc = get_fuse_conn(dir);

0 commit comments

Comments
 (0)