All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] mm: kmemleak: fix the disable-time cleanup races
@ 2026-12-03 15:25 Catalin Marinas
  2026-12-03 15:25 ` [PATCH 1/3] mm: kmemleak: take kmemleak_lock in the disable-time object cleanup Catalin Marinas
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Catalin Marinas @ 2026-12-03 15:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Weilin Tong, Breno Leitao, David Hildenbrand, linux-mm,
	linux-kernel

Hi Andrew,

Patch 1 here supersedes Weilin's "mm: kmemleak: serialize disable-time
cleanup" in mm-unstable, so I think we can drop that one. I reviewed it
but Sashiko found more problems in the area, so here's a more
comprehensive fix. If you'd rather keep it (it's harmless), I can rebase
on top. This series is based on v7.4-rc1.

When kmemleak is disabled at runtime, __kmemleak_do_cleanup() removes
the objects without kmemleak_lock. A "clear" written to debugfs can run
a second cleanup concurrently with cleanup_work's (reported by Weilin
[1]) and callbacks such as kmemleak_free() that passed their enabled
checks before the disable can still update the object tree and list
(reported by Sashiko [2]). Both corrupt the tree and list.

Patch 1 takes kmemleak_lock when removing each object in the cleanup,
covering both cases. Patch 2 skips the hex dump in the report once frees
are no longer tracked since the reported objects may have been freed.
Patch 3 annotates the lockless accesses to the enable flags for
completeness. I couldn't get KCSAN to trigger a warning.

Tested on arm64 under Qemu with KASAN. On v7.4-rc1, writing "off" and
then "clear" crashes reliably and patch 1 fixes it. The concurrent
callback race needed some delays inserted to trigger a KASAN
use-after-free in rb_erase() (also fixed by patch 1).

LLM help (Claude): race analysis, testing, code and commit log
checks/suggestions, identifying the hex dump problem fixed by patch 2.

[1] https://lore.kernel.org/r/149d93f2cfe20d355f4d9882ce2bf99030217772.1793871596.git.tongweilin@linux.alibaba.com
[2] https://sashiko.dev/#/bug/linux-d5496447-37ff-43f3-81ed-e1a5616df463

Catalin Marinas (3):
  mm: kmemleak: take kmemleak_lock in the disable-time object cleanup
  mm: kmemleak: do not hex dump objects once free tracking has stopped
  mm: kmemleak: annotate the lockless accesses to the enable flags

 mm/kmemleak.c | 73 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 45 insertions(+), 28 deletions(-)



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-12-05 17:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 15:25 [PATCH 0/3] mm: kmemleak: fix the disable-time cleanup races Catalin Marinas
2026-12-03 15:25 ` [PATCH 1/3] mm: kmemleak: take kmemleak_lock in the disable-time object cleanup Catalin Marinas
2026-12-03 18:40   ` + mm-kmemleak-take-kmemleak_lock-in-the-disable-time-object-cleanup.patch added to mm-new branch Andrew Morton
2026-12-04 15:25   ` [PATCH 1/3] mm: kmemleak: take kmemleak_lock in the disable-time object cleanup sashiko-bot
2026-12-05 10:37     ` Catalin Marinas
2026-12-05 17:35       ` Andrew Morton
2026-12-03 15:25 ` [PATCH 2/3] mm: kmemleak: do not hex dump objects once free tracking has stopped Catalin Marinas
2026-12-03 18:40   ` + mm-kmemleak-do-not-hex-dump-objects-once-free-tracking-has-stopped.patch added to mm-new branch Andrew Morton
2026-12-03 15:25 ` [PATCH 3/3] mm: kmemleak: annotate the lockless accesses to the enable flags Catalin Marinas
2026-12-03 18:40   ` + mm-kmemleak-annotate-the-lockless-accesses-to-the-enable-flags.patch added to mm-new branch Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.