Skip to content

Commit b493ad7

Browse files
lxbszidryomov
authored andcommitted
ceph: fix deadlock or deadcode of misusing dget()
The lock order is incorrect between denty and its parent, we should always make sure that the parent get the lock first. But since this deadcode is never used and the parent dir will always be set from the callers, let's just remove it. Link: https://lore.kernel.org/r/20231116081919.GZ1957730@ZenIV Reported-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Xiubo Li <xiubli@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent aaefabc commit b493ad7

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

fs/ceph/caps.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4887,13 +4887,15 @@ int ceph_encode_dentry_release(void **p, struct dentry *dentry,
48874887
struct inode *dir,
48884888
int mds, int drop, int unless)
48894889
{
4890-
struct dentry *parent = NULL;
48914890
struct ceph_mds_request_release *rel = *p;
48924891
struct ceph_dentry_info *di = ceph_dentry(dentry);
48934892
struct ceph_client *cl;
48944893
int force = 0;
48954894
int ret;
48964895

4896+
/* This shouldn't happen */
4897+
BUG_ON(!dir);
4898+
48974899
/*
48984900
* force an record for the directory caps if we have a dentry lease.
48994901
* this is racy (can't take i_ceph_lock and d_lock together), but it
@@ -4903,14 +4905,9 @@ int ceph_encode_dentry_release(void **p, struct dentry *dentry,
49034905
spin_lock(&dentry->d_lock);
49044906
if (di->lease_session && di->lease_session->s_mds == mds)
49054907
force = 1;
4906-
if (!dir) {
4907-
parent = dget(dentry->d_parent);
4908-
dir = d_inode(parent);
4909-
}
49104908
spin_unlock(&dentry->d_lock);
49114909

49124910
ret = ceph_encode_inode_release(p, dir, mds, drop, unless, force);
4913-
dput(parent);
49144911

49154912
cl = ceph_inode_to_client(dir);
49164913
spin_lock(&dentry->d_lock);

0 commit comments

Comments
 (0)