ceph: don't leak snap_rwsem in handle_cap_grant
authorJeff Layton <jlayton@kernel.org>
Fri, 3 Jun 2022 20:39:57 +0000 (16:39 -0400)
committerIlya Dryomov <idryomov@gmail.com>
Tue, 2 Aug 2022 22:54:12 +0000 (00:54 +0200)
When handle_cap_grant is called on an IMPORT op, then the snap_rwsem is
held and the function is expected to release it before returning. It
currently fails to do that in all cases which could lead to a deadlock.

Fixes: 6f05b30ea063 ("ceph: reset i_requested_max_size if file write is not wanted")
Link: https://tracker.ceph.com/issues/55857
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Luís Henriques <lhenriques@suse.de>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/caps.c

index ac8fd5e7f5405f345fe12a7276819f3a513309fe..2b1f22322e8fa583624b801fd6e44337de21697b 100644 (file)
@@ -3578,24 +3578,23 @@ static void handle_cap_grant(struct inode *inode,
                        fill_inline = true;
        }
 
-       if (ci->i_auth_cap == cap &&
-           le32_to_cpu(grant->op) == CEPH_CAP_OP_IMPORT) {
-               if (newcaps & ~extra_info->issued)
-                       wake = true;
+       if (le32_to_cpu(grant->op) == CEPH_CAP_OP_IMPORT) {
+               if (ci->i_auth_cap == cap) {
+                       if (newcaps & ~extra_info->issued)
+                               wake = true;
+
+                       if (ci->i_requested_max_size > max_size ||
+                           !(le32_to_cpu(grant->wanted) & CEPH_CAP_ANY_FILE_WR)) {
+                               /* re-request max_size if necessary */
+                               ci->i_requested_max_size = 0;
+                               wake = true;
+                       }
 
-               if (ci->i_requested_max_size > max_size ||
-                   !(le32_to_cpu(grant->wanted) & CEPH_CAP_ANY_FILE_WR)) {
-                       /* re-request max_size if necessary */
-                       ci->i_requested_max_size = 0;
-                       wake = true;
+                       ceph_kick_flushing_inode_caps(session, ci);
                }
-
-               ceph_kick_flushing_inode_caps(session, ci);
-               spin_unlock(&ci->i_ceph_lock);
                up_read(&session->s_mdsc->snap_rwsem);
-       } else {
-               spin_unlock(&ci->i_ceph_lock);
        }
+       spin_unlock(&ci->i_ceph_lock);
 
        if (fill_inline)
                ceph_fill_inline_data(inode, NULL, extra_info->inline_data,