From: Chris Down <chris@chrisdown.name>
To: Vlastimil Babka <vbabka@kernel.org>, Harry Yoo <harry@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Kees Cook <kees@kernel.org>, Marco Elver <elver@google.com>,
GONG Ruiqi <gongruiqi@huaweicloud.com>,
Jan Kiszka <jan.kiszka@siemens.com>,
Kieran Bingham <kbingham@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
linux-mm@kvack.org, linux-hardening@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com
Subject: [PATCH 3/8] mm/slub: Support disabling freelist randomisation at boot
Date: Tue, 27 Oct 2026 15:35:49 +0800 [thread overview]
Message-ID: <58f32032f0f5f3828322780aca1847f1cd80cef0.1793086056.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1793086056.git.chris@chrisdown.name>
Add a slab_freelist_random= early parameter, enabled by default on
kernels built with CONFIG_SLAB_FREELIST_RANDOM=y.
Signed-off-by: Chris Down <chris@chrisdown.name>
---
Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
mm/Kconfig | 3 +++
mm/slub.c | 16 ++++++++++++++++
3 files changed, 26 insertions(+)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index ddf2f6fd60be..5c4d784e7786 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -7021,6 +7021,13 @@ Kernel parameters
without that option.
Default: on.
+ slab_freelist_random= [MM,EARLY]
+ Format: <bool>
+ Enable or disable slab freelist randomisation on
+ kernels built with CONFIG_SLAB_FREELIST_RANDOM=y.
+ Ignored without that option.
+ Default: on.
+
slab_max_order= [MM]
Determines the maximum allowed order for slabs.
A high setting may cause OOMs due to memory
diff --git a/mm/Kconfig b/mm/Kconfig
index 3ae97fec9946..56c422684b44 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -205,6 +205,9 @@ config SLAB_FREELIST_RANDOM
security feature reduces the predictability of the kernel slab
allocator against heap overflows.
+ The randomisation is enabled by default and can be disabled at
+ boot with "slab_freelist_random=0".
+
config SLAB_FREELIST_HARDENED
bool "Harden slab freelist metadata"
depends on !SLUB_TINY
diff --git a/mm/slub.c b/mm/slub.c
index de4937fcb293..7e9dadda3d10 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3424,12 +3424,23 @@ static inline struct slab *alloc_slab_page(gfp_t flags, int node,
}
#ifdef CONFIG_SLAB_FREELIST_RANDOM
+static bool slab_freelist_random __ro_after_init = true;
+
+static int __init setup_slab_freelist_random(char *str)
+{
+ return kstrtobool(str, &slab_freelist_random);
+}
+early_param("slab_freelist_random", setup_slab_freelist_random);
+
/* Pre-initialize the random sequence cache */
static int init_cache_random_seq(struct kmem_cache *s)
{
unsigned int count = oo_objects(s->oo);
int err;
+ if (!slab_freelist_random)
+ return 0;
+
/* Bailout if already initialised */
if (s->random_seq)
return 0;
@@ -3456,6 +3467,11 @@ static void __init init_freelist_randomization(void)
{
struct kmem_cache *s;
+ if (!slab_freelist_random) {
+ pr_info("SLUB: freelist randomisation disabled\n");
+ return;
+ }
+
mutex_lock(&slab_mutex);
list_for_each_entry(s, &slab_caches, list)
--
2.54.0
next prev parent reply other threads:[~2026-10-27 7:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 7:35 [PATCH 0/8] mm/slab: Support selecting slab hardening features " Chris Down
2026-10-27 7:35 ` [PATCH 1/8] mm/slub: Support disabling freelist hardening " Chris Down
2026-10-27 7:35 ` [PATCH 2/8] slub_kunit: Add a test for slab_freelist_hardened= Chris Down
2026-10-27 7:35 ` Chris Down [this message]
2026-10-27 7:35 ` [PATCH 4/8] slub_kunit: Add a test for slab_freelist_random= Chris Down
2026-10-27 7:35 ` [PATCH 5/8] mm/slab: Support disabling SLAB_BUCKETS at boot Chris Down
2026-10-27 7:36 ` [PATCH 6/8] slub_kunit: Add a test for the slab_buckets boot parameter Chris Down
2026-10-27 7:36 ` [PATCH 7/8] mm/slab: Support disabling KMALLOC_PARTITION_CACHES at boot Chris Down
2026-10-27 7:36 ` [PATCH 8/8] slub_kunit: Add a test for the kmalloc_partition boot parameter Chris Down
2026-10-27 8:10 ` [PATCH 0/8] mm/slab: Support selecting slab hardening features at boot Vlastimil Babka (SUSE)
2026-10-27 18:31 ` Harry Yoo
2026-10-28 15:23 ` Chris Down
2026-10-28 15:06 ` Harry Yoo
2026-10-28 15:27 ` Chris Down
2026-10-28 15:37 ` Harry Yoo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58f32032f0f5f3828322780aca1847f1cd80cef0.1793086056.git.chris@chrisdown.name \
--to=chris@chrisdown.name \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=corbet@lwn.net \
--cc=elver@google.com \
--cc=gongruiqi@huaweicloud.com \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=jan.kiszka@siemens.com \
--cc=kbingham@kernel.org \
--cc=kees@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®