Skip to contentSkip to conversation

fuse: add bounds check before truncate_pagecache

PATCH In review Arijit Banerjee 2 participants 2 messages Feb 18, 2019 – Feb 26, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 1b3f3b6..5744d16 100644
@@ -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
maintainer
#1 lore raw
Quoted 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.

---
 fs/fuse/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/fuse/inode.c +0 -0
index 1b3f3b6..5744d16 100644

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