Re: [PATCH] mm/kmemleak: fix checksum computation for per-cpu objects
From: Catalin Marinas
Date: Fri Jul 03 2026 - 12:28:51 EST
On Fri, Jul 03, 2026 at 09:17:24AM -0700, Breno Leitao wrote:
> 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@xxxxxxxxx [0]
> Co-developed-by: Catalin Marinas <catalin.marinas@xxxxxxx>
Since you added co-developed-by, I think it needs this as well:
Signed-off-by: Catalin Marinas <catalin.marinas@xxxxxxx>
(otherwise I'm fine with suggested-by)
Thanks for the investigation and posting this.
--
Catalin