All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.18.y] mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs()
       [not found] <2026090858-arousal-getting-ee35@gregkh>
@ 2026-09-09  3:28 ` SJ Park
  2026-09-09  3:45   ` sashiko-bot
  2026-09-09 13:01   ` Greg KH
  2026-09-10  0:41 ` SJ Park
  1 sibling, 2 replies; 5+ messages in thread
From: SJ Park @ 2026-09-09  3:28 UTC (permalink / raw)
  To: stable; +Cc: damon, SJ Park, Andrew Morton

damon_sysfs_apply_inputs() reads ops_id twice.  It could race with
ops_id_store().  As a result, the min_region_sz could wrongly be set up.
Read it once.

The user impact is trivial.  Sane users ain't update the parameter in
parallel.  Even if it happens, the DAMON core layer handles the wrong
min_region_sz (!is_power_of_2()).  Even if somehow the race ended up
making a min_region_sz that is different from the user's intention but
still valid, only monitoring itself runs differently than expected.  No
critical consequences like kernel panic or memory corruption happen

The issue was discovered [1] by Sashiko.

Link: https://lore.kernel.org/20260715031002.108504-7-sj@kernel.org
Link: https://lore.kernel.org/20260703172417.95426-1-sj@kernel.org [1]
Fixes: 8d009da32f13 ("mm/damon/sysfs: set damon_ctx->min_sz_region only for paddr use case")
Signed-off-by: SJ Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> # 6.18.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 5adaaa28be8a79ddd7e103b171f9d6e14e7fc26e)
Signed-off-by: SJ Park <sj@kernel.org>
---
 mm/damon/sysfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index a6c3e83a3dad5..655e4de69bee8 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1432,14 +1432,16 @@ static inline bool damon_sysfs_kdamond_running(
 static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,
 		struct damon_sysfs_context *sys_ctx)
 {
+	enum damon_ops_id ops_id;
 	int err;
 
-	err = damon_select_ops(ctx, sys_ctx->ops_id);
+	ops_id = READ_ONCE(sys_ctx->ops_id);
+	err = damon_select_ops(ctx, ops_id);
 	if (err)
 		return err;
 	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_sz_region = max(
 				DAMON_MIN_REGION / sys_ctx->addr_unit, 1);
 	err = damon_sysfs_set_attrs(ctx, sys_ctx->attrs);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 6.18.y] mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs()
  2026-09-09  3:28 ` [PATCH 6.18.y] mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs() SJ Park
@ 2026-09-09  3:45   ` sashiko-bot
  2026-09-09 13:01   ` Greg KH
  1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-09-09  3:45 UTC (permalink / raw)
  To: SJ Park; +Cc: damon

> damon_sysfs_apply_inputs() reads ops_id twice.  It could race with
> ops_id_store().  As a result, the min_region_sz could wrongly be set up.
> Read it once.
> 
> The user impact is trivial.  Sane users ain't update the parameter in
> parallel.  Even if it happens, the DAMON core layer handles the wrong
> min_region_sz (!is_power_of_2()).  Even if somehow the race ended up
> making a min_region_sz that is different from the user's intention but
> still valid, only monitoring itself runs differently than expected.  No
> critical consequences like kernel panic or memory corruption happen
> 
> The issue was discovered [1] by Sashiko.
> 
> Link: https://lore.kernel.org/20260715031002.108504-7-sj@kernel.org
> Link: https://lore.kernel.org/20260703172417.95426-1-sj@kernel.org [1]
> Fixes: 8d009da32f13 ("mm/damon/sysfs: set damon_ctx->min_sz_region only for paddr use case")
> Signed-off-by: SJ Park <sj@kernel.org>
> Cc: <stable@vger.kernel.org> # 6.18.x
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> (cherry picked from commit 5adaaa28be8a79ddd7e103b171f9d6e14e7fc26e)
> Signed-off-by: SJ Park <sj@kernel.org>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909032830.119383-1-sj@kernel.org?part=1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 6.18.y] mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs()
  2026-09-09  3:28 ` [PATCH 6.18.y] mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs() SJ Park
  2026-09-09  3:45   ` sashiko-bot
@ 2026-09-09 13:01   ` Greg KH
  2026-09-10  0:45     ` SJ Park
  1 sibling, 1 reply; 5+ messages in thread
From: Greg KH @ 2026-09-09 13:01 UTC (permalink / raw)
  To: SJ Park; +Cc: stable, damon, Andrew Morton

On Tue, Sep 08, 2026 at 08:28:30PM -0700, SJ Park wrote:
> damon_sysfs_apply_inputs() reads ops_id twice.  It could race with
> ops_id_store().  As a result, the min_region_sz could wrongly be set up.
> Read it once.
> 
> The user impact is trivial.  Sane users ain't update the parameter in
> parallel.  Even if it happens, the DAMON core layer handles the wrong
> min_region_sz (!is_power_of_2()).  Even if somehow the race ended up
> making a min_region_sz that is different from the user's intention but
> still valid, only monitoring itself runs differently than expected.  No
> critical consequences like kernel panic or memory corruption happen
> 
> The issue was discovered [1] by Sashiko.
> 
> Link: https://lore.kernel.org/20260715031002.108504-7-sj@kernel.org
> Link: https://lore.kernel.org/20260703172417.95426-1-sj@kernel.org [1]
> Fixes: 8d009da32f13 ("mm/damon/sysfs: set damon_ctx->min_sz_region only for paddr use case")
> Signed-off-by: SJ Park <sj@kernel.org>
> Cc: <stable@vger.kernel.org> # 6.18.x
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> (cherry picked from commit 5adaaa28be8a79ddd7e103b171f9d6e14e7fc26e)
> Signed-off-by: SJ Park <sj@kernel.org>
> ---
>  mm/damon/sysfs.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> index a6c3e83a3dad5..655e4de69bee8 100644
> --- a/mm/damon/sysfs.c
> +++ b/mm/damon/sysfs.c
> @@ -1432,14 +1432,16 @@ static inline bool damon_sysfs_kdamond_running(
>  static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,
>  		struct damon_sysfs_context *sys_ctx)
>  {
> +	enum damon_ops_id ops_id;
>  	int err;
>  
> -	err = damon_select_ops(ctx, sys_ctx->ops_id);
> +	ops_id = READ_ONCE(sys_ctx->ops_id);
> +	err = damon_select_ops(ctx, ops_id);
>  	if (err)
>  		return err;
>  	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_sz_region = max(
>  				DAMON_MIN_REGION / sys_ctx->addr_unit, 1);
>  	err = damon_sysfs_set_attrs(ctx, sys_ctx->attrs);
> -- 
> 2.47.3
> 
> 

Does not apply :(

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 6.18.y] mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs()
       [not found] <2026090858-arousal-getting-ee35@gregkh>
  2026-09-09  3:28 ` [PATCH 6.18.y] mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs() SJ Park
@ 2026-09-10  0:41 ` SJ Park
  1 sibling, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-09-10  0:41 UTC (permalink / raw)
  To: stable; +Cc: damon, SJ Park, Andrew Morton

damon_sysfs_apply_inputs() reads ops_id twice.  It could race with
ops_id_store().  As a result, the min_region_sz could wrongly be set up.
Read it once.

The user impact is trivial.  Sane users ain't update the parameter in
parallel.  Even if it happens, the DAMON core layer handles the wrong
min_region_sz (!is_power_of_2()).  Even if somehow the race ended up
making a min_region_sz that is different from the user's intention but
still valid, only monitoring itself runs differently than expected.  No
critical consequences like kernel panic or memory corruption happen

The issue was discovered [1] by Sashiko.

Link: https://lore.kernel.org/20260715031002.108504-7-sj@kernel.org
Link: https://lore.kernel.org/20260703172417.95426-1-sj@kernel.org [1]
Fixes: 8d009da32f13 ("mm/damon/sysfs: set damon_ctx->min_sz_region only for paddr use case")
Signed-off-by: SJ Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> # 6.18.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 5adaaa28be8a79ddd7e103b171f9d6e14e7fc26e)
Signed-off-by: SJ Park <sj@kernel.org>
---
 mm/damon/sysfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 53f99f05eb38e..7f52470be36e3 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1440,14 +1440,16 @@ static inline bool damon_sysfs_kdamond_running(
 static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,
 		struct damon_sysfs_context *sys_ctx)
 {
+	enum damon_ops_id ops_id;
 	int err;
 
-	err = damon_select_ops(ctx, sys_ctx->ops_id);
+	ops_id = READ_ONCE(sys_ctx->ops_id);
+	err = damon_select_ops(ctx, ops_id);
 	if (err)
 		return err;
 	ctx->addr_unit = READ_ONCE(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_sz_region = max(
 				DAMON_MIN_REGION / ctx->addr_unit, 1);
 	err = damon_sysfs_set_attrs(ctx, sys_ctx->attrs);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 6.18.y] mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs()
  2026-09-09 13:01   ` Greg KH
@ 2026-09-10  0:45     ` SJ Park
  0 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-09-10  0:45 UTC (permalink / raw)
  To: Greg KH; +Cc: SJ Park, stable, damon, Andrew Morton

On Wed, 9 Sep 2026 15:01:49 +0200 Greg KH <greg@kroah.com> wrote:

> On Tue, Sep 08, 2026 at 08:28:30PM -0700, SJ Park wrote:
> > damon_sysfs_apply_inputs() reads ops_id twice.  It could race with
> > ops_id_store().  As a result, the min_region_sz could wrongly be set up.
> > Read it once.
> > 
> > The user impact is trivial.  Sane users ain't update the parameter in
> > parallel.  Even if it happens, the DAMON core layer handles the wrong
> > min_region_sz (!is_power_of_2()).  Even if somehow the race ended up
> > making a min_region_sz that is different from the user's intention but
> > still valid, only monitoring itself runs differently than expected.  No
> > critical consequences like kernel panic or memory corruption happen
> > 
> > The issue was discovered [1] by Sashiko.
> > 
> > Link: https://lore.kernel.org/20260715031002.108504-7-sj@kernel.org
> > Link: https://lore.kernel.org/20260703172417.95426-1-sj@kernel.org [1]
> > Fixes: 8d009da32f13 ("mm/damon/sysfs: set damon_ctx->min_sz_region only for paddr use case")
> > Signed-off-by: SJ Park <sj@kernel.org>
> > Cc: <stable@vger.kernel.org> # 6.18.x
> > Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> > (cherry picked from commit 5adaaa28be8a79ddd7e103b171f9d6e14e7fc26e)
> > Signed-off-by: SJ Park <sj@kernel.org>
> > ---
> >  mm/damon/sysfs.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> > index a6c3e83a3dad5..655e4de69bee8 100644
> > --- a/mm/damon/sysfs.c
> > +++ b/mm/damon/sysfs.c
> > @@ -1432,14 +1432,16 @@ static inline bool damon_sysfs_kdamond_running(
> >  static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,
> >  		struct damon_sysfs_context *sys_ctx)
> >  {
> > +	enum damon_ops_id ops_id;
> >  	int err;
> >  
> > -	err = damon_select_ops(ctx, sys_ctx->ops_id);
> > +	ops_id = READ_ONCE(sys_ctx->ops_id);
> > +	err = damon_select_ops(ctx, ops_id);
> >  	if (err)
> >  		return err;
> >  	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_sz_region = max(
> >  				DAMON_MIN_REGION / sys_ctx->addr_unit, 1);
> >  	err = damon_sysfs_set_attrs(ctx, sys_ctx->attrs);
> > -- 
> > 2.47.3
> > 
> > 
> 
> Does not apply :(

Seems a patch in 6.18.50..6.18.51-rc1 is causing the conflict.  I just rebased
the patch on 6.18.51-rc1 and posted as another reply [1].

[1] https://lore.kernel.org/20260910004154.115973-1-sj@kernel.org


Thanks,
SJ

[...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-10  0:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <2026090858-arousal-getting-ee35@gregkh>
2026-09-09  3:28 ` [PATCH 6.18.y] mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs() SJ Park
2026-09-09  3:45   ` sashiko-bot
2026-09-09 13:01   ` Greg KH
2026-09-10  0:45     ` SJ Park
2026-09-10  0:41 ` SJ Park

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.