Re: [PATCH v3 28/54] dyndbg: restore classmap protection when theres a controlling_param
From: Sean Paul
Date: Fri Jun 20 2025 - 10:42:13 EST
On Thu, Apr 3, 2025 at 9:48 AM Jim Cromie <jim.cromie@xxxxxxxxx> wrote:
>
\snip
>
> -static void ddebug_match_apply_kparam(const struct kernel_param *kp,
> - const struct _ddebug_class_map *map,
> - const char *mod_name)
> +static struct _ddebug_class_param *
> +ddebug_get_classmap_kparam(const struct kernel_param *kp,
> + const struct _ddebug_class_map *map)
> {
> struct _ddebug_class_param *dcp;
>
> if (kp->ops != ¶m_ops_dyndbg_classes)
> - return;
> + return false;
Return type is struct _ddebug_class_param *, should this be NULL?
>
> dcp = (struct _ddebug_class_param *)kp->arg;
>
> - if (map == dcp->map) {
> + return (map == dcp->map)
> + ? dcp : (struct _ddebug_class_param *)NULL;
> +}
> +
> +static void ddebug_match_apply_kparam(const struct kernel_param *kp,
> + struct _ddebug_class_map *map,
> + const char *mod_name)
> +{
> + struct _ddebug_class_param *dcp = ddebug_get_classmap_kparam(kp, map);
> +
> + if (dcp) {
> + map->controlling_param = dcp;
> v2pr_info(" kp:%s.%s =0x%lx", mod_name, kp->name, *dcp->bits);
> vpr_cm_info(map, " %s mapped to: ", mod_name);
> ddebug_sync_classbits(kp, mod_name);
> }
> }
>
> -static void ddebug_apply_params(const struct _ddebug_class_map *cm, const char *mod_name)
> +static void ddebug_apply_params(struct _ddebug_class_map *cm, const char *mod_name)
> {
> const struct kernel_param *kp;
> #if IS_ENABLED(CONFIG_MODULES)
> @@ -1266,6 +1288,13 @@ static void ddebug_apply_params(const struct _ddebug_class_map *cm, const char *
> }
> }
>
> +/*
> + * called from add_module, ie early. it can find controlling kparams,
> + * which can/does? enable protection of this classmap from class-less
> + * queries, on the grounds that the user created the kparam, means to
> + * use it, and expects it to reflect reality. We should oblige him,
> + * and protect those classmaps from classless "-p" changes.
> + */
> static void ddebug_apply_class_maps(const struct _ddebug_info *di)
> {
> struct _ddebug_class_map *cm;
> --
> 2.49.0
>