]> err.no Git - linux-2.6/blobdiff - fs/fuse/dir.c
[PATCH] fuse: check directory aliasing in mkdir
[linux-2.6] / fs / fuse / dir.c
index 83be119ef0670a4510fe8934b285acf667e1f252..3a47247a889e3ec107daec6b77f47af0eec00591 100644 (file)
@@ -74,6 +74,19 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
        return 1;
 }
 
+static int dir_alias(struct inode *inode)
+{
+       if (S_ISDIR(inode->i_mode)) {
+               /* Don't allow creating an alias to a directory  */
+               struct dentry *alias = d_find_alias(inode);
+               if (alias) {
+                       dput(alias);
+                       return 1;
+               }
+       }
+       return 0;
+}
+
 static struct dentry_operations fuse_dentry_operations = {
        .d_revalidate   = fuse_dentry_revalidate,
 };
@@ -263,7 +276,7 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
        fuse_put_request(fc, req);
 
        /* Don't allow userspace to do really stupid things... */
-       if ((inode->i_mode ^ mode) & S_IFMT) {
+       if (((inode->i_mode ^ mode) & S_IFMT) || dir_alias(inode)) {
                iput(inode);
                return -EIO;
        }
@@ -763,29 +776,29 @@ static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync)
        return file ? fuse_fsync_common(file, de, datasync, 1) : 0;
 }
 
-static unsigned iattr_to_fattr(struct iattr *iattr, struct fuse_attr *fattr)
+static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
 {
        unsigned ivalid = iattr->ia_valid;
-       unsigned fvalid = 0;
-
-       memset(fattr, 0, sizeof(*fattr));
 
        if (ivalid & ATTR_MODE)
-               fvalid |= FATTR_MODE,   fattr->mode = iattr->ia_mode;
+               arg->valid |= FATTR_MODE,   arg->mode = iattr->ia_mode;
        if (ivalid & ATTR_UID)
-               fvalid |= FATTR_UID,    fattr->uid = iattr->ia_uid;
+               arg->valid |= FATTR_UID,    arg->uid = iattr->ia_uid;
        if (ivalid & ATTR_GID)
-               fvalid |= FATTR_GID,    fattr->gid = iattr->ia_gid;
+               arg->valid |= FATTR_GID,    arg->gid = iattr->ia_gid;
        if (ivalid & ATTR_SIZE)
-               fvalid |= FATTR_SIZE,   fattr->size = iattr->ia_size;
+               arg->valid |= FATTR_SIZE,   arg->size = iattr->ia_size;
        /* You can only _set_ these together (they may change by themselves) */
        if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) {
-               fvalid |= FATTR_ATIME | FATTR_MTIME;
-               fattr->atime = iattr->ia_atime.tv_sec;
-               fattr->mtime = iattr->ia_mtime.tv_sec;
+               arg->valid |= FATTR_ATIME | FATTR_MTIME;
+               arg->atime = iattr->ia_atime.tv_sec;
+               arg->mtime = iattr->ia_mtime.tv_sec;
+       }
+       if (ivalid & ATTR_FILE) {
+               struct fuse_file *ff = iattr->ia_file->private_data;
+               arg->valid |= FATTR_FH;
+               arg->fh = ff->fh;
        }
-
-       return fvalid;
 }
 
 static int fuse_setattr(struct dentry *entry, struct iattr *attr)
@@ -820,7 +833,7 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
                return -EINTR;
 
        memset(&inarg, 0, sizeof(inarg));
-       inarg.valid = iattr_to_fattr(attr, &inarg.attr);
+       iattr_to_fattr(attr, &inarg);
        req->in.h.opcode = FUSE_SETATTR;
        req->in.h.nodeid = get_node_id(inode);
        req->inode = inode;
@@ -874,14 +887,9 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
        err = fuse_lookup_iget(dir, entry, &inode);
        if (err)
                return ERR_PTR(err);
-       if (inode && S_ISDIR(inode->i_mode)) {
-               /* Don't allow creating an alias to a directory  */
-               struct dentry *alias = d_find_alias(inode);
-               if (alias) {
-                       dput(alias);
-                       iput(inode);
-                       return ERR_PTR(-EIO);
-               }
+       if (inode && dir_alias(inode)) {
+               iput(inode);
+               return ERR_PTR(-EIO);
        }
        d_add(entry, inode);
        return NULL;