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 2/3] mm: kmemleak: do not hex dump objects once free tracking has stopped
Date: Thu, 3 Dec 2026 15:25:13 +0000 [thread overview]
Message-ID: <20261203152515.2270778-3-catalin.marinas@arm.com> (raw)
In-Reply-To: <20261203152515.2270778-1-catalin.marinas@arm.com>
If kmemleak is disabled after reporting leaks, the metadata is kept so
that the report can still be read, but kmemleak_free_enabled is cleared.
kmemleak_free() then no longer clears OBJECT_ALLOCATED, which the report
checks under object->lock before hex dumping an object. Reading the
report can therefore hex dump memory that has been freed, or unmapped in
the case of vmalloc and percpu areas.
Skip the hex dump once kmemleak_free_enabled is cleared. The callers
hold scan_mutex, under which kmemleak_do_cleanup() clears the flag.
Fixes: 74341703edca ("kmemleak: Report previously found leaks even after an error")
Cc: <stable@vger.kernel.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
mm/kmemleak.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 9c2d01fd4113..0fd3ea174367 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -311,6 +311,13 @@ static void hex_dump_object(struct seq_file *seq,
if (WARN_ON_ONCE(object->flags & OBJECT_PHYS))
return;
+ /*
+ * Frees are no longer tracked, so the object may have been freed or
+ * unmapped. The callers hold scan_mutex, under which the flag is cleared.
+ */
+ if (!kmemleak_free_enabled)
+ return;
+
if (object->flags & OBJECT_PERCPU)
ptr = (const u8 *)this_cpu_ptr((void __percpu *)object->pointer);
next prev parent 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 [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 15:25 ` Catalin Marinas [this message]
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-3-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®