Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: SJ Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Aveline Noir <jm5905938@gmail.com>,
	stable@vger.kernel.org, Dawei Li <set_pte_at@outlook.com>,
	Lian Wang <lianux.mm@gmail.com>, SJ Park <sj@kernel.org>,
	damon@lists.linux.dev, linux-mm@kvack.org,
	Enze Li <lienze@kylinos.cn>
Subject: [PATCH mm-hotfixes-unstable v2] mm/damon/sysfs: skip registration if DAMON core init fails
Date: Mon, 30 Nov 2026 07:07:28 -0800	[thread overview]
Message-ID: <20261130150729.88226-1-sj@kernel.org> (raw)

From: Aveline Noir <jm5905938@gmail.com>

DAMON sysfs registers its interface even if DAMON core initialization
fails.  If damon_init() fails to allocate damon_region_cache, starting a
kdamond with an initial region can pass a NULL cache to
kmem_cache_alloc() via damon_new_region().  As a result, NULL
dereference can happen.  The initialization failure is unlikely, but the
consequence is quite bad.

Check damon_initialized() before creating the DAMON sysfs directory and
return -ENOMEM if the core is unavailable.

Fixes: a18709442869 ("mm/damon: improve damon_new_region strategy")
Cc: <stable@vger.kernel.org> # 6.1.x
Cc: Lian Wang <lianux.mm@gmail.com>
Cc: Dawei Li <set_pte_at@outlook.com>
Signed-off-by: Aveline Noir <jm5905938@gmail.com>
Reviewed-by: SJ Park <sj@kernel.org>
Tested-by: Enze Li <lienze@kylinos.cn>
Reviewed-by: Enze Li <lienze@kylinos.cn>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20261123-damon-sysfs-init-guard-v1-1-a2a6ca65693a@gmail.com
- Update commit message.
- Collect R-b: from SJ.
- Collect T-b: and R-b: from Enze Li.
- Cc stable@.
- Rebase to the latest mm-new.

 mm/damon/sysfs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 70a4b64fb8ea..973213e4313a 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -3031,6 +3031,9 @@ static int __init damon_sysfs_init(void)
 	struct damon_sysfs_ui_dir *admin;
 	int err;
 
+	if (!damon_initialized())
+		return -ENOMEM;
+
 	damon_sysfs_root = kobject_create_and_add("damon", mm_kobj);
 	if (!damon_sysfs_root)
 		return -ENOMEM;

base-commit: d1d23727a7f0d50eef2075d78d7fa26200303217
-- 
2.47.3


                 reply	other threads:[~2026-11-30 15:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261130150729.88226-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=jm5905938@gmail.com \
    --cc=lianux.mm@gmail.com \
    --cc=lienze@kylinos.cn \
    --cc=linux-mm@kvack.org \
    --cc=set_pte_at@outlook.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox