All of lore.kernel.org
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SeongJae Park <sj@kernel.org>,
	damon@lists.linux.dev, kernel-team@meta.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	stable@vger.kernel.org
Subject: [PATCH 1/6] samples/damon/wsse: fix boot time enable handling
Date: Sun,  6 Jul 2025 12:32:02 -0700	[thread overview]
Message-ID: <20250706193207.39810-2-sj@kernel.org> (raw)
In-Reply-To: <20250706193207.39810-1-sj@kernel.org>

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.

Fixes: b757c6cfc696 ("samples/damon/wsse: start and stop DAMON as the user requests")
Cc: stable@vger.kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 samples/damon/wsse.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c
index e20238a249e7..15e2683fe5f3 100644
--- a/samples/damon/wsse.c
+++ b/samples/damon/wsse.c
@@ -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)
 {
@@ -103,6 +105,9 @@ static int damon_sample_wsse_enable_store(
 		return 0;
 
 	if (enable) {
+		if (!init_called)
+			return 0;
+
 		err = damon_sample_wsse_start();
 		if (err)
 			enable = false;
@@ -114,7 +119,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);
-- 
2.39.5

  reply	other threads:[~2025-07-06 19:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-06 19:32 [PATCH 0/6] mm/damon: fix misc bugs in DAMON modules SeongJae Park
2025-07-06 19:32 ` SeongJae Park [this message]
2025-07-06 19:32 ` [PATCH 2/6] samples/damon/prcl: fix boot time enable crash SeongJae Park
2025-07-06 19:32 ` [PATCH 3/6] samples/damon/mtier: support boot time enable setup SeongJae Park
2025-07-06 19:32 ` [PATCH 4/6] mm/damon/reclaim: reset enabled when DAMON start failed SeongJae Park
2025-07-06 19:32 ` [PATCH 5/6] mm/damon/lru_sort: " SeongJae Park
2025-07-06 19:32 ` [PATCH 6/6] mm/damon/reclaim: use parameter context correctly SeongJae Park

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=20250706193207.39810-2-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.