* [PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application
@ 2025-08-27 11:58 Quanmin Yan
2025-08-27 11:58 ` [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; 4+ messages in thread
From: Quanmin Yan @ 2025-08-27 11:58 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.
Changes from RFC v1
(https://lore.kernel.org/all/20250826033653.1208227-1-yanquanmin1@huawei.com/)
- No code changes.
- Drop RFC tag.
- Add 'Cc: stable@' tags to each patch.
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] 4+ messages in thread
* [PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters()
2025-08-27 11:58 [PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application Quanmin Yan
@ 2025-08-27 11:58 ` Quanmin Yan
2025-08-27 11:58 ` [PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters() Quanmin Yan
2025-08-27 17:28 ` [PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application SeongJae Park
2 siblings, 0 replies; 4+ messages in thread
From: Quanmin Yan @ 2025-08-27 11:58 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")
Cc: <stable@vger.kernel.org> # 6.0.x
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
---
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] 4+ messages in thread
* [PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters()
2025-08-27 11:58 [PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application Quanmin Yan
2025-08-27 11:58 ` [PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Quanmin Yan
@ 2025-08-27 11:58 ` Quanmin Yan
2025-08-27 17:28 ` [PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application SeongJae Park
2 siblings, 0 replies; 4+ messages in thread
From: Quanmin Yan @ 2025-08-27 11:58 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")
Cc: <stable@vger.kernel.org> # 6.1.x
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
---
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] 4+ messages in thread
* Re: [PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application
2025-08-27 11:58 [PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application Quanmin Yan
2025-08-27 11:58 ` [PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Quanmin Yan
2025-08-27 11:58 ` [PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters() Quanmin Yan
@ 2025-08-27 17:28 ` SeongJae Park
2 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2025-08-27 17:28 UTC (permalink / raw)
To: Quanmin Yan
Cc: SeongJae Park, akpm, damon, linux-kernel, linux-mm,
wangkefeng.wang, zuoze1
A trivial typo on the subject: "s/void/avoid/". Andrew, could you please fix
that when you pick this in mm tree? Let us know if we can help.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-27 17:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27 11:58 [PATCH 0/2] mm/damon: void divide-by-zero in DAMON module's parameters application Quanmin Yan
2025-08-27 11:58 ` [PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Quanmin Yan
2025-08-27 11:58 ` [PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters() Quanmin Yan
2025-08-27 17:28 ` [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).