From: tujinjiang@bytedance.com
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Jinjiang Tu <tujinjiang@bytedance.com>
Subject: [PATCH] vmscan: fix potential arbitrary pointer passed to kfree in unregister_shrinker
Date: Wed, 27 Jul 2022 17:07:00 +0800 [thread overview]
Message-ID: <20220727090700.3238-1-tujinjiang@bytedance.com> (raw)
From: Jinjiang Tu <tujinjiang@bytedance.com>
when shrinker is registered with SHRINKER_MEMCG_AWARE flag,
register_shrinker will not initialize shrinker->nr_deferred,
but the pointer will be passed to kfree in unregister_shrinker
when the shrinker is unregistered. This leads to kernel crash
when the shrinker object is dynamically allocated.
To fix it, this patch initialize shrinker->nr_deferred at the
beginning of prealloc_shrinker.
Signed-off-by: Jinjiang Tu <tujinjiang@bytedance.com>
---
mm/vmscan.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index f7d9a683e3a7..06ab5a398971 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -613,6 +613,7 @@ int prealloc_shrinker(struct shrinker *shrinker)
unsigned int size;
int err;
+ shrinker->nr_deferred = NULL;
if (shrinker->flags & SHRINKER_MEMCG_AWARE) {
err = prealloc_memcg_shrinker(shrinker);
if (err != -ENOSYS)
--
2.17.1
next reply other threads:[~2022-07-27 9:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-27 9:07 tujinjiang [this message]
2022-07-27 14:43 ` Michal Hocko
2022-07-27 15:50 ` Yang Shi
2022-07-28 2:37 ` [External] " 锦江屠
2022-07-28 7:34 ` Michal Hocko
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=20220727090700.3238-1-tujinjiang@bytedance.com \
--to=tujinjiang@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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