Commit 2780505e authored by SeongJae Park's avatar SeongJae Park Committed by Andrew Morton
Browse files

samples/damon/prcl: fix boot time enable crash

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: 2aca2546 ("samples/damon: introduce a skeleton of a smaple DAMON module for proactive reclamation")
Signed-off-by: default avatarSeongJae Park <sj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 0ed1165c
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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;
}