Whamcloud - gitweb
LU-18961 mdt: add safety checks in MDT_BOOL_RW_ATTR 09/59009/2
authorOleg Drokin <green@whamcloud.com>
Tue, 29 Apr 2025 04:05:27 +0000 (00:05 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 7 May 2025 21:14:29 +0000 (21:14 +0000)
MDT_BOOL_RW_ATTR macro creates a store and show methods
for a boolean sysfs entry, but in process they use result
of mdt_dev() call without checking, but internally
it uses container_of_safe that could return NULL or
ERR_PTR, so we need to check the return value.

While we can probably pass in the decoded PTR_ERR,
since NULL is also an option, simplier to just return
-ENOENT which makes sense on it's own.

Change-Id: Ibbc62cf74dc5d8b7e335fc42ff5149bd2ae174c6
Signed-off-by: Oleg Drokin <green@whamcloud.com>
Test-Parameters: trivial
Fixes: d71a24005b753 ("LU-17144 mdt: set dmv by setxattr")
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/59009
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
lustre/mdt/mdt_lproc.c

index ae223f8..c83f449 100644 (file)
@@ -811,6 +811,8 @@ static ssize_t name##_show(struct kobject *kobj, struct attribute *attr,\
        struct obd_device *obd = container_of(kobj, struct obd_device,  \
                                              obd_kset.kobj);           \
        struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);              \
+       if (IS_ERR_OR_NULL(mdt))                                        \
+               return -ENOENT;                                         \
        return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_##name);      \
 }                                                                      \
 static ssize_t name##_store(struct kobject *kobj, struct attribute *attr,\
@@ -821,6 +823,8 @@ static ssize_t name##_store(struct kobject *kobj, struct attribute *attr,\
        struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);              \
        bool val;                                                       \
        int rc;                                                         \
+       if (IS_ERR_OR_NULL(mdt))                                        \
+               return -ENOENT;                                         \
        rc = kstrtobool(buffer, &val);                                  \
        if (rc)                                                         \
                return rc;                                              \