linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] don't record leak information on allocations done between kmemleak_init and kmemleak_late_init
@ 2024-01-02 15:34 Chris von Recklinghausen
  2024-01-02 20:07 ` Catalin Marinas
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Chris von Recklinghausen @ 2024-01-02 15:34 UTC (permalink / raw)
  To: Catalin Marinas, linux-kernel; +Cc: crecklin

If an object is allocated after kmemleak_init is called but before
kmemleak_late_init is called, calls to kmemleak_not_leak or
kmemleak_ignore on the object don't prevent a scan from reporting the
object as a leak.

Avoid this situation by only registering objects in kmemleak_alloc when
kmemleak_initialized is set.

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
---
 mm/kmemleak.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 5501363d6b31..0c8a5f456874 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1117,7 +1117,8 @@ void __ref kmemleak_free_part(const void *ptr, size_t size)
 {
 	pr_debug("%s(0x%px)\n", __func__, ptr);
 
-	if (kmemleak_enabled && ptr && !IS_ERR(ptr))
+	if (kmemleak_enabled && kmemleak_late_initialized && ptr &&
+		!IS_ERR(ptr))
 		delete_object_part((unsigned long)ptr, size, false);
 }
 EXPORT_SYMBOL_GPL(kmemleak_free_part);
@@ -1135,7 +1136,8 @@ void __ref kmemleak_free_percpu(const void __percpu *ptr)
 
 	pr_debug("%s(0x%px)\n", __func__, ptr);
 
-	if (kmemleak_free_enabled && ptr && !IS_ERR(ptr))
+	if (kmemleak_free_enabled && kmemleak_late_initialized && ptr &&
+		!IS_ERR(ptr))
 		for_each_possible_cpu(cpu)
 			delete_object_full((unsigned long)per_cpu_ptr(ptr,
 								      cpu));
@@ -1189,7 +1191,8 @@ void __ref kmemleak_not_leak(const void *ptr)
 {
 	pr_debug("%s(0x%px)\n", __func__, ptr);
 
-	if (kmemleak_enabled && ptr && !IS_ERR(ptr))
+	if (kmemleak_enabled && kmamleak_late_initialized && ptr &&
+		!IS_ERR(ptr))
 		make_gray_object((unsigned long)ptr);
 }
 EXPORT_SYMBOL(kmemleak_not_leak);
@@ -1207,7 +1210,8 @@ void __ref kmemleak_ignore(const void *ptr)
 {
 	pr_debug("%s(0x%px)\n", __func__, ptr);
 
-	if (kmemleak_enabled && ptr && !IS_ERR(ptr))
+	if (kmemleak_enabled && kmamleak_late_initialized && ptr &&
+		!IS_ERR(ptr))
 		make_black_object((unsigned long)ptr, false);
 }
 EXPORT_SYMBOL(kmemleak_ignore);
-- 
2.43.0


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

end of thread, other threads:[~2024-01-03 12:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-02 15:34 [PATCH] don't record leak information on allocations done between kmemleak_init and kmemleak_late_init Chris von Recklinghausen
2024-01-02 20:07 ` Catalin Marinas
     [not found]   ` <5d979584-a168-4594-af19-93af6bc0ae5a@redhat.com>
2024-01-03 12:25     ` Catalin Marinas
2024-01-03  3:08 ` kernel test robot
2024-01-03 10:51 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).