reiserfs: Expand i_mutex to enclose lookup_one_len
2.6.30-rc3 introduced some sanity checks in the VFS code to avoid NFS bugs by ensuring that lookup_one_len is always called under i_mutex. This patch expands the i_mutex locking to enclose lookup_one_len. This was always required, but not not enforced in the reiserfs code since it does locking around the xattr interactions with the xattr_sem. This is obvious enough, and it survived an overnight 50 thread ACL test. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
67e55205ec
commit
5a6059c358
1 changed files with 14 additions and 18 deletions
|
@ -120,25 +120,20 @@ static struct dentry *lookup_or_create_dir(struct dentry *parent,
|
||||||
struct dentry *dentry;
|
struct dentry *dentry;
|
||||||
BUG_ON(!parent);
|
BUG_ON(!parent);
|
||||||
|
|
||||||
|
mutex_lock_nested(&parent->d_inode->i_mutex, I_MUTEX_XATTR);
|
||||||
dentry = lookup_one_len(name, parent, strlen(name));
|
dentry = lookup_one_len(name, parent, strlen(name));
|
||||||
if (IS_ERR(dentry))
|
if (!IS_ERR(dentry) && !dentry->d_inode) {
|
||||||
return dentry;
|
|
||||||
else if (!dentry->d_inode) {
|
|
||||||
int err = -ENODATA;
|
int err = -ENODATA;
|
||||||
|
|
||||||
if (xattr_may_create(flags)) {
|
if (xattr_may_create(flags))
|
||||||
mutex_lock_nested(&parent->d_inode->i_mutex,
|
|
||||||
I_MUTEX_XATTR);
|
|
||||||
err = xattr_mkdir(parent->d_inode, dentry, 0700);
|
err = xattr_mkdir(parent->d_inode, dentry, 0700);
|
||||||
mutex_unlock(&parent->d_inode->i_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
dentry = ERR_PTR(err);
|
dentry = ERR_PTR(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mutex_unlock(&parent->d_inode->i_mutex);
|
||||||
return dentry;
|
return dentry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +179,7 @@ fill_with_dentries(void *buf, const char *name, int namelen, loff_t offset,
|
||||||
{
|
{
|
||||||
struct reiserfs_dentry_buf *dbuf = buf;
|
struct reiserfs_dentry_buf *dbuf = buf;
|
||||||
struct dentry *dentry;
|
struct dentry *dentry;
|
||||||
|
WARN_ON_ONCE(!mutex_is_locked(&dbuf->xadir->d_inode->i_mutex));
|
||||||
|
|
||||||
if (dbuf->count == ARRAY_SIZE(dbuf->dentries))
|
if (dbuf->count == ARRAY_SIZE(dbuf->dentries))
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
|
@ -349,6 +345,7 @@ static struct dentry *xattr_lookup(struct inode *inode, const char *name,
|
||||||
if (IS_ERR(xadir))
|
if (IS_ERR(xadir))
|
||||||
return ERR_CAST(xadir);
|
return ERR_CAST(xadir);
|
||||||
|
|
||||||
|
mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR);
|
||||||
xafile = lookup_one_len(name, xadir, strlen(name));
|
xafile = lookup_one_len(name, xadir, strlen(name));
|
||||||
if (IS_ERR(xafile)) {
|
if (IS_ERR(xafile)) {
|
||||||
err = PTR_ERR(xafile);
|
err = PTR_ERR(xafile);
|
||||||
|
@ -360,18 +357,15 @@ static struct dentry *xattr_lookup(struct inode *inode, const char *name,
|
||||||
|
|
||||||
if (!xafile->d_inode) {
|
if (!xafile->d_inode) {
|
||||||
err = -ENODATA;
|
err = -ENODATA;
|
||||||
if (xattr_may_create(flags)) {
|
if (xattr_may_create(flags))
|
||||||
mutex_lock_nested(&xadir->d_inode->i_mutex,
|
|
||||||
I_MUTEX_XATTR);
|
|
||||||
err = xattr_create(xadir->d_inode, xafile,
|
err = xattr_create(xadir->d_inode, xafile,
|
||||||
0700|S_IFREG);
|
0700|S_IFREG);
|
||||||
mutex_unlock(&xadir->d_inode->i_mutex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
dput(xafile);
|
dput(xafile);
|
||||||
out:
|
out:
|
||||||
|
mutex_unlock(&xadir->d_inode->i_mutex);
|
||||||
dput(xadir);
|
dput(xadir);
|
||||||
if (err)
|
if (err)
|
||||||
return ERR_PTR(err);
|
return ERR_PTR(err);
|
||||||
|
@ -435,6 +429,7 @@ static int lookup_and_delete_xattr(struct inode *inode, const char *name)
|
||||||
if (IS_ERR(xadir))
|
if (IS_ERR(xadir))
|
||||||
return PTR_ERR(xadir);
|
return PTR_ERR(xadir);
|
||||||
|
|
||||||
|
mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR);
|
||||||
dentry = lookup_one_len(name, xadir, strlen(name));
|
dentry = lookup_one_len(name, xadir, strlen(name));
|
||||||
if (IS_ERR(dentry)) {
|
if (IS_ERR(dentry)) {
|
||||||
err = PTR_ERR(dentry);
|
err = PTR_ERR(dentry);
|
||||||
|
@ -442,14 +437,13 @@ static int lookup_and_delete_xattr(struct inode *inode, const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dentry->d_inode) {
|
if (dentry->d_inode) {
|
||||||
mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR);
|
|
||||||
err = xattr_unlink(xadir->d_inode, dentry);
|
err = xattr_unlink(xadir->d_inode, dentry);
|
||||||
mutex_unlock(&xadir->d_inode->i_mutex);
|
|
||||||
update_ctime(inode);
|
update_ctime(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
out_dput:
|
out_dput:
|
||||||
|
mutex_unlock(&xadir->d_inode->i_mutex);
|
||||||
dput(xadir);
|
dput(xadir);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -906,9 +900,9 @@ static int create_privroot(struct dentry *dentry)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct inode *inode = dentry->d_parent->d_inode;
|
struct inode *inode = dentry->d_parent->d_inode;
|
||||||
mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR);
|
WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
|
||||||
|
|
||||||
err = xattr_mkdir(inode, dentry, 0700);
|
err = xattr_mkdir(inode, dentry, 0700);
|
||||||
mutex_unlock(&inode->i_mutex);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
dentry = NULL;
|
dentry = NULL;
|
||||||
|
@ -980,6 +974,7 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
|
||||||
/* If we don't have the privroot located yet - go find it */
|
/* If we don't have the privroot located yet - go find it */
|
||||||
if (!REISERFS_SB(s)->priv_root) {
|
if (!REISERFS_SB(s)->priv_root) {
|
||||||
struct dentry *dentry;
|
struct dentry *dentry;
|
||||||
|
mutex_lock_nested(&s->s_root->d_inode->i_mutex, I_MUTEX_CHILD);
|
||||||
dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
|
dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
|
||||||
strlen(PRIVROOT_NAME));
|
strlen(PRIVROOT_NAME));
|
||||||
if (!IS_ERR(dentry)) {
|
if (!IS_ERR(dentry)) {
|
||||||
|
@ -993,6 +988,7 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
err = PTR_ERR(dentry);
|
err = PTR_ERR(dentry);
|
||||||
|
mutex_unlock(&s->s_root->d_inode->i_mutex);
|
||||||
|
|
||||||
if (!err && dentry) {
|
if (!err && dentry) {
|
||||||
s->s_root->d_op = &xattr_lookup_poison_ops;
|
s->s_root->d_op = &xattr_lookup_poison_ops;
|
||||||
|
|
Loading…
Reference in a new issue