Commit 39ee059a authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Linus Torvalds

[PATCH] fuse: check file type in lookup

Previously invalid types were quietly changed to regular files, but at
revalidation the inode was changed to bad.  This was rather inconsistent
behavior.

Now check if the type is valid on initial lookup, and return -EIO if not.
Signed-off-by: default avatarMiklos Szeredi <miklos@szeredi.hu>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 6ad84aca
...@@ -166,6 +166,12 @@ static struct dentry_operations fuse_dentry_operations = { ...@@ -166,6 +166,12 @@ static struct dentry_operations fuse_dentry_operations = {
.d_revalidate = fuse_dentry_revalidate, .d_revalidate = fuse_dentry_revalidate,
}; };
static inline int valid_mode(int m)
{
return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) ||
S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
}
static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
struct nameidata *nd) struct nameidata *nd)
{ {
...@@ -185,7 +191,8 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, ...@@ -185,7 +191,8 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
fuse_lookup_init(req, dir, entry, &outarg); fuse_lookup_init(req, dir, entry, &outarg);
request_send(fc, req); request_send(fc, req);
err = req->out.h.error; err = req->out.h.error;
if (!err && outarg.nodeid && invalid_nodeid(outarg.nodeid)) if (!err && ((outarg.nodeid && invalid_nodeid(outarg.nodeid)) ||
!valid_mode(outarg.attr.mode)))
err = -EIO; err = -EIO;
if (!err && outarg.nodeid) { if (!err && outarg.nodeid) {
inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
...@@ -328,10 +335,13 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req, ...@@ -328,10 +335,13 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
fuse_put_request(fc, req); fuse_put_request(fc, req);
return err; return err;
} }
if (invalid_nodeid(outarg.nodeid)) { err = -EIO;
fuse_put_request(fc, req); if (invalid_nodeid(outarg.nodeid))
return -EIO; goto out_put_request;
}
if ((outarg.attr.mode ^ mode) & S_IFMT)
goto out_put_request;
inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
&outarg.attr); &outarg.attr);
if (!inode) { if (!inode) {
...@@ -340,8 +350,7 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req, ...@@ -340,8 +350,7 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
} }
fuse_put_request(fc, req); fuse_put_request(fc, req);
/* Don't allow userspace to do really stupid things... */ if (dir_alias(inode)) {
if (((inode->i_mode ^ mode) & S_IFMT) || dir_alias(inode)) {
iput(inode); iput(inode);
return -EIO; return -EIO;
} }
...@@ -350,6 +359,10 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req, ...@@ -350,6 +359,10 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
fuse_change_timeout(entry, &outarg); fuse_change_timeout(entry, &outarg);
fuse_invalidate_attr(dir); fuse_invalidate_attr(dir);
return 0; return 0;
out_put_request:
fuse_put_request(fc, req);
return err;
} }
static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode, static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode,
......
...@@ -135,12 +135,8 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr) ...@@ -135,12 +135,8 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
fuse_init_common(inode); fuse_init_common(inode);
init_special_inode(inode, inode->i_mode, init_special_inode(inode, inode->i_mode,
new_decode_dev(attr->rdev)); new_decode_dev(attr->rdev));
} else { } else
/* Don't let user create weird files */ BUG();
inode->i_mode = S_IFREG;
fuse_init_common(inode);
fuse_init_file_inode(inode);
}
} }
static int fuse_inode_eq(struct inode *inode, void *_nodeidp) static int fuse_inode_eq(struct inode *inode, void *_nodeidp)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment