[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALvZod5E649XyBC+NLkHTJJWWoWh+Uuhegw=4_4MQGxok5VpXw@mail.gmail.com>
Date: Thu, 30 Mar 2023 12:55:22 -0700
From: Shakeel Butt <shakeelb@...gle.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
linux-kernel@...r.kernel.org,
Marek Szyprowski <m.szyprowski@...sung.com>,
linux-mm@...ck.org, stable@...r.kernel.org
Subject: Re: [PATCH 1/1] mm: Fix memory leak on mm_init error handling
On Thu, Mar 30, 2023 at 12:42 PM Andrew Morton
<akpm@...ux-foundation.org> wrote:
>
> On Thu, 30 Mar 2023 09:38:22 -0400 Mathieu Desnoyers <mathieu.desnoyers@...icios.com> wrote:
>
> > commit f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter")
> > introduces a memory leak by missing a call to destroy_context() when a
> > percpu_counter fails to allocate.
> >
> > Before introducing the per-cpu counter allocations, init_new_context()
> > was the last call that could fail in mm_init(), and thus there was no
> > need to ever invoke destroy_context() in the error paths. Adding the
> > following percpu counter allocations adds error paths after
> > init_new_context(), which means its associated destroy_context() needs
> > to be called when percpu counters fail to allocate.
> >
> > ...
> >
> > --- a/kernel/fork.c
> > +++ b/kernel/fork.c
> > @@ -1171,6 +1171,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
> > fail_pcpu:
> > while (i > 0)
> > percpu_counter_destroy(&mm->rss_stat[--i]);
> > + destroy_context(mm);
> > fail_nocontext:
> > mm_free_pgd(mm);
> > fail_nopgd:
>
> Is there really a leak? I wasn't able to find a version of
> init_new_context() which performs allocation.
>
There are more than 20 archs defining this function and I couldn't
check each one of them. I think we can assume there might be new
allocation in the future.
Powered by blists - more mailing lists