mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-14 09:09:56 +00:00
[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@emcraft.com> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
This commit is contained in:
parent
edc4ff7c08
commit
422138dd68
@ -56,15 +56,20 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
|
|||||||
mdatalen = sizeof(dev);
|
mdatalen = sizeof(dev);
|
||||||
D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of kdev_t\n", mdatalen));
|
D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of kdev_t\n", mdatalen));
|
||||||
} else if (S_ISLNK(inode->i_mode)) {
|
} else if (S_ISLNK(inode->i_mode)) {
|
||||||
|
down(&f->sem);
|
||||||
mdatalen = f->metadata->size;
|
mdatalen = f->metadata->size;
|
||||||
mdata = kmalloc(f->metadata->size, GFP_USER);
|
mdata = kmalloc(f->metadata->size, GFP_USER);
|
||||||
if (!mdata)
|
if (!mdata) {
|
||||||
|
up(&f->sem);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
}
|
||||||
ret = jffs2_read_dnode(c, f, f->metadata, mdata, 0, mdatalen);
|
ret = jffs2_read_dnode(c, f, f->metadata, mdata, 0, mdatalen);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
up(&f->sem);
|
||||||
kfree(mdata);
|
kfree(mdata);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
up(&f->sem);
|
||||||
D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of symlink target\n", mdatalen));
|
D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of symlink target\n", mdatalen));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user