fuse: readdirplus: sanity checks
authorMiklos Szeredi <mszeredi@suse.cz>
Wed, 17 Jul 2013 12:53:53 +0000 (14:53 +0200)
committerMiklos Szeredi <mszeredi@suse.cz>
Wed, 17 Jul 2013 12:53:53 +0000 (14:53 +0200)
Add sanity checks before adding or updating an entry with data received
from readdirplus.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
CC: stable@vger.kernel.org
fs/fuse/dir.c

index 2ae5308174e2938c49422c1fe08c1a316f642cfa..bb6829720dd61e4c84e672b68bd98788456474bd 100644 (file)
@@ -1223,6 +1223,12 @@ static int fuse_direntplus_link(struct file *file,
                if (name.name[1] == '.' && name.len == 2)
                        return 0;
        }
+
+       if (invalid_nodeid(o->nodeid))
+               return -EIO;
+       if (!fuse_valid_type(o->attr.mode))
+               return -EIO;
+
        fc = get_fuse_conn(dir);
 
        name.hash = full_name_hash(name.name, name.len);
@@ -1231,10 +1237,14 @@ static int fuse_direntplus_link(struct file *file,
                inode = dentry->d_inode;
                if (!inode) {
                        d_drop(dentry);
-               } else if (get_node_id(inode) != o->nodeid) {
+               } else if (get_node_id(inode) != o->nodeid ||
+                          ((o->attr.mode ^ inode->i_mode) & S_IFMT)) {
                        err = d_invalidate(dentry);
                        if (err)
                                goto out;
+               } else if (is_bad_inode(inode)) {
+                       err = -EIO;
+                       goto out;
                } else {
                        struct fuse_inode *fi;
                        fi = get_fuse_inode(inode);