Skip to content

Commit d26f607

Browse files
pbadariakpm00
authored andcommitted
mm/damon/dbgfs: avoid duplicate context directory creation
When user tries to create a DAMON context via the DAMON debugfs interface with a name of an already existing context, the context directory creation fails but a new context is created and added in the internal data structure, due to absence of the directory creation success check. As a result, memory could leak and DAMON cannot be turned on. An example test case is as below: # cd /sys/kernel/debug/damon/ # echo "off" > monitor_on # echo paddr > target_ids # echo "abc" > mk_context # echo "abc" > mk_context # echo $$ > abc/target_ids # echo "on" > monitor_on <<< fails Return value of 'debugfs_create_dir()' is expected to be ignored in general, but this is an exceptional case as DAMON feature is depending on the debugfs functionality and it has the potential duplicate name issue. This commit therefore fixes the issue by checking the directory creation failure and immediately return the error in the case. Link: https://lkml.kernel.org/r/[email protected] Fixes: 75c1c2b ("mm/damon/dbgfs: support multiple contexts") Signed-off-by: Badari Pulavarty <[email protected]> Signed-off-by: SeongJae Park <[email protected]> Cc: <[email protected]> [ 5.15.x] Signed-off-by: Andrew Morton <[email protected]>
1 parent ac733f6 commit d26f607

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

mm/damon/dbgfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,9 @@ static int dbgfs_mk_context(char *name)
818818
return -ENOENT;
819819

820820
new_dir = debugfs_create_dir(name, root);
821+
/* Below check is required for a potential duplicated name case */
822+
if (IS_ERR(new_dir))
823+
return PTR_ERR(new_dir);
821824
dbgfs_dirs[dbgfs_nr_ctxs] = new_dir;
822825

823826
new_ctx = dbgfs_new_ctx();

0 commit comments

Comments
 (0)