Re: [PATCH v7 24/29] dyndbg: pin class param storage to u32
[email protected] Tue, 21 Jul 2026 21:10:52 +0000
| Newsgroups | org.kernel.vger.linux-modules,org.freedesktop.lists.dri-devel |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Bitwise shift out-of-bounds on 32-bit architectures when evaluating `BIT(bi)` in `ddebug_apply_class_bitmap()`. -- --- Patch [24]: [PATCH v7 24/29] dyndbg: pin class param storage to u32 --- commit 87a65c25e24b4e05bdc18ddf16105e9237d922db Author: Jim Cromie <[email protected]> dyndbg: pin class param storage to u32 This commit changes the bits and lvl fields in struct ddebug_class_param to use u32 instead of unsigned long. This ensures consistent sizing across different architectures. > diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c > index 59e3c0eccbede..60b67face46e1 100644 > --- a/lib/dynamic_debug.c > +++ b/lib/dynamic_debug.c [ ... ] > @@ -643,24 +643,27 @@ static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp, > int bi, ct; > > if (*new_bits != old_bits) > - v2pr_info("apply bitmap: 0x%lx to: 0x%lx for %s\n", *new_bits, > + v2pr_info("apply bitmap: 0x%x to: 0x%x for %s\n", *new_bits, > old_bits, query_modname ?: "'*'"); > > for (bi = 0; bi < map->length; bi++) { > - if (test_bit(bi, new_bits) == test_bit(bi, &old_bits)) > + bool new_b = !!(*new_bits & BIT(bi)); > + bool old_b = !!(old_bits & BIT(bi)); [Severity: Medium] Can this result in an out-of-bounds bitwise shift on 32-bit architectures? The BIT(bi) macro expands to (1UL << bi). On 32-bit systems, 1UL is 32 bits wide. If a module defines a classmap with 32 or more classes (map->length >= 32), shifting by 32 or more triggers undefined behavior. On most 32-bit architectures, the CPU masks the shift count modulo 32, meaning BIT(32) evaluates to BIT(0). This causes the loop to incorrectly re-evaluate and alter class 0 instead of processing the intended class, leading to incorrect functional behavior when configuring dynamic debug. > + if (new_b == old_b) > continue; > > snprintf(query, QUERY_SIZE, "class %s %c%s", map->class_names[bi], -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=24