Skip to content

Commit 3479641

Browse files
sjp38torvalds
authored andcommitted
mm/damon/dbgfs: protect targets destructions with kdamond_lock
DAMON debugfs interface iterates current monitoring targets in 'dbgfs_target_ids_read()' while holding the corresponding 'kdamond_lock'. However, it also destructs the monitoring targets in 'dbgfs_before_terminate()' without holding the lock. This can result in a use_after_free bug. This commit avoids the race by protecting the destruction with the corresponding 'kdamond_lock'. Link: https://lkml.kernel.org/r/[email protected] Reported-by: Sangwoo Bae <[email protected]> Fixes: 4bc0595 ("mm/damon: implement a debugfs-based user space interface") Signed-off-by: SeongJae Park <[email protected]> Cc: <[email protected]> [5.15.x] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 595ec19 commit 3479641

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

mm/damon/dbgfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,12 @@ static void dbgfs_before_terminate(struct damon_ctx *ctx)
650650
if (!targetid_is_pid(ctx))
651651
return;
652652

653+
mutex_lock(&ctx->kdamond_lock);
653654
damon_for_each_target_safe(t, next, ctx) {
654655
put_pid((struct pid *)t->id);
655656
damon_destroy_target(t);
656657
}
658+
mutex_unlock(&ctx->kdamond_lock);
657659
}
658660

659661
static struct damon_ctx *dbgfs_new_ctx(void)

0 commit comments

Comments
 (0)