linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application
@ 2025-08-26  3:36 Quanmin Yan
  2025-08-26  3:36 ` [RFC PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Quanmin Yan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Quanmin Yan @ 2025-08-26  3:36 UTC (permalink / raw)
  To: sj
  Cc: akpm, damon, linux-kernel, linux-mm, yanquanmin1, wangkefeng.wang,
	zuoze1

DAMON's RECLAIM or LRU_SORT modules perform no validation on
user-configured parameters during application, which may lead
to division-by-zero errors.

Avoid the divide-by-zero by adding validation checks when DAMON
modules attempt to apply the parameters.

Quanmin Yan (2):
  mm/damon/lru_sort: avoid divide-by-zero in
    damon_lru_sort_apply_parameters()
  mm/damon/reclaim: avoid divide-by-zero in
    damon_reclaim_apply_parameters()

 mm/damon/lru_sort.c | 5 +++++
 mm/damon/reclaim.c  | 5 +++++
 2 files changed, 10 insertions(+)

-- 
2.43.0



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

* [RFC PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters()
  2025-08-26  3:36 [RFC PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application Quanmin Yan
@ 2025-08-26  3:36 ` Quanmin Yan
  2025-08-26 14:32   ` SeongJae Park
  2025-08-26  3:36 ` [RFC PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters() Quanmin Yan
  2025-08-26 14:36 ` [RFC PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application SeongJae Park
  2 siblings, 1 reply; 6+ messages in thread
From: Quanmin Yan @ 2025-08-26  3:36 UTC (permalink / raw)
  To: sj
  Cc: akpm, damon, linux-kernel, linux-mm, yanquanmin1, wangkefeng.wang,
	zuoze1

During the calculation of 'hot_thres' and 'cold_thres', either
'sample_interval' or 'aggr_interval' is used as the divisor,
which may lead to division-by-zero errors. Fix it by directly
returning -EINVAL when such a case occurs. Additionally, since
'aggr_interval' is already required to be set no smaller than
'sample_interval' in damon_set_attrs(), only the case where
'sample_interval' is zero needs to be checked.

Fixes: 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting")
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
---
 mm/damon/lru_sort.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 151a9de5ad8b..b5a5ed16a7a5 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -198,6 +198,11 @@ static int damon_lru_sort_apply_parameters(void)
 	if (err)
 		return err;
 
+	if (!damon_lru_sort_mon_attrs.sample_interval) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	err = damon_set_attrs(ctx, &damon_lru_sort_mon_attrs);
 	if (err)
 		goto out;
-- 
2.43.0



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

* [RFC PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters()
  2025-08-26  3:36 [RFC PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application Quanmin Yan
  2025-08-26  3:36 ` [RFC PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Quanmin Yan
@ 2025-08-26  3:36 ` Quanmin Yan
  2025-08-26 14:34   ` SeongJae Park
  2025-08-26 14:36 ` [RFC PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application SeongJae Park
  2 siblings, 1 reply; 6+ messages in thread
From: Quanmin Yan @ 2025-08-26  3:36 UTC (permalink / raw)
  To: sj
  Cc: akpm, damon, linux-kernel, linux-mm, yanquanmin1, wangkefeng.wang,
	zuoze1

When creating a new scheme of DAMON_RECLAIM, the calculation
of 'min_age_region' uses 'aggr_interval' as the divisor, which
may lead to division-by-zero errors. Fix it by directly returning
-EINVAL when such a case occurs.

Fixes: f5a79d7c0c87 ("mm/damon: introduce struct damos_access_pattern")
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
---
 mm/damon/reclaim.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 3c71b4596676..fb7c982a0018 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -194,6 +194,11 @@ static int damon_reclaim_apply_parameters(void)
 	if (err)
 		return err;
 
+	if (!damon_reclaim_mon_attrs.aggr_interval) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	err = damon_set_attrs(param_ctx, &damon_reclaim_mon_attrs);
 	if (err)
 		goto out;
-- 
2.43.0



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

* Re: [RFC PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters()
  2025-08-26  3:36 ` [RFC PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Quanmin Yan
@ 2025-08-26 14:32   ` SeongJae Park
  0 siblings, 0 replies; 6+ messages in thread
From: SeongJae Park @ 2025-08-26 14:32 UTC (permalink / raw)
  To: Quanmin Yan
  Cc: SeongJae Park, akpm, damon, linux-kernel, linux-mm,
	wangkefeng.wang, zuoze1

On Tue, 26 Aug 2025 11:36:52 +0800 Quanmin Yan <yanquanmin1@huawei.com> wrote:

> During the calculation of 'hot_thres' and 'cold_thres', either
> 'sample_interval' or 'aggr_interval' is used as the divisor,
> which may lead to division-by-zero errors. Fix it by directly
> returning -EINVAL when such a case occurs. Additionally, since
> 'aggr_interval' is already required to be set no smaller than
> 'sample_interval' in damon_set_attrs(), only the case where
> 'sample_interval' is zero needs to be checked.

Nice catch and fix!

> 
> Fixes: 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting")

Let's add Cc: stable@

> Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>

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


Thanks,
SJ

[...]


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

* Re: [RFC PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters()
  2025-08-26  3:36 ` [RFC PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters() Quanmin Yan
@ 2025-08-26 14:34   ` SeongJae Park
  0 siblings, 0 replies; 6+ messages in thread
From: SeongJae Park @ 2025-08-26 14:34 UTC (permalink / raw)
  To: Quanmin Yan
  Cc: SeongJae Park, akpm, damon, linux-kernel, linux-mm,
	wangkefeng.wang, zuoze1

On Tue, 26 Aug 2025 11:36:53 +0800 Quanmin Yan <yanquanmin1@huawei.com> wrote:

> When creating a new scheme of DAMON_RECLAIM, the calculation
> of 'min_age_region' uses 'aggr_interval' as the divisor, which
> may lead to division-by-zero errors. Fix it by directly returning
> -EINVAL when such a case occurs.

Nice catch, thank you for this patch!

> 
> Fixes: f5a79d7c0c87 ("mm/damon: introduce struct damos_access_pattern")

Let's add Cc: stable@

> Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>

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


Thanks,
SJ

[...]


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

* Re: [RFC PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application
  2025-08-26  3:36 [RFC PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application Quanmin Yan
  2025-08-26  3:36 ` [RFC PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Quanmin Yan
  2025-08-26  3:36 ` [RFC PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters() Quanmin Yan
@ 2025-08-26 14:36 ` SeongJae Park
  2 siblings, 0 replies; 6+ messages in thread
From: SeongJae Park @ 2025-08-26 14:36 UTC (permalink / raw)
  To: Quanmin Yan
  Cc: SeongJae Park, akpm, damon, linux-kernel, linux-mm,
	wangkefeng.wang, zuoze1

On Tue, 26 Aug 2025 11:36:51 +0800 Quanmin Yan <yanquanmin1@huawei.com> wrote:

> DAMON's RECLAIM or LRU_SORT modules perform no validation on
> user-configured parameters during application, which may lead
> to division-by-zero errors.
> 
> Avoid the divide-by-zero by adding validation checks when DAMON
> modules attempt to apply the parameters.

Thank you for finding and fixing these problems, Quanmin!  All looks good,
though I think it would be better to add 'Cc: stable@' tags to each patch.


Thanks,
SJ

[...]


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

end of thread, other threads:[~2025-08-26 14:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26  3:36 [RFC PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application Quanmin Yan
2025-08-26  3:36 ` [RFC PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Quanmin Yan
2025-08-26 14:32   ` SeongJae Park
2025-08-26  3:36 ` [RFC PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters() Quanmin Yan
2025-08-26 14:34   ` SeongJae Park
2025-08-26 14:36 ` [RFC PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).