[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <b9f2a2c2ee33565b158a4bbe97cc2c2861881f93.1649370874.git.khalid.aziz@oracle.com>
Date: Mon, 11 Apr 2022 10:05:49 -0600
From: Khalid Aziz <khalid.aziz@...cle.com>
To: akpm@...ux-foundation.org, willy@...radead.org
Cc: Khalid Aziz <khalid.aziz@...cle.com>, aneesh.kumar@...ux.ibm.com,
arnd@...db.de, 21cnbao@...il.com, corbet@....net,
dave.hansen@...ux.intel.com, david@...hat.com,
ebiederm@...ssion.com, hagen@...u.net, jack@...e.cz,
keescook@...omium.org, kirill@...temov.name, kucharsk@...il.com,
linkinjeon@...nel.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
longpeng2@...wei.com, luto@...nel.org, markhemm@...glemail.com,
pcc@...gle.com, rppt@...nel.org, sieberf@...zon.com,
sjpark@...zon.de, surenb@...gle.com, tst@...oebel-theuer.de,
yzaikin@...gle.com
Subject: [PATCH v1 05/14] mm/mshare: Add locking to msharefs syscalls
Lock the root inode for msharefs when creating a new file or
deleting an existing one to avoid races. mshare syscalls are low
frequency operations, so locking the root inode is reasonable.
Signed-off-by: Khalid Aziz <khalid.aziz@...cle.com>
---
mm/mshare.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/mm/mshare.c b/mm/mshare.c
index b9d7836f9bd1..85ccb7f02f33 100644
--- a/mm/mshare.c
+++ b/mm/mshare.c
@@ -195,11 +195,12 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr,
err = msharefs_d_hash(msharefs_sb->s_root, &namestr);
if (err)
goto err_out;
+ inode_lock(d_inode(msharefs_sb->s_root));
dentry = d_lookup(msharefs_sb->s_root, &namestr);
if (dentry && (oflag & (O_EXCL|O_CREAT))) {
err = -EEXIST;
dput(dentry);
- goto err_out;
+ goto err_unlock_inode;
}
if (dentry) {
@@ -232,6 +233,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr,
goto err_relinfo;
}
+ inode_unlock(d_inode(msharefs_sb->s_root));
putname(fname);
return 0;
@@ -239,6 +241,8 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr,
kfree(info);
err_relmm:
mmput(mm);
+err_unlock_inode:
+ inode_unlock(d_inode(msharefs_sb->s_root));
err_out:
putname(fname);
return err;
@@ -264,10 +268,11 @@ SYSCALL_DEFINE1(mshare_unlink, const char *, name)
err = msharefs_d_hash(msharefs_sb->s_root, &namestr);
if (err)
goto err_out;
+ inode_lock(d_inode(msharefs_sb->s_root));
dentry = d_lookup(msharefs_sb->s_root, &namestr);
if (dentry == NULL) {
err = -EINVAL;
- goto err_out;
+ goto err_unlock_inode;
}
inode = d_inode(dentry);
@@ -290,11 +295,14 @@ SYSCALL_DEFINE1(mshare_unlink, const char *, name)
dput(dentry);
}
+ inode_unlock(d_inode(msharefs_sb->s_root));
putname(fname);
return 0;
err_dput:
dput(dentry);
+err_unlock_inode:
+ inode_unlock(d_inode(msharefs_sb->s_root));
err_out:
putname(fname);
return err;
--
2.32.0
Powered by blists - more mailing lists