mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Weilin Tong <tongweilin@linux.alibaba.com>,
	Breno Leitao <leitao@debian.org>,
	David Hildenbrand <david@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 0/3] mm: kmemleak: fix the disable-time cleanup races
Date: Thu,  3 Dec 2026 15:25:11 +0000	[thread overview]
Message-ID: <20261203152515.2270778-1-catalin.marinas@arm.com> (raw)

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(-)


             reply	other threads:[~2026-12-03 15:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 15:25 Catalin Marinas [this message]
2026-12-03 15:25 ` [PATCH 1/3] mm: kmemleak: take kmemleak_lock in the disable-time object cleanup Catalin Marinas
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 15:25 ` [PATCH 3/3] mm: kmemleak: annotate the lockless accesses to the enable flags Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203152515.2270778-1-catalin.marinas@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=tongweilin@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®