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 8/9] mm: kmemleak: erase page->freelist in slab_destroy
Date
slab_destroy frees the allocated memory pointed by page->freelist. It
should also erase the reference to it. Otherwise, when the memory is
reused for another object, kmemleak will find the stale pointer and
erroneously increase the reference count of the new object. That will
lead to undetected memory leaks.

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

diff --git a/mm/slab.c b/mm/slab.c
index aa5eb725ee9c..12acce274502 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1625,8 +1625,10 @@ static void slab_destroy(struct kmem_cache *cachep, struct slab *slab)
* From now on, we don't use freelist
* although actual page can be freed in rcu context
*/
- if (OFF_SLAB(cachep))
+ if (OFF_SLAB(cachep)) {
kfree(freelist);
+ kmemleak_erase(&slab->freelist);
+ }
}

/*
--
2.37.1
\
 
 \ /
  Last update: 2023-03-26 23:52    [W:0.059 / U:0.464 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site