DAMON development mailing list
 help / color / mirror / Atom feed
* [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at()
       [not found] <2026090820-envoy-endanger-c99b@gregkh>
@ 2026-09-09  3:58 ` SJ Park
  2026-09-09  4:02   ` sashiko-bot
  2026-09-09  6:34   ` SJ Park
  2026-09-09  6:36 ` SJ Park
  1 sibling, 2 replies; 7+ messages in thread
From: SJ Park @ 2026-09-09  3:58 UTC (permalink / raw)
  To: stable; +Cc: damon, SJ Park, Brendan Higgins, Andrew Morton

damon_test_split_at() test next region that is assumed to be created by
damon_split_region_at() invocation.  But the split might fail.  In this
case, the succeeding test may dereference invalid pointers returned by
damon_next_region().

The invalid pointer may not cause a really bad user impact, because of the
implementation detail.  It would only read wrong contents in the belonging
damon_target struct.  Depending on the future change of the offset from
the link header to the accessing field, this could also be really
dangerous, though.  Still, the realistic user impact would be limited.  It
would affect only test run setups.

Fix it by testing if the number of regions was also changed as expected
and exit early for the failure.

The issue was discovered [1] by Sashiko.

Link: https://lore.kernel.org/20260718001442.87129-3-sj@kernel.org
Link: https://lore.kernel.org/20260714142352.100478-1-sj@kernel.org [1]
Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
Signed-off-by: SJ Park <sj@kernel.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: <stable@vger.kernel.org> # 5.15.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 9b18ef3c3aa1ce24176e340061caf15fa2742564)
Signed-off-by: SJ Park <sj@kernel.org>
---
 mm/damon/core-test.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
index d8fef225930a5..1dd17d43a642c 100644
--- a/mm/damon/core-test.h
+++ b/mm/damon/core-test.h
@@ -162,6 +162,9 @@ static void damon_test_split_at(struct kunit *test)
 	}
 	damon_add_region(r, t);
 	damon_split_region_at(t, r, 25);
+	KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2);
+	if (!damon_nr_regions(t) != 2)
+		goto out;
 	KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
 	KUNIT_EXPECT_EQ(test, r->ar.end, 25ul);
 
@@ -169,6 +172,7 @@ static void damon_test_split_at(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, r->ar.start, 25ul);
 	KUNIT_EXPECT_EQ(test, r->ar.end, 100ul);
 
+out:
 	damon_free_target(t);
 	damon_destroy_ctx(c);
 }
-- 
2.47.3


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

* Re: [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at()
  2026-09-09  3:58 ` [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at() SJ Park
@ 2026-09-09  4:02   ` sashiko-bot
  2026-09-09  6:32     ` SJ Park
  2026-09-09  6:34   ` SJ Park
  1 sibling, 1 reply; 7+ messages in thread
From: sashiko-bot @ 2026-09-09  4:02 UTC (permalink / raw)
  To: SJ Park; +Cc: damon

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The error-checking condition `!damon_nr_regions(t) != 2` is always true due to operator precedence, causing the test to unconditionally skip its core assertions.
--

commit 6fefc501724f8572d4bbc1782d2ab55fa7568e21
Author: SJ Park <sj@kernel.org>

mm/damon/core-kunit: check region count before testing in split_at()

This patch updates damon_test_split_at() to verify the region count was
successfully changed before proceeding. This prevents invalid pointer
dereferences if the split fails.

Link: https://lore.kernel.org/20260718001442.87129-3-sj@kernel.org
Link: https://lore.kernel.org/20260714142352.100478-1-sj@kernel.org [1]

> diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
> index d8fef225930a5..1dd17d43a642c 100644
> --- a/mm/damon/core-test.h
> +++ b/mm/damon/core-test.h
> @@ -162,6 +162,9 @@ static void damon_test_split_at(struct kunit *test)
>  	}
>  	damon_add_region(r, t);
>  	damon_split_region_at(t, r, 25);
> +	KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2);
> +	if (!damon_nr_regions(t) != 2)
> +		goto out;

[Severity: Medium]
Will this error-checking condition unintentionally skip the core assertions
of the test?

Because of operator precedence, !damon_nr_regions(t) evaluates to either 0
or 1. Neither 0 nor 1 equals 2, meaning the inequality (!= 2) is always true.

This seems to force the test to unconditionally take the goto out path, 
bypassing the boundary validations it is designed to perform.

>  	KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
>  	KUNIT_EXPECT_EQ(test, r->ar.end, 25ul);

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

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

* Re: [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at()
  2026-09-09  4:02   ` sashiko-bot
@ 2026-09-09  6:32     ` SJ Park
  0 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-09-09  6:32 UTC (permalink / raw)
  To: sashiko-bot; +Cc: SJ Park, damon

On Wed, 09 Sep 2026 04:02:48 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The error-checking condition `!damon_nr_regions(t) != 2` is always true due to operator precedence, causing the test to unconditionally skip its core assertions.
> --
> 
> commit 6fefc501724f8572d4bbc1782d2ab55fa7568e21
> Author: SJ Park <sj@kernel.org>
> 
> mm/damon/core-kunit: check region count before testing in split_at()
> 
> This patch updates damon_test_split_at() to verify the region count was
> successfully changed before proceeding. This prevents invalid pointer
> dereferences if the split fails.
> 
> Link: https://lore.kernel.org/20260718001442.87129-3-sj@kernel.org
> Link: https://lore.kernel.org/20260714142352.100478-1-sj@kernel.org [1]
> 
> > diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
> > index d8fef225930a5..1dd17d43a642c 100644
> > --- a/mm/damon/core-test.h
> > +++ b/mm/damon/core-test.h
> > @@ -162,6 +162,9 @@ static void damon_test_split_at(struct kunit *test)
> >  	}
> >  	damon_add_region(r, t);
> >  	damon_split_region_at(t, r, 25);
> > +	KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2);
> > +	if (!damon_nr_regions(t) != 2)
> > +		goto out;
> 
> [Severity: Medium]
> Will this error-checking condition unintentionally skip the core assertions
> of the test?
> 
> Because of operator precedence, !damon_nr_regions(t) evaluates to either 0
> or 1. Neither 0 nor 1 equals 2, meaning the inequality (!= 2) is always true.
> 
> This seems to force the test to unconditionally take the goto out path, 
> bypassing the boundary validations it is designed to perform.

Nice finding, it was a typo.  I will fix.

> 
> >  	KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
> >  	KUNIT_EXPECT_EQ(test, r->ar.end, 25ul);
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260909035813.162131-1-sj@kernel.org?part=1
> 


Thanks,
SJ

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

* Re: [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at()
  2026-09-09  3:58 ` [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at() SJ Park
  2026-09-09  4:02   ` sashiko-bot
@ 2026-09-09  6:34   ` SJ Park
  1 sibling, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-09-09  6:34 UTC (permalink / raw)
  To: SJ Park; +Cc: stable, damon, Brendan Higgins, Andrew Morton

On Tue,  8 Sep 2026 20:58:13 -0700 SJ Park <sj@kernel.org> wrote:

> damon_test_split_at() test next region that is assumed to be created by
> damon_split_region_at() invocation.  But the split might fail.  In this
> case, the succeeding test may dereference invalid pointers returned by
> damon_next_region().
> 
> The invalid pointer may not cause a really bad user impact, because of the
> implementation detail.  It would only read wrong contents in the belonging
> damon_target struct.  Depending on the future change of the offset from
> the link header to the accessing field, this could also be really
> dangerous, though.  Still, the realistic user impact would be limited.  It
> would affect only test run setups.
> 
> Fix it by testing if the number of regions was also changed as expected
> and exit early for the failure.
> 
> The issue was discovered [1] by Sashiko.
> 
> Link: https://lore.kernel.org/20260718001442.87129-3-sj@kernel.org
> Link: https://lore.kernel.org/20260714142352.100478-1-sj@kernel.org [1]
> Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
> Signed-off-by: SJ Park <sj@kernel.org>
> Cc: Brendan Higgins <brendan.higgins@linux.dev>
> Cc: <stable@vger.kernel.org> # 5.15.x
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> (cherry picked from commit 9b18ef3c3aa1ce24176e340061caf15fa2742564)
> Signed-off-by: SJ Park <sj@kernel.org>
> ---
>  mm/damon/core-test.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
> index d8fef225930a5..1dd17d43a642c 100644
> --- a/mm/damon/core-test.h
> +++ b/mm/damon/core-test.h
> @@ -162,6 +162,9 @@ static void damon_test_split_at(struct kunit *test)
>  	}
>  	damon_add_region(r, t);
>  	damon_split_region_at(t, r, 25);
> +	KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2);
> +	if (!damon_nr_regions(t) != 2)
> +		goto out;

Sashiko found the above if condition has a typo.  It should 's/!damon/damon/'.
Please ignore this patch.  I will send a corrected patch as another reply.

>  	KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
>  	KUNIT_EXPECT_EQ(test, r->ar.end, 25ul);
>  
> @@ -169,6 +172,7 @@ static void damon_test_split_at(struct kunit *test)
>  	KUNIT_EXPECT_EQ(test, r->ar.start, 25ul);
>  	KUNIT_EXPECT_EQ(test, r->ar.end, 100ul);
>  
> +out:
>  	damon_free_target(t);
>  	damon_destroy_ctx(c);
>  }
> -- 
> 2.47.3
> 
> 


Thanks,
SJ

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

* [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at()
       [not found] <2026090820-envoy-endanger-c99b@gregkh>
  2026-09-09  3:58 ` [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at() SJ Park
@ 2026-09-09  6:36 ` SJ Park
  2026-09-09  6:47   ` sashiko-bot
  2026-09-09 20:26   ` Sasha Levin
  1 sibling, 2 replies; 7+ messages in thread
From: SJ Park @ 2026-09-09  6:36 UTC (permalink / raw)
  To: stable; +Cc: damon, SJ Park, Brendan Higgins, Andrew Morton

damon_test_split_at() test next region that is assumed to be created by
damon_split_region_at() invocation.  But the split might fail.  In this
case, the succeeding test may dereference invalid pointers returned by
damon_next_region().

The invalid pointer may not cause a really bad user impact, because of the
implementation detail.  It would only read wrong contents in the belonging
damon_target struct.  Depending on the future change of the offset from
the link header to the accessing field, this could also be really
dangerous, though.  Still, the realistic user impact would be limited.  It
would affect only test run setups.

Fix it by testing if the number of regions was also changed as expected
and exit early for the failure.

The issue was discovered [1] by Sashiko.

Link: https://lore.kernel.org/20260718001442.87129-3-sj@kernel.org
Link: https://lore.kernel.org/20260714142352.100478-1-sj@kernel.org [1]
Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
Signed-off-by: SJ Park <sj@kernel.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: <stable@vger.kernel.org> # 5.15.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 9b18ef3c3aa1ce24176e340061caf15fa2742564)
Signed-off-by: SJ Park <sj@kernel.org>
---
 mm/damon/core-test.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
index d8fef225930a5..069c9032b98bc 100644
--- a/mm/damon/core-test.h
+++ b/mm/damon/core-test.h
@@ -162,6 +162,9 @@ static void damon_test_split_at(struct kunit *test)
 	}
 	damon_add_region(r, t);
 	damon_split_region_at(t, r, 25);
+	KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2);
+	if (damon_nr_regions(t) != 2)
+		goto out;
 	KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
 	KUNIT_EXPECT_EQ(test, r->ar.end, 25ul);
 
@@ -169,6 +172,7 @@ static void damon_test_split_at(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, r->ar.start, 25ul);
 	KUNIT_EXPECT_EQ(test, r->ar.end, 100ul);
 
+out:
 	damon_free_target(t);
 	damon_destroy_ctx(c);
 }
-- 
2.47.3


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

* Re: [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at()
  2026-09-09  6:36 ` SJ Park
@ 2026-09-09  6:47   ` sashiko-bot
  2026-09-09 20:26   ` Sasha Levin
  1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-09-09  6:47 UTC (permalink / raw)
  To: SJ Park; +Cc: damon

> damon_test_split_at() test next region that is assumed to be created by
> damon_split_region_at() invocation.  But the split might fail.  In this
> case, the succeeding test may dereference invalid pointers returned by
> damon_next_region().
> 
> The invalid pointer may not cause a really bad user impact, because of the
> implementation detail.  It would only read wrong contents in the belonging
> damon_target struct.  Depending on the future change of the offset from
> the link header to the accessing field, this could also be really
> dangerous, though.  Still, the realistic user impact would be limited.  It
> would affect only test run setups.
> 
> Fix it by testing if the number of regions was also changed as expected
> and exit early for the failure.
> 
> The issue was discovered [1] by Sashiko.
> 
> Link: https://lore.kernel.org/20260718001442.87129-3-sj@kernel.org
> Link: https://lore.kernel.org/20260714142352.100478-1-sj@kernel.org [1]
> Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
> Signed-off-by: SJ Park <sj@kernel.org>
> Cc: Brendan Higgins <brendan.higgins@linux.dev>
> Cc: <stable@vger.kernel.org> # 5.15.x
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> (cherry picked from commit 9b18ef3c3aa1ce24176e340061caf15fa2742564)
> 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/20260909063631.101832-1-sj@kernel.org?part=1


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

* Re: [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at()
  2026-09-09  6:36 ` SJ Park
  2026-09-09  6:47   ` sashiko-bot
@ 2026-09-09 20:26   ` Sasha Levin
  1 sibling, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2026-09-09 20:26 UTC (permalink / raw)
  To: stable; +Cc: Sasha Levin, damon, SJ Park, Brendan Higgins, Andrew Morton

> damon_test_split_at() test next region that is assumed to be created by
> damon_split_region_at() invocation.  But the split might fail.  In this
> case, the succeeding test may dereference invalid pointers returned by
> damon_next_region().

Queued for 6.1, thanks.

-- 
Thanks,
Sasha

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

end of thread, other threads:[~2026-09-09 20:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <2026090820-envoy-endanger-c99b@gregkh>
2026-09-09  3:58 ` [PATCH 6.1.y] mm/damon/core-kunit: check region count before testing in split_at() SJ Park
2026-09-09  4:02   ` sashiko-bot
2026-09-09  6:32     ` SJ Park
2026-09-09  6:34   ` SJ Park
2026-09-09  6:36 ` SJ Park
2026-09-09  6:47   ` sashiko-bot
2026-09-09 20:26   ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox