From: Oleg Drokin Date: Tue, 29 Apr 2025 04:05:27 +0000 (-0400) Subject: LU-18961 mdt: add safety checks in MDT_BOOL_RW_ATTR X-Git-Tag: 2.16.55~25 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=117be08e587cac3021b7f4ddb2428eb1178b01cb;p=fs%2Flustre-release.git LU-18961 mdt: add safety checks in MDT_BOOL_RW_ATTR 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 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 Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Timothy Day --- diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index ae223f8..c83f449 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -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; \