All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/damon/sysfs: do not ignore callback's return value in damon_sysfs_damon_call()
@ 2025-09-20 10:52 Akinobu Mita
  2025-09-20 12:11 ` SeongJae Park
  0 siblings, 1 reply; 3+ messages in thread
From: Akinobu Mita @ 2025-09-20 10:52 UTC (permalink / raw)
  To: damon; +Cc: akinobu.mita

The callback return value is ignored in damon_sysfs_damon_call(), which
means that it is not possible to detect invalid user input when writing
commands such as 'commit' to /sys/kernel/mm/damon/admin/kdamonds/<K>/state.
Fix it.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 mm/damon/sysfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index fe4e73d0ebbb..97e16f00f23e 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1627,12 +1627,15 @@ static int damon_sysfs_damon_call(int (*fn)(void *data),
 		struct damon_sysfs_kdamond *kdamond)
 {
 	struct damon_call_control call_control = {};
+	int err;
 
 	if (!kdamond->damon_ctx)
 		return -EINVAL;
 	call_control.fn = fn;
 	call_control.data = kdamond;
-	return damon_call(kdamond->damon_ctx, &call_control);
+	err = damon_call(kdamond->damon_ctx, &call_control);
+
+	return err ? err : call_control.return_code;
 }
 
 struct damon_sysfs_schemes_walk_data {
-- 
2.43.0


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

* Re: [PATCH] mm/damon/sysfs: do not ignore callback's return value in damon_sysfs_damon_call()
  2025-09-20 10:52 [PATCH] mm/damon/sysfs: do not ignore callback's return value in damon_sysfs_damon_call() Akinobu Mita
@ 2025-09-20 12:11 ` SeongJae Park
  2025-09-20 12:53   ` SeongJae Park
  0 siblings, 1 reply; 3+ messages in thread
From: SeongJae Park @ 2025-09-20 12:11 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: SeongJae Park, damon, stable

On Sat, 20 Sep 2025 19:52:36 +0900 Akinobu Mita <akinobu.mita@gmail.com> wrote:

> The callback return value is ignored in damon_sysfs_damon_call(), which
> means that it is not possible to detect invalid user input when writing
> commands such as 'commit' to /sys/kernel/mm/damon/admin/kdamonds/<K>/state.
> Fix it.

Thank you for finding this issue, Akinobu!  Before the introduction of
damon_sysfs_damon_call() and its usages, DAMON sysfs interface was returning an
error in case of such command failures.  So this is fixing a user-visible
unintended behavior change.  Hence this may deserve Cc-ing stable@ in my
opinion.

> 

So, below may better to be added?

Fixes: f64539dcdb87 ("mm/damon/sysfs: use damon_call() for update_schemes_stats")
Cc: <stable@vger.ekrnel.org> # v6.14.x

> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

Reviewed-by: SeongJae Park <sj@kernel.org>

> ---
>  mm/damon/sysfs.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> index fe4e73d0ebbb..97e16f00f23e 100644
> --- a/mm/damon/sysfs.c
> +++ b/mm/damon/sysfs.c
> @@ -1627,12 +1627,15 @@ static int damon_sysfs_damon_call(int (*fn)(void *data),
>  		struct damon_sysfs_kdamond *kdamond)
>  {
>  	struct damon_call_control call_control = {};
> +	int err;
>  
>  	if (!kdamond->damon_ctx)
>  		return -EINVAL;
>  	call_control.fn = fn;
>  	call_control.data = kdamond;
> -	return damon_call(kdamond->damon_ctx, &call_control);
> +	err = damon_call(kdamond->damon_ctx, &call_control);
> +

I think the above new line is not really needed, but it is definitely trivial.

> +	return err ? err : call_control.return_code;
>  }
>  
>  struct damon_sysfs_schemes_walk_data {
> -- 
> 2.43.0


Thanks,
SJ

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

* Re: [PATCH] mm/damon/sysfs: do not ignore callback's return value in damon_sysfs_damon_call()
  2025-09-20 12:11 ` SeongJae Park
@ 2025-09-20 12:53   ` SeongJae Park
  0 siblings, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2025-09-20 12:53 UTC (permalink / raw)
  To: SeongJae Park; +Cc: Akinobu Mita, damon, stable, Andrew Morton

+ Andrew

On Sat, 20 Sep 2025 05:11:31 -0700 SeongJae Park <sj@kernel.org> wrote:

> On Sat, 20 Sep 2025 19:52:36 +0900 Akinobu Mita <akinobu.mita@gmail.com> wrote:
> 
> > The callback return value is ignored in damon_sysfs_damon_call(), which
> > means that it is not possible to detect invalid user input when writing
> > commands such as 'commit' to /sys/kernel/mm/damon/admin/kdamonds/<K>/state.
> > Fix it.
> 
> Thank you for finding this issue, Akinobu!  Before the introduction of
> damon_sysfs_damon_call() and its usages, DAMON sysfs interface was returning an
> error in case of such command failures.  So this is fixing a user-visible
> unintended behavior change.  Hence this may deserve Cc-ing stable@ in my
> opinion.
> 
> > 
> 
> So, below may better to be added?
> 
> Fixes: f64539dcdb87 ("mm/damon/sysfs: use damon_call() for update_schemes_stats")
> Cc: <stable@vger.ekrnel.org> # v6.14.x
> 
> > Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> 
> Reviewed-by: SeongJae Park <sj@kernel.org>
> 
> > ---
> >  mm/damon/sysfs.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> > index fe4e73d0ebbb..97e16f00f23e 100644
> > --- a/mm/damon/sysfs.c
> > +++ b/mm/damon/sysfs.c
> > @@ -1627,12 +1627,15 @@ static int damon_sysfs_damon_call(int (*fn)(void *data),
> >  		struct damon_sysfs_kdamond *kdamond)
> >  {
> >  	struct damon_call_control call_control = {};
> > +	int err;
> >  
> >  	if (!kdamond->damon_ctx)
> >  		return -EINVAL;
> >  	call_control.fn = fn;
> >  	call_control.data = kdamond;
> > -	return damon_call(kdamond->damon_ctx, &call_control);
> > +	err = damon_call(kdamond->damon_ctx, &call_control);
> > +
> 
> I think the above new line is not really needed, but it is definitely trivial.
> 
> > +	return err ? err : call_control.return_code;
> >  }
> >  
> >  struct damon_sysfs_schemes_walk_data {
> > -- 
> > 2.43.0
> 
> 
> Thanks,
> SJ
> 

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

end of thread, other threads:[~2025-09-20 12:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-20 10:52 [PATCH] mm/damon/sysfs: do not ignore callback's return value in damon_sysfs_damon_call() Akinobu Mita
2025-09-20 12:11 ` SeongJae Park
2025-09-20 12:53   ` SeongJae 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.