From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [PATCH 5/5] mm/damon/sysfs: read ops_id only once
Date: Tue, 14 Jul 2026 07:29:49 -0700 [thread overview]
Message-ID: <20260714142950.100711-1-sj@kernel.org> (raw)
In-Reply-To: <20260714142509.010D91F000E9@smtp.kernel.org>
On Tue, 14 Jul 2026 14:25:08 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The patch implements an incomplete fix for a TOCTOU data race. It correctly uses READ_ONCE() for `ops_id` to prevent `min_region_sz` corruption, but leaves an identical unresolved race condition for `addr_unit` immediately below it.
> --
>
> --- Patch [5]: [PATCH 5/5] mm/damon/sysfs: read ops_id only once ---
> commit f0f9d921acb64429b2f4e2895a8088cc3b5477d5
> Author: SJ Park <sj@kernel.org>
>
> mm/damon/sysfs: read ops_id only once
>
> This commit addresses a time-of-check to time-of-use race condition in
> damon_sysfs_apply_inputs() by reading ops_id only once. This prevents a
> concurrent sysfs write from causing min_region_sz to be incorrectly
> configured.
>
> Link: https://lore.kernel.org/20260703172417.95426-1-sj@kernel.org
>
> > diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> > index b5fe036f78015..60a1a9e4ada34 100644
> > --- a/mm/damon/sysfs.c
> > +++ b/mm/damon/sysfs.c
> > @@ -2094,14 +2094,16 @@ static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,
>
> [ ... ]
>
> > ctx->addr_unit = sys_ctx->addr_unit;
> > /* addr_unit is respected by only DAMON_OPS_PADDR */
> > - if (sys_ctx->ops_id == DAMON_OPS_PADDR)
> > + if (ops_id == DAMON_OPS_PADDR)
> > ctx->min_region_sz = max(
> > DAMON_MIN_REGION_SZ / sys_ctx->addr_unit, 1);
>
> [Severity: Medium]
> Is there a similar race condition remaining for sys_ctx->addr_unit?
>
> While this patch successfully fixes the race for ops_id, sys_ctx->addr_unit
> is read twice sequentially in this same block of code without protection.
>
> A concurrent sysfs write to addr_unit between the assignment to
> ctx->addr_unit and the division in the max() calculation could cause DAMON
> to inconsistently calculate min_region_sz, degrading monitoring precision.
>
> Should addr_unit also be read only once using READ_ONCE() here to fully
> prevent the race?
Good catch. I also found I forgot adding Fixes: tag. I'll fix this in the
next revision.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260714135236.92699-1-sj@kernel.org?part=5
Thanks,
SJ
next prev parent reply other threads:[~2026-07-14 14:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 13:52 [PATCH 0/5] mm/damon: unurgent fixes for infinite loop, NULL de-ref and races SJ Park
2026-07-14 13:52 ` [PATCH 1/5] mm/damon/core: avoid infinite kdamond_merge_regions() internal loop SJ Park
2026-07-14 13:52 ` [PATCH 2/5] mm/damon/tests/core-kunit: catch test failure in test_merge_regions_of() SJ Park
2026-07-14 14:01 ` sashiko-bot
2026-07-14 14:23 ` SJ Park
2026-07-14 13:52 ` [PATCH 3/5] mm/damon/vaddr: drop last same folio access check optimization SJ Park
2026-07-14 13:52 ` [PATCH 4/5] mm/damon/paddr: drop last same folio access check reuse optimization SJ Park
2026-07-14 13:52 ` [PATCH 5/5] mm/damon/sysfs: read ops_id only once SJ Park
2026-07-14 14:25 ` sashiko-bot
2026-07-14 14:29 ` SJ Park [this message]
2026-07-14 14:32 ` [PATCH 0/5] mm/damon: unurgent fixes for infinite loop, NULL de-ref and races SJ 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=20260714142950.100711-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-bot@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.