[PATCH v3] ubifs: make ubifs_[get|set]xattr atomic
Dongsheng Yang
yangds.fnst at cn.fujitsu.com
Thu Aug 6 23:07:20 PDT 2015
This commit make the ubifs_[get|set]xattr protected by ui_mutex.
Originally, there is a possibility that ubifs_getxattr to get
a wrong value.
P1 P2
---------- ----------
ubifs_getxattr ubifs_setxattr
- kfree()
- memcpy()
- kmemdup()
Then ubifs_getxattr() would get a non-sense data. To solve this
problem, this commit make the xattr of ubifs_inode updated in
atomic.
Signed-off-by: Dongsheng Yang <yangds.fnst at cn.fujitsu.com>
---
-v2
fix a dead lock in error flow
fs/ubifs/xattr.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
index 96f3448..33badeb 100644
--- a/fs/ubifs/xattr.c
+++ b/fs/ubifs/xattr.c
@@ -208,14 +208,17 @@ static int change_xattr(struct ubifs_info *c, struct inode *host,
if (err)
return err;
+ mutex_lock(&ui->ui_mutex);
kfree(ui->data);
ui->data = kmemdup(value, size, GFP_NOFS);
if (!ui->data) {
+ mutex_unlock(&ui->ui_mutex);
err = -ENOMEM;
goto out_free;
}
inode->i_size = ui->ui_size = size;
ui->data_len = size;
+ mutex_unlock(&ui->ui_mutex);
mutex_lock(&host_ui->ui_mutex);
host->i_ctime = ubifs_current_time(host);
@@ -409,6 +412,7 @@ ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf,
ubifs_assert(inode->i_size == ui->data_len);
ubifs_assert(ubifs_inode(host)->xattr_size > ui->data_len);
+ mutex_lock(&ui->ui_mutex);
if (buf) {
/* If @buf is %NULL we are supposed to return the length */
if (ui->data_len > size) {
@@ -423,6 +427,7 @@ ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf,
err = ui->data_len;
out_iput:
+ mutex_unlock(&ui->ui_mutex);
iput(inode);
out_unlock:
kfree(xent);
--
1.8.4.2
More information about the linux-mtd
mailing list