]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
mm/kmemleak: fix checksum computation for per-cpu objects
authorBreno Leitao <leitao@debian.org>
Fri, 3 Jul 2026 16:17:24 +0000 (09:17 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 9 Jul 2026 22:48:55 +0000 (15:48 -0700)
commit79c37ae3733e93d9d8ea12ecb44f717e61439024
tree206bc6e88a87bc0a4189e4d53fcaead54946f614
parent954157679ec34661c2e87e7eb796104a797c32db
mm/kmemleak: fix checksum computation for per-cpu objects

The per-cpu object checksum folds each CPU's CRC together with XOR and
seeds every CRC with 0.  Both choices make update_checksum() miss content
changes:

  - XOR is self-cancelling, so equal contents on two CPUs cancel out and
    simultaneous identical changes leave the checksum unchanged.
  - crc32(0, ...) over all-zero content is 0, so a freshly allocated,
    zeroed per-cpu area checksums to 0, matching the initial value, and
    the object is never seen to change.

See discussions at [0].

When update_checksum() wrongly reports an actively modified object as
unchanged, kmemleak stops greying it for an extra scan and can report a
live per-cpu object as a leak.

Fold the per-cpu CRC as a single rolling checksum across all CPUs and
initialise the object checksum to ~0 so the first computed value always
registers as a change, even for content that hashes to 0.
reset_checksum() is seeded the same way.

Link: https://lore.kernel.org/all/akfYImSNDh3OjIfR@gmail.com
Link: https://lore.kernel.org/20260703-kmemleak_checksum-v1-1-5e0ab7d6966f@debian.org
Fixes: 6c99d4eb7c5e ("kmemleak: enable tracking for percpu pointers")
Signed-off-by: Breno Leitao <leitao@debian.org>
Co-developed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/kmemleak.c