lkml.org 
[lkml]   [2023]   [Jan]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 9/9] mm: kmemleak: fix undetected leaks for page aligned objects
Date
If kmalloc returns a page aligned object, then the object has 2
references: the pointer returned by kmalloc and page->s_mem of the first
page of the object. Account for this extra reference, so that kmemleak
can correctly detect leaks for page aligned objects.

Signed-off-by: George Prekas <george@enfabrica.net>
---
mm/slab.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mm/slab.h b/mm/slab.h
index 7cc432969945..76341c7c048e 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -734,6 +734,7 @@ static inline void slab_post_alloc_hook(struct kmem_cache *s,
unsigned int orig_size)
{
unsigned int zero_size = s->object_size;
+ int min_count;
size_t i;

flags &= gfp_allowed_mask;
@@ -761,7 +762,11 @@ static inline void slab_post_alloc_hook(struct kmem_cache *s,
p[i] = kasan_slab_alloc(s, p[i], flags, init);
if (p[i] && init && !kasan_has_integrated_init())
memset(p[i], 0, zero_size);
- kmemleak_alloc_recursive(p[i], s->object_size, 1,
+ min_count = 1;
+ /* If p[i] is page aligned, then a page->s_mem refers to it. */
+ if (((uintptr_t)p[i] & ~PAGE_MASK) == 0)
+ min_count++;
+ kmemleak_alloc_recursive(p[i], s->object_size, min_count,
s->flags, flags);
kmsan_slab_alloc(s, p[i], flags);
}
--
2.37.1
\
 
 \ /
  Last update: 2023-03-26 23:52    [W:0.130 / U:0.344 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site