Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: SJ Park <sj@kernel.org>
To: SJ Park <sj@kernel.org>
Cc: stable@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>,
	damon@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [RFC PATCH] mm/damon/sysfs-schemes: hold damon_sysfs_lock in target_value_store()
Date: Tue, 20 Oct 2026 18:02:22 -0700	[thread overview]
Message-ID: <20261021010223.94305-1-sj@kernel.org> (raw)
In-Reply-To: <20261021005234.94107-1-sj@kernel.org>

On Tue, 20 Oct 2026 17:52:33 -0700 SJ Park <sj@kernel.org> wrote:

> On Tue, 20 Oct 2026 07:47:25 -0700 SJ Park <sj@kernel.org> wrote:
> 
> > Remove a race condition under certain use cases that can trigger
> > divide-by-zero.
> > 
> > damon_sysfs_add_quota_score() setup damos quota goal as user configured
> > and pass to the core layer.  Because it could have a race with
> > damos_sysfs_quota_goals_rm_dirs(), which destructs the files that carry
> > user configuration, both are called under damon_sysfs_lock protection.
> > 
> > The damos quota goal setup disallows zero target_value parameter because
> > it can be used as a denominator later in the core layer function,
> > damos_quota_score().  Otherwise, divide-by-zero can happen.
> 
> This is no more true due to another patch [1].  The patch added the zero
> target_value case in the core layer central validation pass.  But it forgot
> removing the redundant check in sysfs.
> 
> > 
> > For the zero value check and final assignment,
> > damon_sysfs_add_quota_score() reads damos_sysfs_quota_goal->target_value
> > twice.  And user can update damos_sysfs_quota_goal->target_value via
> > target_value_store(), which doesn't hold damon_sysfs_lock.  As a result,
> > a time-of-check-to time-of-use (toctou) race can happen.  If the user
> > sets the value to zero between the zero value check and final
> > target_value assignment, zero target_value is passed to the core layer
> > and results in divide-by-zero.
> 
> So toctou race exists, but it cannot result in divide-by-zero.

And the toctou doesn't matter because the final value based same check will be
made in the core layer.  But the toctou makes readers easy to be confused.  I
will post another patch removing the unnecessary zero value check.


Thanks,
SJ

[...]


      reply	other threads:[~2026-10-21  1:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 14:47 [RFC PATCH] mm/damon/sysfs-schemes: hold damon_sysfs_lock in target_value_store() SJ Park
2026-10-20 14:54 ` sashiko-bot
2026-10-20 15:04   ` SJ Park
2026-10-21  0:52 ` SJ Park
2026-10-21  1:02   ` SJ Park [this message]

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=20261021010223.94305-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox