If 'enable' parameter of the 'mtier' 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.
Fixes: 82a08bde3cf7 ("samples/damon: implement a DAMON module for memory tiering")
Cc: stable@vger.kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
---
samples/damon/mtier.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c
index 97892ade7f31..20c3102242ec 100644
--- a/samples/damon/mtier.c
+++ b/samples/damon/mtier.c
@@ -157,6 +157,8 @@ static void damon_sample_mtier_stop(void)
damon_destroy_ctx(ctxs[1]);
}
+static bool init_called;
+
static int damon_sample_mtier_enable_store(
const char *val, const struct kernel_param *kp)
{
@@ -170,6 +172,9 @@ static int damon_sample_mtier_enable_store(
if (enable == enabled)
return 0;
+ if (!init_called)
+ return 0;
+
if (enable) {
err = damon_sample_mtier_start();
if (err)
@@ -182,6 +187,14 @@ static int damon_sample_mtier_enable_store(
static int __init damon_sample_mtier_init(void)
{
+ int err = 0;
+
+ init_called = true;
+ if (enable) {
+ err = damon_sample_mtier_start();
+ if (err)
+ enable = false;
+ }
return 0;
}
--
2.39.5