All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/slab: Perform init_on_free earlier
@ 2020-12-10 18:37 Alexander Popov
  2020-12-10 23:48   ` David Rientjes
  2020-12-11  1:17   ` Joonsoo Kim
  0 siblings, 2 replies; 5+ messages in thread
From: Alexander Popov @ 2020-12-10 18:37 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, linux-mm, linux-kernel, Alexander Potapenko,
	Dmitry Vyukov, kasan-dev, Alexander Popov
  Cc: notify

Currently in CONFIG_SLAB init_on_free happens too late, and heap
objects go to the heap quarantine not being erased.

Lets move init_on_free clearing before calling kasan_slab_free().
In that case heap quarantine will store erased objects, similarly
to CONFIG_SLUB=y behavior.

Signed-off-by: Alexander Popov <alex.popov@linux.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
---
 mm/slab.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index b1113561b98b..344a101e37e0 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3416,6 +3416,9 @@ static void cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac)
 static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp,
 					 unsigned long caller)
 {
+	if (unlikely(slab_want_init_on_free(cachep)))
+		memset(objp, 0, cachep->object_size);
+
 	/* Put the object into the quarantine, don't touch it for now. */
 	if (kasan_slab_free(cachep, objp, _RET_IP_))
 		return;
@@ -3434,8 +3437,6 @@ void ___cache_free(struct kmem_cache *cachep, void *objp,
 	struct array_cache *ac = cpu_cache_get(cachep);
 
 	check_irq_off();
-	if (unlikely(slab_want_init_on_free(cachep)))
-		memset(objp, 0, cachep->object_size);
 	kmemleak_free_recursive(objp, cachep->flags);
 	objp = cache_free_debugcheck(cachep, objp, caller);
 	memcg_slab_free_hook(cachep, &objp, 1);
-- 
2.26.2


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

* Re: [PATCH] mm/slab: Perform init_on_free earlier
  2020-12-10 18:37 [PATCH] mm/slab: Perform init_on_free earlier Alexander Popov
@ 2020-12-10 23:48   ` David Rientjes
  2020-12-11  1:17   ` Joonsoo Kim
  1 sibling, 0 replies; 5+ messages in thread
From: David Rientjes @ 2020-12-10 23:48 UTC (permalink / raw)
  To: Alexander Popov
  Cc: Christoph Lameter, Pekka Enberg, Joonsoo Kim, Andrew Morton,
	linux-mm, linux-kernel, Alexander Potapenko, Dmitry Vyukov,
	kasan-dev, notify

On Thu, 10 Dec 2020, Alexander Popov wrote:

> Currently in CONFIG_SLAB init_on_free happens too late, and heap
> objects go to the heap quarantine not being erased.
> 
> Lets move init_on_free clearing before calling kasan_slab_free().
> In that case heap quarantine will store erased objects, similarly
> to CONFIG_SLUB=y behavior.
> 
> Signed-off-by: Alexander Popov <alex.popov@linux.com>
> Reviewed-by: Alexander Potapenko <glider@google.com>

Acked-by: David Rientjes <rientjes@google.com>

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

* Re: [PATCH] mm/slab: Perform init_on_free earlier
@ 2020-12-10 23:48   ` David Rientjes
  0 siblings, 0 replies; 5+ messages in thread
From: David Rientjes @ 2020-12-10 23:48 UTC (permalink / raw)
  To: Alexander Popov
  Cc: Christoph Lameter, Pekka Enberg, Joonsoo Kim, Andrew Morton,
	linux-mm, linux-kernel, Alexander Potapenko, Dmitry Vyukov,
	kasan-dev, notify

On Thu, 10 Dec 2020, Alexander Popov wrote:

> Currently in CONFIG_SLAB init_on_free happens too late, and heap
> objects go to the heap quarantine not being erased.
> 
> Lets move init_on_free clearing before calling kasan_slab_free().
> In that case heap quarantine will store erased objects, similarly
> to CONFIG_SLUB=y behavior.
> 
> Signed-off-by: Alexander Popov <alex.popov@linux.com>
> Reviewed-by: Alexander Potapenko <glider@google.com>

Acked-by: David Rientjes <rientjes@google.com>


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

* Re: [PATCH] mm/slab: Perform init_on_free earlier
  2020-12-10 18:37 [PATCH] mm/slab: Perform init_on_free earlier Alexander Popov
@ 2020-12-11  1:17   ` Joonsoo Kim
  2020-12-11  1:17   ` Joonsoo Kim
  1 sibling, 0 replies; 5+ messages in thread
From: Joonsoo Kim @ 2020-12-11  1:17 UTC (permalink / raw)
  To: Alexander Popov
  Cc: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Linux Memory Management List, LKML,
	Alexander Potapenko, Dmitry Vyukov, kasan-dev, notify

2020년 12월 11일 (금) 오전 3:37, Alexander Popov <alex.popov@linux.com>님이 작성:
>
> Currently in CONFIG_SLAB init_on_free happens too late, and heap
> objects go to the heap quarantine not being erased.
>
> Lets move init_on_free clearing before calling kasan_slab_free().
> In that case heap quarantine will store erased objects, similarly
> to CONFIG_SLUB=y behavior.
>
> Signed-off-by: Alexander Popov <alex.popov@linux.com>
> Reviewed-by: Alexander Potapenko <glider@google.com>

Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>

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

* Re: [PATCH] mm/slab: Perform init_on_free earlier
@ 2020-12-11  1:17   ` Joonsoo Kim
  0 siblings, 0 replies; 5+ messages in thread
From: Joonsoo Kim @ 2020-12-11  1:17 UTC (permalink / raw)
  To: Alexander Popov
  Cc: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Linux Memory Management List, LKML,
	Alexander Potapenko, Dmitry Vyukov, kasan-dev, notify

2020년 12월 11일 (금) 오전 3:37, Alexander Popov <alex.popov@linux.com>님이 작성:
>
> Currently in CONFIG_SLAB init_on_free happens too late, and heap
> objects go to the heap quarantine not being erased.
>
> Lets move init_on_free clearing before calling kasan_slab_free().
> In that case heap quarantine will store erased objects, similarly
> to CONFIG_SLUB=y behavior.
>
> Signed-off-by: Alexander Popov <alex.popov@linux.com>
> Reviewed-by: Alexander Potapenko <glider@google.com>

Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>


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

end of thread, other threads:[~2020-12-11  1:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 18:37 [PATCH] mm/slab: Perform init_on_free earlier Alexander Popov
2020-12-10 23:48 ` David Rientjes
2020-12-10 23:48   ` David Rientjes
2020-12-11  1:17 ` Joonsoo Kim
2020-12-11  1:17   ` Joonsoo Kim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.