[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHbLzkpu91gEDzep76iRT+yFxLFaTf4fn3=bmP-fs-UP4i3NEg@mail.gmail.com>
Date: Wed, 27 Jul 2022 08:50:16 -0700
From: Yang Shi <shy828301@...il.com>
To: Michal Hocko <mhocko@...e.com>
Cc: tujinjiang@...edance.com, akpm@...ux-foundation.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] vmscan: fix potential arbitrary pointer passed to kfree
in unregister_shrinker
On Wed, Jul 27, 2022 at 7:43 AM Michal Hocko <mhocko@...e.com> wrote:
>
> [Cc Yang Shi]
Thanks, Michal.
> On Wed 27-07-22 17:07:00, tujinjiang@...edance.com wrote:
> > From: Jinjiang Tu <tujinjiang@...edance.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.
>
> > 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")
>
> > Signed-off-by: Jinjiang Tu <tujinjiang@...edance.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)
>
> You should be able to move it under SHRINKER_MEMCG_AWARE branch, no?
>
> --
> Michal Hocko
> SUSE Labs
Powered by blists - more mailing lists