* + mm-damon-sysfs-schemes-hold-damon_sysfs_lock-in-target_metric_store.patch added to mm-unstable branch
@ 2026-10-25 16:54 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2026-10-25 16:54 UTC (permalink / raw)
To: mm-commits, stable, sj, akpm
The patch titled
Subject: mm/damon/sysfs-schemes: hold damon_sysfs_lock in target_metric_store()
has been added to the -mm mm-unstable branch. Its filename is
mm-damon-sysfs-schemes-hold-damon_sysfs_lock-in-target_metric_store.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-damon-sysfs-schemes-hold-damon_sysfs_lock-in-target_metric_store.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: SJ Park <sj@kernel.org>
Subject: mm/damon/sysfs-schemes: hold damon_sysfs_lock in target_metric_store()
Date: Sun, 25 Oct 2026 09:48:04 -0700
Patch series "mm/damon: fix three race bugs in sysfs and core", v1.
There are three race condition bugs in DAMON sysfs interface and the
core layer. User impacts are not critical but better to fix sooner than
later.
Patch 1 fixes a toctou bug in DAMON sysfs interface that can mess up
DAMOS auto-tuning. Patches 2 and 3 move static variables that can be
wrongly shared with multiple kdamonds and therefore make DAMON
monitoring results be a little more indeterministic.
Note for Andrew. These are not urgent but better to take the hotfix
track in my humble opinion.
This patch (of 3):
damon_sysfs_add_quota_score() reads damos_sysfs_quota_goal->metric
twice, once to set damos_quota_goal->metric to the value, and once again
to set the metric-dependent damos_quota_goal unions based on the value.
target_metrics_score() can update damos_sysfs_quota_goal->metric between
the two reads. This time-of-check to time-of-use (toctou) race can make
the union fields incorrectly set. The incorrect damos_quota_goal will
be passed to the core layer and make DAMOS incorrectly behave.
Users could reproduce the race by writing a new value to the
target_metric sysfs file while DAMON is starting, or online parameters
update is ongoing. The issue will only rarely happen in the real use
cases. It requires sysfs write permission. The race window is short.
Sane users wouldn't do such writes while DAMON enablement and/or online
parameters update is ongoing.
The user impact is not very critical. The race is not easy to
unintentionally trigger. No leak or crash happens. Nonetheless, DAMOS
could be unexpectedly more or less aggressive and does not achieve the
auto-tune goal. Because of the nature of races, investigating will be
difficult. Users can control the impact from unexpected aggressiveness
using additional quotas and resolve the issue in runtime by
re-installing the quota goal, though.
Avoid the race by protecting damos_sysfs_quota_goal->metric write in
target_metric_store() with damon_sysfs_lock. Because
damon_sysfs_add_quota_score() is called while holding the same lock, the
race is removed.
The issue was discovered as a part of a bug report [1] from Sashiko,
which is partially outdated. In more detail, the Sashiko report [1] was
mainly for an outdated bug [2]. But it was also mentioning the issue of
this patch as a similar class bug.
Link: https://lore.kernel.org/20261025164808.152048-1-sj@kernel.org
Link: https://lore.kernel.org/20261025164808.152048-2-sj@kernel.org
Link: https://sashiko.dev/#/bug/linux-7f814c9a-986f-4103-a55a-ef9537dcf62b [1]
Link: https://lore.kernel.org/20261021005234.94107-1-sj@kernel.org [2]
Fixes: 85fcf0ffc460 ("mm/damon/sysfs-schemes: connect damos_quota_goal nid with core layer")
Signed-off-by: SJ Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: <stable@vger.kernel.org> # 6.16.x
---
mm/damon/sysfs-schemes.c | 3 +++
1 file changed, 3 insertions(+)
--- a/mm/damon/sysfs-schemes.c~mm-damon-sysfs-schemes-hold-damon_sysfs_lock-in-target_metric_store
+++ a/mm/damon/sysfs-schemes.c
@@ -1310,7 +1310,10 @@ static ssize_t target_metric_store(struc
metric_name = &damos_sysfs_qgoal_metric_names[i];
if (sysfs_streq(buf, metric_name->name)) {
+ if (!mutex_trylock(&damon_sysfs_lock))
+ return -EBUSY;
goal->metric = metric_name->metric;
+ mutex_unlock(&damon_sysfs_lock);
return count;
}
}
_
Patches currently in -mm which might be from sj@kernel.org are
mm-damon-sysfs-schemes-hold-damon_sysfs_lock-in-target_metric_store.patch
mm-damon-core-move-static-variable-last_nr_regions-to-damon_ctx.patch
mm-damon-core-move-static-variable-rotation-to-damon_ctx.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-25 16:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-25 16:54 + mm-damon-sysfs-schemes-hold-damon_sysfs_lock-in-target_metric_store.patch added to mm-unstable branch Andrew Morton
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.