fuse: add bounds check before truncate_pagecache
Subsystems (2)
PATCH 1/1 fuse: add bounds check before truncate_pagecache
If a filesystem returns negative inode sizes, future reads on the file were causing the cpu to spin on truncate_pagecache. This seems like invalid behaviour as a buggy / malicious filesystem can cause a lockup.
This patch checks for negative sizes before truncating the page cache.
--- fs/fuse/inode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/fuse/inode.c +3 -1
@@ -236,7 +236,9 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,bool inval = false;if (oldsize != attr->size) { -truncate_pagecache (inode, attr->size); +if ((off_t )attr->size >=0 ) +truncate_pagecache (inode, attr->size); + inval = true; }else if (fc->auto_inval_data) {struct timespec64 new_mtime = {
Signature · 1 line
1.9.1
Miklos Szeredi
maintainerQuoted 20 lines · Arijit Banerjee
If a filesystem returns negative inode sizes, future reads on the file were causing the cpu to spin on
truncate_pagecache. This seems like invalid behaviour as a buggy / malicious filesystem can cause a lockup.This patch checks for negative sizes before truncating the page cache.
Signed-off-by Arijit Banerjee <[email protected]>--- fs/fuse/inode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/fuse/inode.c +0
-0
fs/fuse/inode.c void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, · line 241
Quoted 7 lines
fs/fuse/inode.c +3
-1@@ -236,7 +236,9 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,bool inval = false;if (oldsize != attr->size) { -truncate_pagecache (inode, attr->size); +if ((off_t )attr->size >=0 ) +truncate_pagecache (inode, attr->size); +
Hi,
Thanks for the report and patch.
I'd fix it differently: passing a negative size should be invalid entirely, so we should validate attr.size before calling fuse_change_attributes...() and return -EIO, just like in case of an invalid attr.mode. Do you agree?
E.g. implement a new function: fuse_validate_attr() that returns false if some attribute is invalid. We possibly need to look at other attributes as well for invalid values.
Thanks,
Miklos