Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] dyndbg: module's own classmaps bypass protection due to missing controlling_param init - [Medium] dyndbg: data race on map->controlling_param due to lockless initialization --
commit 5ffc9f5551765ac7c4413f320b8e9d1977dbe99a Author: Jim Cromie <[email protected]> dyndbg: resolve "protection" of class'd pr_debug This commit updates the protection mechanism for class'd pr_debug callsites against unclassed queries. It introduces a requirement that a sysfs parameter (controlling_param) must be present for a classmap to be protected. > diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c > index c023d07623f29..ac54a0499369c 100644 > --- a/lib/dynamic_debug.c > +++ b/lib/dynamic_debug.c [ ... ] > @@ -257,7 +300,28 @@ static bool ddebug_match_desc(const struct ddebug_query > *query, > dp->lineno > query->last_lineno) > return false; > > - return true; > + /* > + * above are all satisfied, so we can make final decisions: > + * 1- class FOO or implied class __DEFAULT__ > + * 2- site.is_classed or not > + */ > + if (query->class_string) { > + /* class FOO given, exact match required */ > + return (dp->class_id == selected_class); > + } > + /* query class __DEFAULT__ by omission. */ > + if (dp->class_id == _DPRINTK_CLASS_DFLT) { > + /* un-classed site */ > + return true; > + } > + /* site is class'd */ > + site_map = ddebug_find_map_by_class_id(di, dp->class_id); > + if (!site_map) { > + WARN_ONCE(1, "unknown class_id %d, check %s's CLASSMAP > definitions", dp->class_id, di->mod_name); > + return false; > + } > + /* module(-param) decides protection */ > + return !ddebug_class_wants_protection(site_map); [Severity: High] Does this code inadvertently bypass ABI protection for a module's own class'd pr_debug sites? Since the ddebug_apply_class_maps() block was removed in v10, it appears ddebug_add_module() only initializes user maps (by calling ddebug_apply_class_users() when dt->info.users.len > 0), and misses initializing the defining module's own native classmaps. Consequently, if a module defines a classmap and parameter but has no loaded dependent modules, map->controlling_param remains NULL. This causes ddebug_class_wants_protection() to default to false, allowing unclassed legacy queries to incorrectly modify these protected sites. > } > [ ... ] > +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 && dcp->map == map) { > + map->controlling_param = dcp; [Severity: Medium] Can this assignment introduce a data race? In ddebug_add_module(), the new debug table is published to the globally visible ddebug_tables list under ddebug_lock, but the lock is released before calling ddebug_apply_class_users(). Since ddebug_match_apply_kparam() is subsequently called without locks, concurrent threads processing ddebug_change() could hold ddebug_lock and read map->controlling_param while it is being updated here, leading to a data race. > v2pr_info(" kp:%s.%s =0x%x", mod_name, kp->name, *dcp->bits); > vpr_cm_info(map, " %s maps ", mod_name); > ddebug_sync_classbits(kp, mod_name); > } > } -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=32
