From 46924e15edc7810a5cf82a782851c48dca4b7148 Mon Sep 17 00:00:00 2001 From: Li Dongyang Date: Fri, 21 Mar 2025 12:55:06 +1100 Subject: [PATCH] LU-18846 osd-ldiskfs: fix error handling in iam_lookup_try 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 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58489 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- lustre/osd-ldiskfs/osd_iam.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_iam.c b/lustre/osd-ldiskfs/osd_iam.c index b9ad3e5..0219d46 100644 --- a/lustre/osd-ldiskfs/osd_iam.c +++ b/lustre/osd-ldiskfs/osd_iam.c @@ -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; } -- 1.8.3.1