From: sashiko-bot@kernel.org
To: yahia <yahia.a.abdrabou@gmail.com>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH v2 1/1] mm/damon/reclaim: fix potential memory leak
Date: Sat, 20 Jun 2026 02:48:48 +0000 [thread overview]
Message-ID: <20260620024848.A28561F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260620003557.243313-2-yahia.a.abdrabou@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Use-After-Free and double-free in the DAMON reclaim target initialization error path.
--
commit 277092b38a2c2a13afa6d95d878b7d2841e91821
Author: yahia <yahia.a.abdrabou@gmail.com>
mm/damon/reclaim: fix potential memory leak
This commit attempts to fix a potential memory leak in the damon reclaim
initialization path by destroying the context if an error occurs.
> diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
> --- a/mm/damon/reclaim.c
> +++ b/mm/damon/reclaim.c
[ ... ]
> /* 'enabled' has set before this function, probably via command line */
> if (enabled)
> err = damon_reclaim_turn(true);
>
> out:
> if (err && enabled)
> enabled = false;
> +
> + if (err && ctx) {
> + damon_destroy_ctx(ctx);
[Severity: Critical]
Could this introduce a race condition with the kdamond background thread
leading to a use-after-free and double-free?
If damon_reclaim_turn(true) successfully starts the kdamond_fn thread but a
subsequent operation returns an error (such as -ECANCELED if the thread
encounters an early failure), err will be non-zero.
If that happens, kdamond_fn might be concurrently executing its own teardown
sequence:
kdamond_fn()
done:
damon_destroy_targets(ctx);
...
mutex_lock(&ctx->walk_control_lock);
...
If we blindly call damon_destroy_ctx(ctx) here, it frees the ctx and its
targets while the kdamond thread is still actively using and freeing them.
Should this path ensure the kdamond thread has fully stopped (perhaps
via damon_stop() or similar synchronization) before destroying the context?
> + ctx = NULL;
> + }
> return err;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260620003557.243313-2-yahia.a.abdrabou@gmail.com?part=1
next prev parent reply other threads:[~2026-06-20 2:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-19 23:46 [PATCH 0/2] mm/damon/reclaim: fix initalization and parameter issues yahia
2026-06-19 23:46 ` [PATCH 1/2] mm/damon/reclaim: fix destruction of ctx yahia
2026-06-19 23:51 ` sashiko-bot
2026-06-19 23:46 ` [PATCH 2/2] mm/damon/reclaim: fix potential memory leak yahia
2026-06-19 23:56 ` sashiko-bot
2026-06-20 0:26 ` [PATCH 0/2] mm/damon/reclaim: fix initalization and parameter issues SeongJae Park
2026-06-20 0:35 ` [PATCH v2 0/1] fix initialization " yahia
2026-06-20 0:35 ` [PATCH v2 1/1] mm/damon/reclaim: fix potential memory leak yahia
2026-06-20 2:48 ` sashiko-bot [this message]
2026-06-20 3:29 ` [PATCH v3] " yahia
2026-06-20 16:40 ` SeongJae Park
2026-06-20 16:50 ` [PATCH v1] " yahia
2026-06-20 17:09 ` SeongJae Park
2026-06-20 17:20 ` yahia
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=20260620024848.A28561F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yahia.a.abdrabou@gmail.com \
/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