linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mm-unstable 0/2] mm/damon/sysfs-schemes: avoid updating
@ 2022-11-14 18:29 SeongJae Park
  2022-11-14 18:29 ` [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: skip tried regions update if the scheme directory has removed SeongJae Park
  2022-11-14 18:29 ` [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: skip schemes regions clearing " SeongJae Park
  0 siblings, 2 replies; 3+ messages in thread
From: SeongJae Park @ 2022-11-14 18:29 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, damon, linux-mm, linux-kernel

A DAMON sysfs interface user can start DAMON with a scheme, remove the
sysfs directory for the scheme, and then ask clears/updates of the
scheme's tried regions.  Because the schemes tried regions clear/update
logic doesn't aware of the situation, it results in an invalid memory
access.  Fix the bugs by checking if the scheme sysfs directory exists.

This patchset is fixing commits in mm-unstable.  Andrew, please meld the
first patch into "mm/damon/sysfs: implement DAMOS tried regions update
command"[1], and the second patch into "mm/damon/sysfs-schemes:
implement DAMOS-tried regions clear command"[2].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-damon-sysfs-implement-damos-tried-regions-update-command.patch
[2] https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-damon-sysfs-schemes-implement-damos-tried-regions-clear-command.patch

SeongJae Park (2):
  mm/damon/sysfs-schemes: skip tried regions update if the scheme
    directory has removed
  mm/damon/sysfs-schemes: skip schemes regions clearing if the scheme
    directory has removed

 mm/damon/sysfs-schemes.c | 9 +++++++++
 1 file changed, 9 insertions(+)

-- 
2.25.1



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

* [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: skip tried regions update if the scheme directory has removed
  2022-11-14 18:29 [PATCH mm-unstable 0/2] mm/damon/sysfs-schemes: avoid updating SeongJae Park
@ 2022-11-14 18:29 ` SeongJae Park
  2022-11-14 18:29 ` [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: skip schemes regions clearing " SeongJae Park
  1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2022-11-14 18:29 UTC (permalink / raw)
  To: SeongJae Park, Andrew Morton; +Cc: damon, linux-mm, linux-kernel

A DAMON sysfs interface user can start DAMON with a scheme, remove the
sysfs directory for the scheme, and then ask updates of the scheme's
tried regions.  Because the schemes tried regions update logic doesn't
aware of the situation, it results in an invalid memory access.  Fix the
bug by checking if the scheme sysfs directory exists.

Fixes: 1322c8148dfe ("mm/damon/sysfs: implement DAMOS tried regions update command") # mm-unstable
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index a79aa32d3422..4df3c99983e8 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1231,6 +1231,11 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx,
 			break;
 		schemes_idx++;
 	}
+
+	/* user could removed the scheme sysfs dir */
+	if (schemes_idx >= sysfs_schemes->nr)
+		return 0;
+
 	sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions;
 	region = damon_sysfs_scheme_region_alloc(r);
 	list_add_tail(&region->list, &sysfs_regions->regions_list);
-- 
2.25.1



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

* [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: skip schemes regions clearing if the scheme directory has removed
  2022-11-14 18:29 [PATCH mm-unstable 0/2] mm/damon/sysfs-schemes: avoid updating SeongJae Park
  2022-11-14 18:29 ` [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: skip tried regions update if the scheme directory has removed SeongJae Park
@ 2022-11-14 18:29 ` SeongJae Park
  1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2022-11-14 18:29 UTC (permalink / raw)
  To: SeongJae Park, Andrew Morton; +Cc: damon, linux-mm, linux-kernel

A DAMON sysfs interface user can start DAMON with a scheme, remove the
sysfs directory for the scheme, and then ask clearing of the scheme's
tried regions.  Because the schemes tried regions clearing logic doesn't
aware of the situation, it results in an invalid memory access.  Fix the
bug by checking if the scheme sysfs directory exists.

Fixes: bb9641eb3a3e ("mm/damon/sysfs-schemes: implement DAMOS-tried regions clear command") # mm-unstable
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 4df3c99983e8..e6baf55d617d 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1260,6 +1260,10 @@ int damon_sysfs_schemes_clear_regions(
 	damon_for_each_scheme(scheme, ctx) {
 		struct damon_sysfs_scheme *sysfs_scheme;
 
+		/* user could removed the scheme sysfs dir */
+		if (schemes_idx >= sysfs_schemes->nr)
+			break;
+
 		sysfs_scheme = sysfs_schemes->schemes_arr[schemes_idx++];
 		damon_sysfs_scheme_regions_rm_dirs(
 				sysfs_scheme->tried_regions);
-- 
2.25.1



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

end of thread, other threads:[~2022-11-14 18:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-14 18:29 [PATCH mm-unstable 0/2] mm/damon/sysfs-schemes: avoid updating SeongJae Park
2022-11-14 18:29 ` [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: skip tried regions update if the scheme directory has removed SeongJae Park
2022-11-14 18:29 ` [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: skip schemes regions clearing " SeongJae Park

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