Whamcloud - gitweb
LU-18846 osd-ldiskfs: fix error handling in iam_lookup_try 89/58489/2
authorLi Dongyang <dongyangli@ddn.com>
Fri, 21 Mar 2025 01:55:06 +0000 (12:55 +1100)
committerOleg Drokin <green@whamcloud.com>
Mon, 31 Mar 2025 05:57:55 +0000 (05:57 +0000)
We should check the return code from id_node_read(),
frame->bh could be -EIO or NULL, using it with iam_lock_bh()
could end up crashing.

Change-Id: If9899e2650c6949913217656f803db64c3a0c6fa
Test-Parameters: trivial
Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58489
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/osd-ldiskfs/osd_iam.c

index b9ad3e5..0219d46 100644 (file)
@@ -793,6 +793,9 @@ static int iam_lookup_try(struct iam_path *path)
             ++frame, ++i) {
                err = param->id_ops->id_node_read(c, (iam_ptr_t)ptr, NULL,
                                                  &frame->bh);
+               if (err != 0)
+                       break;
+
                do_corr(schedule());
 
                iam_lock_bh(frame->bh);
@@ -801,18 +804,19 @@ static int iam_lookup_try(struct iam_path *path)
                 * creation procedure may change it and iam_lookup_try() will
                 * see obsolete tree height. -bzzz
                 */
-               if (err != 0)
-                       break;
-
                if (LDISKFS_INVARIANT_ON) {
                        err = param->id_ops->id_node_check(path, frame);
-                       if (err != 0)
+                       if (err != 0) {
+                               iam_unlock_bh(frame->bh);
                                break;
+                       }
                }
 
                err = param->id_ops->id_node_load(path, frame);
-               if (err != 0)
+               if (err != 0) {
+                       iam_unlock_bh(frame->bh);
                        break;
+               }
 
                assert_inv(dx_node_check(path, frame));
                /*
@@ -823,8 +827,10 @@ static int iam_lookup_try(struct iam_path *path)
                 */
                if (i > 0) {
                        err = iam_check_path(path, frame - 1);
-                       if (err != 0)
+                       if (err != 0) {
+                               iam_unlock_bh(frame->bh);
                                break;
+                       }
                }
 
                frame->at = iam_find_position(path, frame);
@@ -834,8 +840,6 @@ static int iam_lookup_try(struct iam_path *path)
                iam_unlock_bh(frame->bh);
                do_corr(schedule());
        }
-       if (err != 0)
-               iam_unlock_bh(frame->bh);
        path->ip_frame = --frame;
        return err;
 }