From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SeongJae Park <sj@kernel.org>,
"# 5 . 15 . x" <stable@vger.kernel.org>,
Brendan Higgins <brendan.higgins@linux.dev>,
David Gow <davidgow@google.com>,
damon@lists.linux.dev, kunit-dev@googlegroups.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-mm@kvack.org
Subject: [PATCH 08/22] mm/damon/tests/core-kunit: handle alloc failures on damon_test_split_regions_of()
Date: Sat, 1 Nov 2025 11:20:02 -0700 [thread overview]
Message-ID: <20251101182021.74868-9-sj@kernel.org> (raw)
In-Reply-To: <20251101182021.74868-1-sj@kernel.org>
damon_test_split_regions_of() is assuming all dynamic memory allocation
in it will succeed. Those are indeed likely in the real use cases since
those allocations are too small to fail, but theoretically those could
fail. In the case, inappropriate memory access can happen. Fix it by
appropriately cleanup pre-allocated memory and skip the execution of the
remaining tests in the failure cases.
Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
Cc: <stable@vger.kernel.org> # 5.15.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 98f2a3de7cea..10618cdd188e 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -278,15 +278,35 @@ static void damon_test_split_regions_of(struct kunit *test)
struct damon_target *t;
struct damon_region *r;
+ if (!c)
+ kunit_skip("ctx alloc fail");
t = damon_new_target();
+ if (!t) {
+ damon_destroy_ctx(c);
+ kunit_skip(test, "target alloc fail");
+ }
r = damon_new_region(0, 22);
+ if (!r) {
+ damon_destroy_ctx(c);
+ damon_free_target(t);
+ kunit_skip(test, "region alloc fail");
+ }
damon_add_region(r, t);
damon_split_regions_of(t, 2, DAMON_MIN_REGION);
KUNIT_EXPECT_LE(test, damon_nr_regions(t), 2u);
damon_free_target(t);
t = damon_new_target();
+ if (!t) {
+ damon_destroy_ctx(c);
+ kunit_skip(test, "second target alloc fail");
+ }
r = damon_new_region(0, 220);
+ if (!r) {
+ damon_destroy_ctx(c);
+ damon_free_target(t);
+ kunit_skip(test, "second region alloc fail");
+ }
damon_add_region(r, t);
damon_split_regions_of(t, 4, DAMON_MIN_REGION);
KUNIT_EXPECT_LE(test, damon_nr_regions(t), 4u);
--
2.47.3
next prev parent reply other threads:[~2025-11-01 18:20 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-01 18:19 [PATCH 00/22] mm/damon/tests: fix memory bugs in kunit tests SeongJae Park
2025-11-01 18:19 ` [PATCH 01/22] mm/damon/tests/core-kunit: fix memory leak in damon_test_set_filters_default_reject() SeongJae Park
2025-11-01 18:19 ` [PATCH 02/22] mm/damon/tests/core-kunit: handle allocation failures in damon_test_regions() SeongJae Park
2025-11-01 18:19 ` [PATCH 03/22] mm/damon/tests/core-kunit: handle memory failure from damon_test_target() SeongJae Park
2025-11-01 18:19 ` [PATCH 04/22] mm/damon/tests/core-kunit: handle memory alloc failure from damon_test_aggregate() SeongJae Park
2025-11-01 18:19 ` [PATCH 05/22] mm/damon/tests/core-kunit: handle alloc failures on damon_test_split_at() SeongJae Park
2025-11-01 18:20 ` [PATCH 06/22] mm/damon/tests/core-kunit: handle alloc failures on damon_test_merge_two() SeongJae Park
2025-11-01 18:20 ` [PATCH 07/22] mm/damon/tests/core-kunit: handle alloc failures on dasmon_test_merge_regions_of() SeongJae Park
2025-11-01 18:20 ` SeongJae Park [this message]
2025-11-01 18:20 ` [PATCH 09/22] mm/damon/tests/core-kunit: handle alloc failures in damon_test_ops_registration() SeongJae Park
2025-11-01 18:20 ` [PATCH 10/22] mm/damon/tests/core-kunit: handle alloc failures in damon_test_set_regions() SeongJae Park
2025-11-01 18:20 ` [PATCH 11/22] mm/damon/tests/core-kunit: handle alloc failures in damon_test_update_monitoring_result() SeongJae Park
2025-11-01 18:20 ` [PATCH 12/22] mm/damon/tests/core-kunit: handle alloc failure on damon_test_set_attrs() SeongJae Park
2025-11-01 18:20 ` [PATCH 13/22] mm/damon/tests/core-kunit: handle alloc failres in damon_test_new_filter() SeongJae Park
2025-11-01 18:20 ` [PATCH 14/22] mm/damon/tests/core-kunit: handle alloc failure on damos_test_commit_filter() SeongJae Park
2025-11-01 18:20 ` [PATCH 15/22] mm/damon/tests/core-kunit: handle alloc failures on damos_test_filter_out() SeongJae Park
2025-11-01 18:20 ` [PATCH 16/22] mm/damon/tests/core-kunit: handle alloc failures on damon_test_set_filters_default_reject() SeongJae Park
2025-11-01 18:20 ` [PATCH 17/22] mm/damon/tests/vaddr-kunit: handle alloc failures on damon_do_test_apply_three_regions() SeongJae Park
2025-11-01 18:20 ` [PATCH 18/22] mm/damon/tests/vaddr-kunit: handle alloc failures in damon_test_split_evenly_fail() SeongJae Park
2025-11-01 18:20 ` [PATCH 19/22] mm/damon/tests/vaddr-kunit: handle alloc failures on damon_test_split_evenly_succ() SeongJae Park
2025-11-01 18:20 ` [PATCH 20/22] mm/damon/tests/sysfs-kunit: handle alloc failures on damon_sysfs_test_add_targets() SeongJae Park
2025-11-01 18:20 ` [PATCH 21/22] mm/damon/tests/core-kunit: remove unnecessary damon_ctx variable on damon_test_split_at() SeongJae Park
2025-11-01 18:20 ` [PATCH 22/22] mm/damon/tests/core-kunit: remove unused ctx in damon_test_split_regions_of() SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251101182021.74868-9-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.higgins@linux.dev \
--cc=damon@lists.linux.dev \
--cc=davidgow@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).