From: Jeff Mahoney <jeffm@suse.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
ReiserFS Mailing List <reiserfs-devel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Al Viro <viro@ftp.linux.org.uk>,
Alexander Beregalov <a.beregalov@gmail.com>,
David <david@unsolicited.net>
Subject: [PATCH] reiserfs: Expand i_mutex to enclose lookup_one_len
Date: Fri, 01 May 2009 12:11:12 -0400 [thread overview]
Message-ID: <49FB1F20.8040400@suse.com> (raw)
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, but it survived an overnight 50 thread ACL test.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/reiserfs/xattr.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -120,25 +120,20 @@ static struct dentry *lookup_or_create_d
struct dentry *dentry;
BUG_ON(!parent);
+ mutex_lock_nested(&parent->d_inode->i_mutex, I_MUTEX_XATTR);
dentry = lookup_one_len(name, parent, strlen(name));
- if (IS_ERR(dentry))
- return dentry;
- else if (!dentry->d_inode) {
+ if (!IS_ERR(dentry) && !dentry->d_inode) {
int err = -ENODATA;
- if (xattr_may_create(flags)) {
- mutex_lock_nested(&parent->d_inode->i_mutex,
- I_MUTEX_XATTR);
+ if (xattr_may_create(flags))
err = xattr_mkdir(parent->d_inode, dentry, 0700);
- mutex_unlock(&parent->d_inode->i_mutex);
- }
if (err) {
dput(dentry);
dentry = ERR_PTR(err);
}
}
-
+ mutex_unlock(&parent->d_inode->i_mutex);
return dentry;
}
@@ -184,6 +179,7 @@ fill_with_dentries(void *buf, const char
{
struct reiserfs_dentry_buf *dbuf = buf;
struct dentry *dentry;
+ WARN_ON_ONCE(!mutex_is_locked(&dbuf->xadir->d_inode->i_mutex));
if (dbuf->count == ARRAY_SIZE(dbuf->dentries))
return -ENOSPC;
@@ -349,6 +345,7 @@ static struct dentry *xattr_lookup(struc
if (IS_ERR(xadir))
return ERR_CAST(xadir);
+ mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR);
xafile = lookup_one_len(name, xadir, strlen(name));
if (IS_ERR(xafile)) {
err = PTR_ERR(xafile);
@@ -360,18 +357,15 @@ static struct dentry *xattr_lookup(struc
if (!xafile->d_inode) {
err = -ENODATA;
- if (xattr_may_create(flags)) {
- mutex_lock_nested(&xadir->d_inode->i_mutex,
- I_MUTEX_XATTR);
+ if (xattr_may_create(flags))
err = xattr_create(xadir->d_inode, xafile,
0700|S_IFREG);
- mutex_unlock(&xadir->d_inode->i_mutex);
- }
}
if (err)
dput(xafile);
out:
+ mutex_unlock(&xadir->d_inode->i_mutex);
dput(xadir);
if (err)
return ERR_PTR(err);
@@ -435,6 +429,7 @@ static int lookup_and_delete_xattr(struc
if (IS_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));
if (IS_ERR(dentry)) {
err = PTR_ERR(dentry);
@@ -442,14 +437,13 @@ static int lookup_and_delete_xattr(struc
}
if (dentry->d_inode) {
- mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR);
err = xattr_unlink(xadir->d_inode, dentry);
- mutex_unlock(&xadir->d_inode->i_mutex);
update_ctime(inode);
}
dput(dentry);
out_dput:
+ mutex_unlock(&xadir->d_inode->i_mutex);
dput(xadir);
return err;
}
@@ -906,9 +900,9 @@ static int create_privroot(struct dentry
{
int err;
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);
- mutex_unlock(&inode->i_mutex);
if (err) {
dput(dentry);
dentry = NULL;
@@ -980,6 +974,7 @@ int reiserfs_xattr_init(struct super_blo
/* If we don't have the privroot located yet - go find it */
if (!REISERFS_SB(s)->priv_root) {
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,
strlen(PRIVROOT_NAME));
if (!IS_ERR(dentry)) {
@@ -993,6 +988,7 @@ int reiserfs_xattr_init(struct super_blo
}
} else
err = PTR_ERR(dentry);
+ mutex_unlock(&s->s_root->d_inode->i_mutex);
if (!err && dentry) {
s->s_root->d_op = &xattr_lookup_poison_ops;
--
Jeff Mahoney
SUSE Labs
next reply other threads:[~2009-05-01 16:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-01 16:11 Jeff Mahoney [this message]
2009-05-01 16:37 ` [PATCH] reiserfs: Expand i_mutex to enclose lookup_one_len Alexander Beregalov
2009-05-01 19:56 ` Andrew Morton
2009-05-01 20:36 ` Jeff Mahoney
2009-05-03 8:52 ` Al Viro
2009-05-03 9:15 ` Al Viro
2009-05-03 10:06 ` Al Viro
2009-05-04 4:51 ` Jeff Mahoney
2009-05-04 6:13 ` Al Viro
2009-05-04 16:40 ` Jeff Mahoney
2009-05-05 19:29 ` Jeff Mahoney
2009-05-04 5:01 ` Jeff Mahoney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49FB1F20.8040400@suse.com \
--to=jeffm@suse.com \
--cc=a.beregalov@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@unsolicited.net \
--cc=linux-kernel@vger.kernel.org \
--cc=reiserfs-devel@vger.kernel.org \
--cc=viro@ftp.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox