Whamcloud - gitweb
LU-17848 osd: fix deref in ldiskfs osd_health_check() 89/58989/3
authorTimothy Day <timday@amazon.com>
Sun, 27 Apr 2025 16:55:24 +0000 (12:55 -0400)
committerOleg Drokin <green@whamcloud.com>
Sat, 7 Jun 2025 23:01:52 +0000 (23:01 +0000)
The implementations of osd_health_check() in ldiskfs
incorrectly check for a NULL mount after already
dereferencing it. Add a check for a NULL mount in
osd_sb() and check for a NULL sb in osd_health_check().

CoverityID: 397885 ("Dereference before null check")

Test-Parameters: trivial
Signed-off-by: Timothy Day <timday@amazon.com>
Change-Id: Id1ce015eb420fe067be375bf0019f305e3e2718c
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58989
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Lijing Chen <lijinc@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-ldiskfs/osd_internal.h

index a621e80..ebf0f10 100644 (file)
@@ -8853,7 +8853,7 @@ static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
        struct osd_device *osd = osd_dev(obd->obd_lu_dev);
        struct super_block *sb = osd_sb(osd);
 
-       return (osd->od_mnt == NULL || sb->s_flags & SB_RDONLY);
+       return (!sb || sb->s_flags & SB_RDONLY);
 }
 
 static int osd_get_info(const struct lu_env *env, struct obd_export *exp,
index 000c8c6..70d959b 100644 (file)
@@ -1107,6 +1107,9 @@ static inline struct osd_device *osd_obj2dev(const struct osd_object *o)
 
 static inline struct super_block *osd_sb(const struct osd_device *dev)
 {
+       if (!dev->od_mnt)
+               return NULL;
+
        return dev->od_mnt->mnt_sb;
 }