[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <YtgteTnQTgyuKUSY@castle>
Date: Wed, 20 Jul 2022 09:29:45 -0700
From: Roman Gushchin <roman.gushchin@...ux.dev>
To: Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] mm: shrinkers: fix double kfree on shrinker name
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@...kaller.appspotmail.com>
> Signed-off-by: Tetsuo Handa <penguin-kernel@...ove.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@...ux.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
Powered by blists - more mailing lists