From: Michal Hocko <mhocko@suse.com>
To: 锦江屠 <tujinjiang@bytedance.com>
Cc: Yang Shi <shy828301@gmail.com>,
akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [External] Re: [PATCH] vmscan: fix potential arbitrary pointer passed to kfree in unregister_shrinker
Date: Thu, 28 Jul 2022 09:34:36 +0200 [thread overview]
Message-ID: <YuI8DPnRBeqd87QB@dhcp22.suse.cz> (raw)
In-Reply-To: <CAF77dw_D5ZD74Sy9UBmQjxNO8ShHzBdVAgRKHv-z-4RKdO=C3g@mail.gmail.com>
On Thu 28-07-22 10:37:26, 锦江屠 wrote:
> On Wed, Jul 27, 2022 at 11:50 PM Yang Shi <shy828301@gmail.com> wrote:
> >
> > On Wed, Jul 27, 2022 at 7:43 AM Michal Hocko <mhocko@suse.com> wrote:
> > >
> > > [Cc Yang Shi]
> >
> > Thanks, Michal.
> >
> > > On Wed 27-07-22 17:07:00, tujinjiang@bytedance.com wrote:
> > > > 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.
> > >
> > > Is this a real life problem? I thought shrinkers were pre-zeroed
> > > already. Not that we should be relying on that but it would be good to
> > > mention whether this is a code fortification or something that we should
> > > be really worried about.
> >
> > Yes, all memcg aware shrinkers are actually pre-zeroed. The fs
> > shrinkers (embedded in super_block) are allocated by kzalloc, all
> > other shrinkers are static declared. So I don't think it will cause
> > any crash in real life.
> >
>
> Yes, the shrinkers in the current kernel will not cause crash, but a new
> memcg aware shrinker may be added in the future, and I think we
> should not assume the shrinker is pre-zeroed.
Agreed. Especially when that is not documented anywhere.
> Function free_prealloced_shrinker does not assume the shrinker is pre-zeroed,
> and does not call kfree(shrinker->nr_deferred) if the shrinker is memcg aware.
> So I think it is better for unregister_shrinker to call kfree only
> when the shrinker
> is not memcg aware.
It would be really great to mention this intention in the changelog.
Your initial wording might make an impression this is a fix for an
existing problem.
> > > > To fix it, this patch initialize shrinker->nr_deferred at the
> > > > beginning of prealloc_shrinker.
> > >
> > > It would be great to add
> > > Fixes: 476b30a0949a ("mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers")
Do not use Fixes tag as this is not a real problem currently.
--
Michal Hocko
SUSE Labs
prev parent reply other threads:[~2022-07-28 7:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-27 9:07 tujinjiang
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 [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=YuI8DPnRBeqd87QB@dhcp22.suse.cz \
--to=mhocko@suse.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shy828301@gmail.com \
--cc=tujinjiang@bytedance.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