From: Roman Gushchin <roman.gushchin@linux.dev>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm: shrinkers: fix double kfree on shrinker name
Date: Wed, 20 Jul 2022 09:29:45 -0700 [thread overview]
Message-ID: <YtgteTnQTgyuKUSY@castle> (raw)
In-Reply-To: <ffa62ece-6a42-2644-16cf-0d33ef32c676@I-love.SAKURA.ne.jp>
On Wed, Jul 20, 2022 at 11:47:55PM +0900, Tetsuo Handa wrote:
> syzbot is reporting double kfree() at free_prealloced_shrinker() [1], for
> destroy_unused_super() calls free_prealloced_shrinker() even if
> prealloc_shrinker() returned an error. Explicitly clear shrinker name
> when prealloc_shrinker() called kfree().
>
> Link: https://syzkaller.appspot.com/bug?extid=8b481578352d4637f510 [1]
> Reported-by: syzbot <syzbot+8b481578352d4637f510@syzkaller.appspotmail.com>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Fixes: e33c267ab70de424 ("mm: shrinkers: provide shrinkers with names")
Hi Tetsuo!
Thank you for the fix! It looks good to me, however I think we should go a bit
further and and zero shrinker->name in all 4 cases where shrinker->name is
freed (an example code below).
Please, feel free to add my ack:
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Thanks!
---
mm/shrinker_debug.c | 1 +
mm/vmscan.c | 9 +++++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c
index e5b40c43221d..b05295bab322 100644
--- a/mm/shrinker_debug.c
+++ b/mm/shrinker_debug.c
@@ -251,6 +251,7 @@ void shrinker_debugfs_remove(struct shrinker *shrinker)
lockdep_assert_held(&shrinker_rwsem);
kfree_const(shrinker->name);
+ shrinker->name = NULL;
if (!shrinker->debugfs_entry)
return;
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 8fa03fb5c5c1..9e7d8db42918 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -647,8 +647,10 @@ int prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...)
return -ENOMEM;
err = __prealloc_shrinker(shrinker);
- if (err)
+ if (err) {
kfree_const(shrinker->name);
+ shrinker->name = NULL;
+ }
return err;
}
@@ -663,6 +665,7 @@ void free_prealloced_shrinker(struct shrinker *shrinker)
{
#ifdef CONFIG_SHRINKER_DEBUG
kfree_const(shrinker->name);
+ shrinker->name = NULL;
#endif
if (shrinker->flags & SHRINKER_MEMCG_AWARE) {
down_write(&shrinker_rwsem);
@@ -707,8 +710,10 @@ int register_shrinker(struct shrinker *shrinker, const char *fmt, ...)
return -ENOMEM;
err = __register_shrinker(shrinker);
- if (err)
+ if (err) {
kfree_const(shrinker->name);
+ shrinker->name = NULL;
+ }
return err;
}
#else
--
2.36.1
prev parent reply other threads:[~2022-07-20 16:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 14:47 [PATCH] mm: shrinkers: fix double kfree on shrinker name Tetsuo Handa
2022-07-20 16:29 ` Roman Gushchin [this message]
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=YtgteTnQTgyuKUSY@castle \
--to=roman.gushchin@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
/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