mirror of
https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux-stable.git
synced 2025-10-03 21:39:54 +10:00
smb: client: fix race with concurrent opens in unlink(2)
[ Upstream commit 0af1561b2d
]
According to some logs reported by customers, CIFS client might end up
reporting unlinked files as existing in stat(2) due to concurrent
opens racing with unlink(2).
Besides sending the removal request to the server, the unlink process
could involve closing any deferred close as well as marking all
existing open handles as deleted to prevent them from deferring
closes, which increases the race window for potential concurrent
opens.
Fix this by unhashing the dentry in cifs_unlink() to prevent any
subsequent opens. Any open attempts, while we're still unlinking,
will block on parent's i_rwsem.
Reported-by: Jay Shin <jaeshin@redhat.com>
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Reviewed-by: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-cifs@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
b40551968d
commit
c3848c3dc8
@ -1649,15 +1649,24 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
|
||||
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
|
||||
struct tcon_link *tlink;
|
||||
struct cifs_tcon *tcon;
|
||||
__u32 dosattr = 0, origattr = 0;
|
||||
struct TCP_Server_Info *server;
|
||||
struct iattr *attrs = NULL;
|
||||
__u32 dosattr = 0, origattr = 0;
|
||||
bool rehash = false;
|
||||
|
||||
cifs_dbg(FYI, "cifs_unlink, dir=0x%p, dentry=0x%p\n", dir, dentry);
|
||||
|
||||
if (unlikely(cifs_forced_shutdown(cifs_sb)))
|
||||
return -EIO;
|
||||
|
||||
/* Unhash dentry in advance to prevent any concurrent opens */
|
||||
spin_lock(&dentry->d_lock);
|
||||
if (!d_unhashed(dentry)) {
|
||||
__d_drop(dentry);
|
||||
rehash = true;
|
||||
}
|
||||
spin_unlock(&dentry->d_lock);
|
||||
|
||||
tlink = cifs_sb_tlink(cifs_sb);
|
||||
if (IS_ERR(tlink))
|
||||
return PTR_ERR(tlink);
|
||||
@ -1706,7 +1715,8 @@ psx_del_no_retry:
|
||||
if (inode)
|
||||
cifs_drop_nlink(inode);
|
||||
} else if (rc == -ENOENT) {
|
||||
d_drop(dentry);
|
||||
if (simple_positive(dentry))
|
||||
d_delete(dentry);
|
||||
} else if (rc == -EBUSY) {
|
||||
if (server->ops->rename_pending_delete) {
|
||||
rc = server->ops->rename_pending_delete(full_path,
|
||||
@ -1757,6 +1767,8 @@ unlink_out:
|
||||
kfree(attrs);
|
||||
free_xid(xid);
|
||||
cifs_put_tlink(tlink);
|
||||
if (rehash)
|
||||
d_rehash(dentry);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user