[JFFS2] Fix race in setting file attributes

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Fri May 5 17:59:01 EDT 2006


commit 422138dd68202fbd8ca9fb0df65e92d733249374
tree 6991cf489ef3fa040309c2e715e02d61632fa7d4
parent edc4ff7c08e9885c40e60c4fb39fa42cc91a0602
author Dmitry Bazhenov <atrey at emcraft.com> Fri, 05 May 2006 22:46:49 +0100
committer David Woodhouse <dwmw2 at infradead.org> Fri, 05 May 2006 22:46:49 +0100

[JFFS2] Fix race in setting file attributes

It seems like there is a potential race in the function jffs2_do_setattr()
in the case when attributes of a symlink are updated. The symlink metadata
is read without having f->sem locked.

The following patch should fix the race.

Signed-off-by: Dmitry Bazhenov <atrey at emcraft.com>
Signed-off-by: David Woodhouse <dwmw2 at infradead.org>

 fs/jffs2/fs.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 09e5d10..ea1f37d 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -56,15 +56,20 @@ static int jffs2_do_setattr (struct inod
 		mdatalen = sizeof(dev);
 		D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of kdev_t\n", mdatalen));
 	} else if (S_ISLNK(inode->i_mode)) {
+		down(&f->sem);
 		mdatalen = f->metadata->size;
 		mdata = kmalloc(f->metadata->size, GFP_USER);
-		if (!mdata)
+		if (!mdata) {
+			up(&f->sem);
 			return -ENOMEM;
+		}
 		ret = jffs2_read_dnode(c, f, f->metadata, mdata, 0, mdatalen);
 		if (ret) {
+			up(&f->sem);
 			kfree(mdata);
 			return ret;
 		}
+		up(&f->sem);
 		D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of symlink target\n", mdatalen));
 	}
 




More information about the linux-mtd-cvs mailing list