]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
samples/damon/prcl: fix boot time enable crash
authorSeongJae Park <sj@kernel.org>
Sun, 21 Sep 2025 14:11:17 +0000 (10:11 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Sep 2025 09:16:53 +0000 (11:16 +0200)
[ Upstream commit 2780505ec2b42c07853b34640bc63279ac2bb53b ]

If 'enable' parameter of the 'prcl' DAMON sample module is set at boot
time via the kernel command line, memory allocation is tried before the
slab is initialized.  As a result kernel NULL pointer dereference BUG can
happen.  Fix it by checking the initialization status.

Link: https://lkml.kernel.org/r/20250706193207.39810-3-sj@kernel.org
Fixes: 2aca254620a8 ("samples/damon: introduce a skeleton of a smaple DAMON module for proactive reclamation")
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: c62cff40481c ("samples/damon/mtier: avoid starting DAMON before initialization")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
samples/damon/prcl.c

index 5597e6a08ab2269751719596b25056b23be6321c..a9d7629d70f0ad850faa28d54d1cdb40556ac8ef 100644 (file)
@@ -109,6 +109,8 @@ static void damon_sample_prcl_stop(void)
                put_pid(target_pidp);
 }
 
+static bool init_called;
+
 static int damon_sample_prcl_enable_store(
                const char *val, const struct kernel_param *kp)
 {
@@ -134,6 +136,14 @@ static int damon_sample_prcl_enable_store(
 
 static int __init damon_sample_prcl_init(void)
 {
+       int err = 0;
+
+       init_called = true;
+       if (enable) {
+               err = damon_sample_prcl_start();
+               if (err)
+                       enable = false;
+       }
        return 0;
 }