From: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
To: David Rientjes <rientjes@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Andrew Morton <akpm@linux-foundation.org>,
Paul Jackson <pj@sgi.com>, Christoph Lameter <clameter@sgi.com>,
Andi Kleen <ak@suse.de>,
linux-kernel@vger.kernel.org
Subject: Re: [patch 3/4] mempolicy: add MPOL_F_STATIC_NODES flag
Date: Tue, 12 Feb 2008 17:25:43 -0700 [thread overview]
Message-ID: <1202862343.4974.44.camel@localhost> (raw)
In-Reply-To: <alpine.DEB.1.00.0802111155310.17652@chino.kir.corp.google.com>
On Mon, 2008-02-11 at 11:56 -0800, David Rientjes wrote:
> On Tue, 12 Feb 2008, KOSAKI Motohiro wrote:
>
> > > @@ -218,21 +167,27 @@ static struct mempolicy *mpol_new(enum mempolicy_mode mode,
> > > return ERR_PTR(-ENOMEM);
> > > flags &= MPOL_MODE_FLAGS;
> > > atomic_set(&policy->refcnt, 1);
> > > + cpuset_update_task_memory_state();
> > > + nodes_and(cpuset_context_nmask, *nodes, cpuset_current_mems_allowed);
> > > switch (mode) {
> > > case MPOL_INTERLEAVE:
> > > - policy->v.nodes = *nodes;
> > > + if (nodes_empty(*nodes))
> > > + return ERR_PTR(-EINVAL);
> >
> > need kmem_cache_free(policy_cache, policy) before return?
> >
>
> Very good catch!
>
>
>
> mempolicy: fix policy memory leak in mpol_new()
>
> If mpol_new() cannot setup a new mempolicy because of an invalid argument
> provided by the user, avoid leaking the mempolicy that has been dynamically
> allocated.
>
> Reported by KOSAKI Motohiro.
>
> Cc: Paul Jackson <pj@sgi.com>
> Cc: Christoph Lameter <clameter@sgi.com>
> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
> Cc: Andi Kleen <ak@suse.de>
> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
> mm/mempolicy.c | 10 +++++-----
> 1 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -171,13 +171,11 @@ static struct mempolicy *mpol_new(enum mempolicy_mode mode,
> nodes_and(cpuset_context_nmask, *nodes, cpuset_current_mems_allowed);
> switch (mode) {
> case MPOL_INTERLEAVE:
> - if (nodes_empty(*nodes))
> - return ERR_PTR(-EINVAL);
> - policy->v.nodes = cpuset_context_nmask;
> - if (nodes_weight(policy->v.nodes) == 0) {
> + if (nodes_empty(*nodes) || nodes_empty(cpuset_context_nmask)) {
> kmem_cache_free(policy_cache, policy);
> return ERR_PTR(-EINVAL);
> }
> + policy->v.nodes = cpuset_context_nmask;
> break;
> case MPOL_PREFERRED:
> policy->v.preferred_node = first_node(cpuset_context_nmask);
> @@ -185,8 +183,10 @@ static struct mempolicy *mpol_new(enum mempolicy_mode mode,
> policy->v.preferred_node = -1;
> break;
> case MPOL_BIND:
> - if (nodes_empty(*nodes))
> + if (nodes_empty(*nodes)) {
> + kmem_cache_free(policy_cache, policy);
> return ERR_PTR(-EINVAL);
> + }
> policy->v.zonelist = bind_zonelist(&cpuset_context_nmask);
> if (IS_ERR(policy->v.zonelist)) {
> void *error_code = policy->v.zonelist;
With this patch, we now have 3 error paths from mpol_new that need to
free the mempolicy struct. How about consolidating them with something
like this [uncompiled/untested]:
PATCH mempolicy - consolidate mpol_new() error paths
Use common error path in mpol_new() for errors that we discover
after allocation the new mempolicy structure. Free the mempolicy
in the common error path.
Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com>
mm/mempolicy.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
Index: Linux/mm/mempolicy.c
===================================================================
--- Linux.orig/mm/mempolicy.c 2008-02-12 15:18:12.000000000 -0700
+++ Linux/mm/mempolicy.c 2008-02-12 15:22:07.000000000 -0700
@@ -156,6 +156,7 @@ static struct mempolicy *mpol_new(enum m
{
struct mempolicy *policy;
nodemask_t cpuset_context_nmask;
+ void *error_code = ERR_PTR(-EINVAL);
pr_debug("setting mode %d flags %d nodes[0] %lx\n",
mode, flags, nodes ? nodes_addr(*nodes)[0] : -1);
@@ -172,8 +173,7 @@ static struct mempolicy *mpol_new(enum m
switch (mode) {
case MPOL_INTERLEAVE:
if (nodes_empty(*nodes) || nodes_empty(cpuset_context_nmask)) {
- kmem_cache_free(policy_cache, policy);
- return ERR_PTR(-EINVAL);
+ goto free_mpol;
}
policy->v.nodes = cpuset_context_nmask;
break;
@@ -184,14 +184,12 @@ static struct mempolicy *mpol_new(enum m
break;
case MPOL_BIND:
if (nodes_empty(*nodes)) {
- kmem_cache_free(policy_cache, policy);
- return ERR_PTR(-EINVAL);
+ goto free_mpol;
}
policy->v.zonelist = bind_zonelist(&cpuset_context_nmask);
if (IS_ERR(policy->v.zonelist)) {
- void *error_code = policy->v.zonelist;
- kmem_cache_free(policy_cache, policy);
- return error_code;
+ error_code = policy->v.zonelist;
+ goto free_mpol;
}
break;
default:
@@ -201,6 +199,10 @@ static struct mempolicy *mpol_new(enum m
policy->cpuset_mems_allowed = cpuset_mems_allowed(current);
policy->user_nodemask = *nodes;
return policy;
+
+free_mpol:
+ kmem_cache_free(policy_cache, policy);
+ return error_code;
}
static void gather_stats(struct page *, void *, int pte_dirty);
next prev parent reply other threads:[~2008-02-13 0:26 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-11 15:30 [patch 1/4] mempolicy: convert MPOL constants to enum David Rientjes
2008-02-11 15:30 ` [patch 2/4] mempolicy: support optional mode flags David Rientjes
2008-02-11 15:30 ` [patch 3/4] mempolicy: add MPOL_F_STATIC_NODES flag David Rientjes
2008-02-11 15:30 ` [patch 4/4] mempolicy: update NUMA memory policy documentation David Rientjes
2008-02-11 16:10 ` Randy Dunlap
2008-02-11 20:06 ` [patch 4/4 v2] " David Rientjes
2008-02-11 20:14 ` Randy Dunlap
2008-02-11 18:25 ` [patch 3/4] mempolicy: add MPOL_F_STATIC_NODES flag KOSAKI Motohiro
2008-02-11 19:56 ` David Rientjes
2008-02-13 0:25 ` Lee Schermerhorn [this message]
2008-02-13 0:57 ` David Rientjes
2008-02-11 19:34 ` Christoph Lameter
2008-02-13 0:22 ` Lee Schermerhorn
2008-02-13 3:52 ` Paul Jackson
2008-02-13 4:03 ` David Rientjes
2008-02-13 4:13 ` Paul Jackson
2008-02-13 4:23 ` David Rientjes
2008-02-13 8:03 ` Paul Jackson
2008-02-13 9:36 ` David Rientjes
2008-02-13 16:01 ` Lee Schermerhorn
2008-02-13 18:48 ` David Rientjes
2008-02-13 18:58 ` Paul Jackson
2008-02-13 19:05 ` Lee Schermerhorn
2008-02-13 19:17 ` David Rientjes
2008-02-13 17:04 ` Paul Jackson
2008-02-13 19:02 ` David Rientjes
2008-02-13 20:29 ` Paul Jackson
2008-02-13 21:35 ` David Rientjes
2008-02-14 11:12 ` Paul Jackson
2008-02-14 12:27 ` Paul Jackson
2008-02-14 10:26 ` Paul Jackson
2008-02-14 19:45 ` David Rientjes
2008-02-15 10:19 ` Paul Jackson
2008-02-15 20:14 ` David Rientjes
2008-02-13 4:18 ` David Rientjes
2008-02-13 5:06 ` David Rientjes
2008-02-13 15:15 ` Lee Schermerhorn
2008-02-13 16:14 ` Lee Schermerhorn
2008-02-13 19:12 ` David Rientjes
2008-02-14 10:09 ` Paul Jackson
2008-02-14 19:40 ` David Rientjes
2008-02-15 1:44 ` David Rientjes
2008-02-15 10:00 ` Paul Jackson
2008-02-14 21:38 ` David Rientjes
2008-02-15 9:27 ` Paul Jackson
2008-02-15 20:23 ` David Rientjes
2008-02-15 20:32 ` David Rientjes
2008-02-15 23:45 ` Paul Jackson
2008-02-15 23:55 ` David Rientjes
2008-02-16 0:11 ` Paul Jackson
2008-02-11 16:36 ` [patch 2/4] mempolicy: support optional mode flags Lee Schermerhorn
2008-02-11 19:34 ` David Rientjes
2008-02-12 15:31 ` Lee Schermerhorn
2008-02-12 19:14 ` David Rientjes
2008-02-11 20:55 ` Paul Jackson
2008-02-11 21:52 ` David Rientjes
2008-02-11 21:57 ` Paul Jackson
2008-02-13 0:14 ` Lee Schermerhorn
2008-02-13 0:25 ` David Rientjes
2008-02-11 18:45 ` [patch 1/4] mempolicy: convert MPOL constants to enum Andi Kleen
2008-02-11 19:25 ` David Rientjes
2008-02-11 19:32 ` Christoph Lameter
2008-02-11 19:40 ` David Rientjes
2008-02-11 19:48 ` Christoph Lameter
2008-02-11 20:02 ` David Rientjes
2008-02-11 20:45 ` Christoph Lameter
2008-02-13 0:10 ` Lee Schermerhorn
2008-02-13 0:31 ` Paul Jackson
2008-02-13 0:53 ` David Rientjes
2008-02-13 1:04 ` Christoph Lameter
2008-02-13 1:28 ` Paul Jackson
2008-02-13 1:32 ` Paul Jackson
2008-02-13 2:00 ` David Rientjes
2008-02-13 2:22 ` Paul Jackson
2008-02-13 2:42 ` David Rientjes
2008-02-13 2:59 ` Paul Jackson
2008-02-13 3:17 ` David Rientjes
2008-02-13 3:22 ` Paul Jackson
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=1202862343.4974.44.camel@localhost \
--to=lee.schermerhorn@hp.com \
--cc=ak@suse.de \
--cc=akpm@linux-foundation.org \
--cc=clameter@sgi.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pj@sgi.com \
--cc=rientjes@google.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;
as well as URLs for NNTP newsgroup(s).