Whamcloud - gitweb
LU-13118 llite: add kobject to struct config_llog_instance 50/56850/5
authorJames Simmons <jsimmons@infradead.org>
Mon, 9 Dec 2024 17:02:47 +0000 (12:02 -0500)
committerOleg Drokin <green@whamcloud.com>
Wed, 22 Jan 2025 18:42:12 +0000 (18:42 +0000)
For the case of PARAM_LLITE in class_process_config() special
handling was implemented to locate the super block which
containes the struct kobject needed to send an uevent. This
special handling depends on naming containing an internal
kernel address which is also used to build the sysfs tree.
To fix this ASLR violation we need to move away from using
this internal address but it will break our special
handling. The solution is to add kobject of llite to the
struct config_llog_instance that can be used by the
class_process_config() so the special handling can go away.
Plus the change allows the removal of lsi_kobj.

Change-Id: Idf1e5a87e9d7b1b6448877d8bc21baf7f823dfeb
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56850
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_disk.h
lustre/include/obd_class.h
lustre/llite/llite_lib.c
lustre/llite/lproc_llite.c
lustre/mgc/mgc_request.c
lustre/mgs/mgs_llog.c
lustre/obdclass/class_obd.c
lustre/obdclass/obd_config.c
lustre/obdclass/obd_mount.c

index f2b9ac2..89fc3a4 100644 (file)
@@ -121,7 +121,6 @@ struct lustre_sb_info {
        struct ll_sb_info        *lsi_llsbi;   /* add'l client sbi info */
        struct dt_device         *lsi_dt_dev;  /* dt device to access disk fs*/
        struct kref               lsi_mounts;  /* references to the srv_mnt */
-       struct kobject           *lsi_kobj;
        char                      lsi_svname[MTI_NAME_MAXLEN];
        /* lsi_osd_obdname format = 'lsi->ls_svname'-osd */
        char                      lsi_osd_obdname[MTI_NAME_MAXLEN + 4];
index b2b21f8..1b2509a 100644 (file)
@@ -194,7 +194,7 @@ char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
                                     const char *new_name);
 void print_lustre_cfg(struct lustre_cfg *lcfg);
-int class_process_config(struct lustre_cfg *lcfg);
+int class_process_config(struct lustre_cfg *lcfg, struct kobject *kobj);
 ssize_t class_set_global(const char *param);
 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
                            struct kobject *kobj);
@@ -232,6 +232,7 @@ int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
 /* Passed as data param to class_config_parse_llog */
 struct config_llog_instance {
        unsigned long            cfg_instance;
+       struct kobject          *cfg_kobj;
        struct super_block      *cfg_sb;
        struct obd_uuid          cfg_uuid;
        llog_cb_t                cfg_callback;
index db159cb..0def180 100644 (file)
@@ -1468,6 +1468,7 @@ int ll_fill_super(struct super_block *sb)
         * joker tries to mount the same fs at two mount points.
         */
        cfg->cfg_instance = cfg_instance;
+       cfg->cfg_kobj = &sbi->ll_kset.kobj;
        cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
        cfg->cfg_callback = class_config_llog_handler;
        cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
index de36407..e357a3f 100644 (file)
@@ -2608,7 +2608,6 @@ static const char *const ra_stat_string[] = {
 
 int ll_debugfs_register_super(struct super_block *sb, const char *name)
 {
-       struct lustre_sb_info *lsi = s2lsi(sb);
        struct ll_sb_info *sbi = ll_s2sbi(sb);
        int err, id;
 
@@ -2627,8 +2626,6 @@ int ll_debugfs_register_super(struct super_block *sb, const char *name)
        if (err)
                RETURN(err);
 
-       lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
-
        if (IS_ERR_OR_NULL(llite_root))
                RETURN(0);
 
@@ -2695,7 +2692,6 @@ out_debugfs:
 
 void ll_debugfs_unregister_super(struct super_block *sb)
 {
-       struct lustre_sb_info *lsi = s2lsi(sb);
        struct ll_sb_info *sbi = ll_s2sbi(sb);
 
        debugfs_remove_recursive(sbi->ll_debugfs_entry);
@@ -2708,8 +2704,6 @@ void ll_debugfs_unregister_super(struct super_block *sb)
                sysfs_remove_link(&sbi->ll_kset.kobj,
                                  sbi->ll_md_obd->obd_type->typ_name);
 
-       kobject_put(lsi->lsi_kobj);
-
        kset_unregister(&sbi->ll_kset);
        wait_for_completion(&sbi->ll_kobj_unregister);
 
index e3f0182..cdf25c0 100644 (file)
@@ -1445,7 +1445,7 @@ fail:;
                CDEBUG(D_INFO, "ir apply logs %lld/%lld for %s -> %s\n",
                       prev_version, max_version, obdname, params);
 
-               rc = class_process_config(lcfg);
+               rc = class_process_config(lcfg, &obd->obd_kset.kobj);
                OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
                                              lcfg->lcfg_buflens));
                if (rc)
index 0909d56..00db6d2 100644 (file)
@@ -3818,11 +3818,11 @@ static int mgs_write_log_sys(const struct lu_env *env,
                switch (cmd) {
                case LCFG_SET_TIMEOUT:
                        if (!obd_timeout_set || lcfg->lcfg_num > obd_timeout)
-                               class_process_config(lcfg);
+                               class_process_config(lcfg, &lustre_kset->kobj);
                        break;
                case LCFG_SET_LDLM_TIMEOUT:
                        if (!ldlm_timeout_set || lcfg->lcfg_num > ldlm_timeout)
-                               class_process_config(lcfg);
+                               class_process_config(lcfg, &lustre_kset->kobj);
                        break;
                default:
                        break;
index 33c5cf0..fe24857 100644 (file)
@@ -343,7 +343,7 @@ int class_handle_ioctl(unsigned int cmd, void __user *uarg)
                if (!rc)
                        rc = lustre_cfg_sanity_check(lcfg, data->ioc_plen1);
                if (!rc)
-                       rc = class_process_config(lcfg);
+                       rc = class_process_config(lcfg, NULL);
 
                OBD_FREE(lcfg, data->ioc_plen1);
                GOTO(out, rc);
index d601d5e..ee4612d 100644 (file)
@@ -1373,7 +1373,7 @@ EXPORT_SYMBOL(lustre_register_quota_process_config);
  * These may come from direct calls (e.g. class_manual_cleanup)
  * or processing the config llog, or ioctl from lctl.
  */
-int class_process_config(struct lustre_cfg *lcfg)
+int class_process_config(struct lustre_cfg *lcfg, struct kobject *kobj)
 {
        struct obd_device *obd;
        struct lnet_nid nid;
@@ -1477,27 +1477,10 @@ int class_process_config(struct lustre_cfg *lcfg)
                /* llite has no OBD */
                if (class_match_param(lustre_cfg_string(lcfg, 1),
                                      PARAM_LLITE, NULL) == 0) {
-                       struct lustre_sb_info *lsi;
-                       unsigned long addr;
                        ssize_t count;
 
-                       /*
-                        * The instance name contains the sb:
-                        * lustre-client-aacfe000
-                        */
-                       tmp = strrchr(lustre_cfg_string(lcfg, 0), '-');
-                       if (!tmp || !*(++tmp))
-                               GOTO(out, err = -EINVAL);
-
-                       if (sscanf(tmp, "%lx", &addr) != 1)
-                               GOTO(out, err = -EINVAL);
-
-                       lsi = s2lsi((struct super_block *)addr);
-                       /* This better be a real Lustre superblock! */
-                       LASSERT(lsi->lsi_lmd->lmd_magic == LMD_MAGIC);
-
-                       count = class_modify_config(lcfg, PARAM_LLITE,
-                                                   lsi->lsi_kobj);
+                       LASSERT(kobj);
+                       count = class_modify_config(lcfg, PARAM_LLITE, kobj);
                        err = count < 0 ? count : 0;
                        GOTO(out, err);
                } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
@@ -1992,7 +1975,7 @@ int class_config_llog_handler(const struct lu_env *env,
 
                lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
 
-               rc = class_process_config(lcfg_new);
+               rc = class_process_config(lcfg_new, cfg->cfg_kobj);
                OBD_FREE(lcfg_new, lustre_cfg_len(lcfg_new->lcfg_bufcount,
                                                  lcfg_new->lcfg_buflens));
 out_inst:
@@ -2341,7 +2324,7 @@ int class_manual_cleanup(struct obd_device *obd)
                RETURN(-ENOMEM);
        lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
 
-       rc = class_process_config(lcfg);
+       rc = class_process_config(lcfg, NULL);
        if (rc) {
                CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
                GOTO(out, rc);
@@ -2349,7 +2332,7 @@ int class_manual_cleanup(struct obd_device *obd)
 
        /* the lcfg is almost the same for both ops */
        lcfg->lcfg_command = LCFG_DETACH;
-       rc = class_process_config(lcfg);
+       rc = class_process_config(lcfg, NULL);
        if (rc)
                CERROR("detach failed %d: %s\n", rc, obd->obd_name);
 out:
index 884b020..abde573 100644 (file)
@@ -153,7 +153,7 @@ static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
                return -ENOMEM;
        lustre_cfg_init(lcfg, cmd, &bufs);
        lcfg->lcfg_nid = nid;
-       rc = class_process_config(lcfg);
+       rc = class_process_config(lcfg, NULL);
        OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
        return rc;
 }