Skip to contentSkip to conversation

fs/ceph:fix double unlock in handle_cap_export()

PATCH Superseded Wu Bo 2 participants 3 messages Apr 28, 2020 Ceph client

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wu Bo

author
#0 lore raw

PATCH 1/1 fs/ceph:fix double unlock in handle_cap_export()

If the ceph_mdsc_open_export_target_session() return fails, should add a lock to avoid twice unlocking.
Because the lock will be released at the retry or out_unlock tag.

---
 fs/ceph/caps.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
fs/ceph/caps.c +14 -12
index 185db76..b5a62a8 100644
@@ -3731,22 +3731,24 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
 
 	/* open target session */
 	tsession = ceph_mdsc_open_export_target_session(mdsc, target);
-	if (!IS_ERR(tsession)) {
-		if (mds > target) {
-			mutex_lock(&session->s_mutex);
-			mutex_lock_nested(&tsession->s_mutex,
-					  SINGLE_DEPTH_NESTING);
-		} else {
-			mutex_lock(&tsession->s_mutex);
-			mutex_lock_nested(&session->s_mutex,
-					  SINGLE_DEPTH_NESTING);
-		}
-		new_cap = ceph_get_cap(mdsc, NULL);
-	} else {
+	if (IS_ERR(tsession)) {
 		WARN_ON(1);
 		tsession = NULL;
 		target = -1;
+		mutex_lock(&session->s_mutex);
+		goto out_unlock;
+	}
+
+	if (mds > target) {
+		mutex_lock(&session->s_mutex);
+		mutex_lock_nested(&tsession->s_mutex,
+					SINGLE_DEPTH_NESTING);
+	} else {
+		mutex_lock(&tsession->s_mutex);
+		mutex_lock_nested(&session->s_mutex,
+					SINGLE_DEPTH_NESTING);
 	}
+	new_cap = ceph_get_cap(mdsc, NULL);
 	goto retry;
 
 out_unlock:
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 5 lines · Wu Bo

If the ceph_mdsc_open_export_target_session() return fails, should add a lock to avoid twice unlocking.
Because the lock will be released at the retry or out_unlock tag.

at retry label, i_ceph_lock get locked. I don't see how i_ceph_lock can get double unlock

Quoted 49 lines
---
 fs/ceph/caps.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
fs/ceph/caps.c +14 -13
index 185db76..b5a62a8 100644
@@ -3731,22 +3731,24 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
 
        /* open target session */
        tsession = ceph_mdsc_open_export_target_session(mdsc, target);
-       if (!IS_ERR(tsession)) {
-               if (mds > target) {
-                       mutex_lock(&session->s_mutex);
-                       mutex_lock_nested(&tsession->s_mutex,
-                                         SINGLE_DEPTH_NESTING);
-               } else {
-                       mutex_lock(&tsession->s_mutex);
-                       mutex_lock_nested(&session->s_mutex,
-                                         SINGLE_DEPTH_NESTING);
-               }
-               new_cap = ceph_get_cap(mdsc, NULL);
-       } else {
+       if (IS_ERR(tsession)) {
                WARN_ON(1);
                tsession = NULL;
                target = -1;
+               mutex_lock(&session->s_mutex);
+               goto out_unlock;
+       }
+
+       if (mds > target) {
+               mutex_lock(&session->s_mutex);
+               mutex_lock_nested(&tsession->s_mutex,
+                                       SINGLE_DEPTH_NESTING);
+       } else {
+               mutex_lock(&tsession->s_mutex);
+               mutex_lock_nested(&session->s_mutex,
+                                       SINGLE_DEPTH_NESTING);
        }
+       new_cap = ceph_get_cap(mdsc, NULL);
        goto retry;
 
 out_unlock:
--

1.8.3.1

author
#2 lore raw
Quoted 10 lines · Zheng
Quoted 5 lines · Wu Bo

If the ceph_mdsc_open_export_target_session() return fails, should add a lock to avoid twice unlocking.
Because the lock will be released at the retry or out_unlock tag.

at retry label, i_ceph_lock get locked. I don't see how i_ceph_lock can get double unlock
sorry, maybe I didn't describe it clearly enough, not i_ceph_lock, but

session->s_mutex.

Thanks.

Wu Bo

Quoted 52 lines
Quoted 47 lines
---
  fs/ceph/caps.c | 26 ++++++++++++++------------
  1 file changed, 14 insertions(+), 12 deletions(-)
fs/ceph/caps.c +14 -13
index 185db76..b5a62a8 100644
@@ -3731,22 +3731,24 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
 
         /* open target session */
         tsession = ceph_mdsc_open_export_target_session(mdsc, target);
-       if (!IS_ERR(tsession)) {
-               if (mds > target) {
-                       mutex_lock(&session->s_mutex);
-                       mutex_lock_nested(&tsession->s_mutex,
-                                         SINGLE_DEPTH_NESTING);
-               } else {
-                       mutex_lock(&tsession->s_mutex);
-                       mutex_lock_nested(&session->s_mutex,
-                                         SINGLE_DEPTH_NESTING);
-               }
-               new_cap = ceph_get_cap(mdsc, NULL);
-       } else {
+       if (IS_ERR(tsession)) {
                 WARN_ON(1);
                 tsession = NULL;
                 target = -1;
+               mutex_lock(&session->s_mutex);
+               goto out_unlock;
+       }
+
+       if (mds > target) {
+               mutex_lock(&session->s_mutex);
+               mutex_lock_nested(&tsession->s_mutex,
+                                       SINGLE_DEPTH_NESTING);
+       } else {
+               mutex_lock(&tsession->s_mutex);
+               mutex_lock_nested(&session->s_mutex,
+                                       SINGLE_DEPTH_NESTING);
         }
+       new_cap = ceph_get_cap(mdsc, NULL);
         goto retry;
 
  out_unlock:
--
Quoted 2 lines

1.8.3.1

.