[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250321204105.1898507-5-kees@kernel.org>
Date: Fri, 21 Mar 2025 13:41:01 -0700
From: Kees Cook <kees@...nel.org>
To: Vlastimil Babka <vbabka@...e.cz>
Cc: Kees Cook <kees@...nel.org>,
Christoph Lameter <cl@...ux.com>,
Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
Roman Gushchin <roman.gushchin@...ux.dev>,
Hyeonggon Yoo <42.hyeyoo@...il.com>,
linux-mm@...ck.org,
Miguel Ojeda <ojeda@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Marco Elver <elver@...gle.com>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Przemek Kitszel <przemyslaw.kitszel@...el.com>,
linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: [PATCH 5/5] [DEBUG] slab: Report number of NULLings
Just to get a sense of what's happening, report the number of NULL
assignments that have been done. After booting an otherwise standard
Ubuntu image, this shows about 240,000 NULLifications have been performed.
Signed-off-by: Kees Cook <kees@...nel.org>
---
Cc: Christoph Lameter <cl@...ux.com>
Cc: Pekka Enberg <penberg@...nel.org>
Cc: David Rientjes <rientjes@...gle.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@....com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Vlastimil Babka <vbabka@...e.cz>
Cc: Roman Gushchin <roman.gushchin@...ux.dev>
Cc: Hyeonggon Yoo <42.hyeyoo@...il.com>
Cc: linux-mm@...ck.org
---
include/linux/slab.h | 3 +++
mm/slab_common.c | 4 ++++
2 files changed, 7 insertions(+)
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 2717ad238fa2..a4740c8b6ccb 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -469,6 +469,8 @@ void __kfree(const void *objp);
void __kfree_sensitive(const void *objp);
size_t __ksize(const void *objp);
+extern atomic_t count_nulled;
+
static inline void kfree_and_null(void **ptr)
{
__kfree(*ptr);
@@ -487,6 +489,7 @@ static inline void kfree_sensitive_and_null(void **ptr)
({ \
typeof(x) *__ptr = &(x); \
__how ## _and_null((void **)__ptr); \
+ atomic_inc(&count_nulled); \
})
#define __free_and_maybe_null(__how, x) \
__builtin_choose_expr(__is_lvalue(x), \
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 9a82952ec266..0412cbab81f9 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -42,6 +42,9 @@ LIST_HEAD(slab_caches);
DEFINE_MUTEX(slab_mutex);
struct kmem_cache *kmem_cache;
+atomic_t count_nulled = ATOMIC_INIT(0);
+EXPORT_SYMBOL(count_nulled);
+
/*
* Set of flags that will prevent slab merging
*/
@@ -1084,6 +1087,7 @@ static void print_slabinfo_header(struct seq_file *m)
* without _too_ many complaints.
*/
seq_puts(m, "slabinfo - version: 2.1\n");
+ seq_printf(m, "# nulled: %d\n", atomic_read(&count_nulled));
seq_puts(m, "# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>");
seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>");
seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
--
2.34.1
Powered by blists - more mailing lists