]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
samples/damon/wsse: fix boot time enable handling
authorSeongJae Park <sj@kernel.org>
Sun, 6 Jul 2025 19:32:02 +0000 (12:32 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 13 Jul 2025 23:38:33 +0000 (16:38 -0700)
Patch series "mm/damon: fix misc bugs in DAMON modules".

From manual code review, I found below bugs in DAMON modules.

DAMON sample modules crash if those are enabled at boot time, via kernel
command line.  A similar issue was found and fixed on DAMON non-sample
modules in the past, but we didn't check that for sample modules.

DAMON non-sample modules are not setting 'enabled' parameters accordingly
when real enabling is failed.  Honggyu found and fixed[1] this type of
bugs in DAMON sample modules, and my inspection was motivated by the great
work.  Kudos to Honggyu.

Finally, DAMON_RECLIAM is mistakenly losing scheme internal status due to
misuse of damon_commit_ctx().  DAMON_LRU_SORT has a similar misuse, but
fortunately it is not causing real status loss.

Fix the bugs.  Since these are similar patterns of bugs that were found in
the past, it would be better to add tests or refactor the code, in future.

This patch (of 6):

If 'enable' parameter of the 'wsse' 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-1-sj@kernel.org
Link: https://lkml.kernel.org/r/20250706193207.39810-2-sj@kernel.org
Link: https://lore.kernel.org/20250702000205.1921-1-honggyu.kim@sk.com
Fixes: b757c6cfc696 ("samples/damon/wsse: start and stop DAMON as the user requests")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
samples/damon/wsse.c

index e20238a249e7b5bf2b50de4f8b2ca21d28da57e9..e941958b103249f1dde0384baa649b3a7834bccb 100644 (file)
@@ -89,6 +89,8 @@ static void damon_sample_wsse_stop(void)
                put_pid(target_pidp);
 }
 
+static bool init_called;
+
 static int damon_sample_wsse_enable_store(
                const char *val, const struct kernel_param *kp)
 {
@@ -114,7 +116,15 @@ static int damon_sample_wsse_enable_store(
 
 static int __init damon_sample_wsse_init(void)
 {
-       return 0;
+       int err = 0;
+
+       init_called = true;
+       if (enable) {
+               err = damon_sample_wsse_start();
+               if (err)
+                       enable = false;
+       }
+       return err;
 }
 
 module_init(damon_sample_wsse_init);