* [PATCH 0/8] mm/damon: move damos filter range arguments validation to core
@ 2026-09-14 14:23 SJ Park
2026-09-14 14:23 ` [PATCH 7/8] mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input SJ Park
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: SJ Park @ 2026-09-14 14:23 UTC (permalink / raw)
To: Andrew Morton
Cc: SJ Park, stable, Brendan Higgins, David Gow, Usama Arif, damon,
kunit-dev, linux-kernel, linux-kselftest, linux-mm
DAMOS filter range arguments are being validated in the DAMON sysfs
interface. Some of those have minor time-of-check to time-of-use
(TOCTOU) bugs. In future, other callers might have duplicated
validations with similar bugs.
Fix the bugs and further refactor the code to move the validation to the
core layer. Also add kunit test cases for the validations.
Patches 1 and 2 fix the existing TOCTOU bugs. Patches 3 and 4 adds the
validation in the core layer. Patch 5 drops the replicated validation
in DAMON sysfs interface. Patch 6 further cleanup the code. Patches 7
and 8 extends kunit tests to test the validation.
Changes from RFC v2
- RFC v2: https://lore.kernel.org/20260913171706.103052-1-sj@kernel.org
- Drop RFC tag.
- Rebase to latest mm-new.
Changes from RFC
- RFC: https://lore.kernel.org/20260912191807.138502-1-sj@kernel.org
- Handle error from damos_commit_filter_arg() on all call sites.
SJ Park (8):
mm/damon/sysfs-schemes: read sysfs_filter->addr_range only once
mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
mm/damon/core: return an error from damos_commit_filter_arg()
mm/damon/core: disallow max < min damos filter range arguments commit
mm/damon/sysfs-schemes: drop centralized filter range arg validations
mm/damon/sysfs-schemes: use switch-case in add_scheme_filters()
mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input
mm/damon/core-kunit: test invalid damos filter commits
mm/damon/core.c | 47 +++++++++++++++++++++++++++----------
mm/damon/sysfs-schemes.c | 32 ++++++++++---------------
mm/damon/tests/core-kunit.h | 38 +++++++++++++++++++++++-------
3 files changed, 76 insertions(+), 41 deletions(-)
base-commit: 5e38c61dbb4349ff7e900d97d96f369c64678eea
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 7/8] mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input
2026-09-14 14:23 [PATCH 0/8] mm/damon: move damos filter range arguments validation to core SJ Park
@ 2026-09-14 14:23 ` SJ Park
2026-09-14 14:23 ` [PATCH 8/8] mm/damon/core-kunit: test invalid damos filter commits SJ Park
2026-09-14 23:43 ` [PATCH 0/8] mm/damon: move damos filter range arguments validation to core SJ Park
2 siblings, 0 replies; 4+ messages in thread
From: SJ Park @ 2026-09-14 14:23 UTC (permalink / raw)
To: Andrew Morton
Cc: SJ Park, Brendan Higgins, David Gow, damon, kunit-dev,
linux-kernel, linux-kselftest, linux-mm
damos_commit_filter_for() supposes damos_commit_filter() to always
succeed with given inputs. damos_commit_filter() could return an error
for invalid inputs. Existing callers always pass only valid inputs, but
they may pass invalid inputs in future, for test purposes. Extend the
function to be able to be used for wrong inputs-caused error testing.
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index a47a5cdf285c8..c9941f3bfb42b 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1127,9 +1127,15 @@ static void damos_test_commit_dests(struct kunit *test)
}
static void damos_test_commit_filter_for(struct kunit *test,
- struct damos_filter *dst, struct damos_filter *src)
+ struct damos_filter *dst, struct damos_filter *src,
+ bool expect_fail)
{
- damos_commit_filter(dst, src);
+ int err;
+
+ err = damos_commit_filter(dst, src);
+ KUNIT_EXPECT_EQ(test, err != 0, expect_fail);
+ if (expect_fail)
+ return;
KUNIT_EXPECT_EQ(test, dst->type, src->type);
KUNIT_EXPECT_EQ(test, dst->matching, src->matching);
KUNIT_EXPECT_EQ(test, dst->allow, src->allow);
@@ -1168,47 +1174,47 @@ static void damos_test_commit_filter(struct kunit *test)
.type = DAMOS_FILTER_TYPE_ANON,
.matching = true,
.allow = true,
- });
+ }, false);
damos_test_commit_filter_for(test, &dst,
&(struct damos_filter){
.type = DAMOS_FILTER_TYPE_MEMCG,
.matching = false,
.allow = false,
.memcg_id = 123,
- });
+ }, false);
damos_test_commit_filter_for(test, &dst,
&(struct damos_filter){
.type = DAMOS_FILTER_TYPE_YOUNG,
.matching = true,
.allow = true,
- });
+ }, false);
damos_test_commit_filter_for(test, &dst,
&(struct damos_filter){
.type = DAMOS_FILTER_TYPE_HUGEPAGE_SIZE,
.matching = false,
.allow = false,
.sz_range = {.min = 234, .max = 345},
- });
+ }, false);
damos_test_commit_filter_for(test, &dst,
&(struct damos_filter){
.type = DAMOS_FILTER_TYPE_UNMAPPED,
.matching = true,
.allow = true,
- });
+ }, false);
damos_test_commit_filter_for(test, &dst,
&(struct damos_filter){
.type = DAMOS_FILTER_TYPE_ADDR,
.matching = false,
.allow = false,
.addr_range = {.start = 456, .end = 567},
- });
+ }, false);
damos_test_commit_filter_for(test, &dst,
&(struct damos_filter){
.type = DAMOS_FILTER_TYPE_TARGET,
.matching = true,
.allow = true,
.target_idx = 6,
- });
+ }, false);
}
static void damos_test_help_initailize_scheme(struct damos *scheme)
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 8/8] mm/damon/core-kunit: test invalid damos filter commits
2026-09-14 14:23 [PATCH 0/8] mm/damon: move damos filter range arguments validation to core SJ Park
2026-09-14 14:23 ` [PATCH 7/8] mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input SJ Park
@ 2026-09-14 14:23 ` SJ Park
2026-09-14 23:43 ` [PATCH 0/8] mm/damon: move damos filter range arguments validation to core SJ Park
2 siblings, 0 replies; 4+ messages in thread
From: SJ Park @ 2026-09-14 14:23 UTC (permalink / raw)
To: Andrew Morton
Cc: SJ Park, Brendan Higgins, David Gow, damon, kunit-dev,
linux-kernel, linux-kselftest, linux-mm
Add test cases for testing the validation of damos filter arguments in
commit time.
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index c9941f3bfb42b..5da84caf4124d 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1195,6 +1195,13 @@ static void damos_test_commit_filter(struct kunit *test)
.allow = false,
.sz_range = {.min = 234, .max = 345},
}, false);
+ damos_test_commit_filter_for(test, &dst,
+ &(struct damos_filter){
+ .type = DAMOS_FILTER_TYPE_HUGEPAGE_SIZE,
+ .matching = false,
+ .allow = false,
+ .sz_range = {.min = 456, .max = 123},
+ }, true);
damos_test_commit_filter_for(test, &dst,
&(struct damos_filter){
.type = DAMOS_FILTER_TYPE_UNMAPPED,
@@ -1208,6 +1215,13 @@ static void damos_test_commit_filter(struct kunit *test)
.allow = false,
.addr_range = {.start = 456, .end = 567},
}, false);
+ damos_test_commit_filter_for(test, &dst,
+ &(struct damos_filter){
+ .type = DAMOS_FILTER_TYPE_ADDR,
+ .matching = false,
+ .allow = false,
+ .addr_range = {.start = 567, .end = 456},
+ }, true);
damos_test_commit_filter_for(test, &dst,
&(struct damos_filter){
.type = DAMOS_FILTER_TYPE_TARGET,
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/8] mm/damon: move damos filter range arguments validation to core
2026-09-14 14:23 [PATCH 0/8] mm/damon: move damos filter range arguments validation to core SJ Park
2026-09-14 14:23 ` [PATCH 7/8] mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input SJ Park
2026-09-14 14:23 ` [PATCH 8/8] mm/damon/core-kunit: test invalid damos filter commits SJ Park
@ 2026-09-14 23:43 ` SJ Park
2 siblings, 0 replies; 4+ messages in thread
From: SJ Park @ 2026-09-14 23:43 UTC (permalink / raw)
To: Andrew Morton
Cc: SJ Park, stable, Brendan Higgins, David Gow, Usama Arif, damon,
kunit-dev, linux-kernel, linux-kselftest, linux-mm
On Mon, 14 Sep 2026 07:23:17 -0700 SJ Park <sj@kernel.org> wrote:
> DAMOS filter range arguments are being validated in the DAMON sysfs
> interface. Some of those have minor time-of-check to time-of-use
> (TOCTOU) bugs. In future, other callers might have duplicated
> validations with similar bugs.
>
> Fix the bugs and further refactor the code to move the validation to the
> core layer. Also add kunit test cases for the validations.
Sashiko found no blocker for this series. Sashiko send its findings to damon@
mailing list [1], and I reply those if anything needs to be clarified. Please
refer to those for details.
[1] https://lore.kernel.org/damon/
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-14 23:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-14 14:23 [PATCH 0/8] mm/damon: move damos filter range arguments validation to core SJ Park
2026-09-14 14:23 ` [PATCH 7/8] mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input SJ Park
2026-09-14 14:23 ` [PATCH 8/8] mm/damon/core-kunit: test invalid damos filter commits SJ Park
2026-09-14 23:43 ` [PATCH 0/8] mm/damon: move damos filter range arguments validation to core SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox