From: "Serge E. Hallyn" <serue@us.ibm.com>
To: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Cc: lkml <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Balbir Singh <balbir@in.ibm.com>,
Bharata B Rao <bharata@linux.vnet.ibm.com>,
dhowells@redhat.com
Subject: Re: [PATCH] Fix a memory leak when freeing up non init usernamespaces users
Date: Fri, 6 Mar 2009 07:54:58 -0600 [thread overview]
Message-ID: <20090306135458.GA30163@us.ibm.com> (raw)
In-Reply-To: <20090306052319.GD4809@linux.vnet.ibm.com>
Quoting Dhaval Giani (dhaval@linux.vnet.ibm.com):
>
> Fix a memory leak when freeing up non init usernamespaces users
>
> We were returning early in the sysfs directory cleanup function
> if the user belonged to a non init usernamespace. Due to this a lot
> of the cleanup was not done and we were left with a leak. Fix the leak.
>
> Reported-by: Serge Hallyn <serue@linux.vnet.ibm.com>
> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
> Acked-by: Serge Hallyn <serue@us.ibm.com>
> Tested-by: Serge Hallyn <serue@us.ibm.com>
Thanks, Dhaval.
-serge
> ---
> kernel/user.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> Index: linux-2.6/kernel/user.c
> ===================================================================
> --- linux-2.6.orig/kernel/user.c
> +++ linux-2.6/kernel/user.c
> @@ -286,14 +286,12 @@ int __init uids_sysfs_init(void)
> /* work function to remove sysfs directory for a user and free up
> * corresponding structures.
> */
> -static void remove_user_sysfs_dir(struct work_struct *w)
> +static void cleanup_user_struct(struct work_struct *w)
> {
> struct user_struct *up = container_of(w, struct user_struct, work);
> unsigned long flags;
> int remove_user = 0;
>
> - if (up->user_ns != &init_user_ns)
> - return;
> /* Make uid_hash_remove() + sysfs_remove_file() + kobject_del()
> * atomic.
> */
> @@ -312,9 +310,11 @@ static void remove_user_sysfs_dir(struct
> if (!remove_user)
> goto done;
>
> - kobject_uevent(&up->kobj, KOBJ_REMOVE);
> - kobject_del(&up->kobj);
> - kobject_put(&up->kobj);
> + if (up->user_ns == &init_user_ns) {
> + kobject_uevent(&up->kobj, KOBJ_REMOVE);
> + kobject_del(&up->kobj);
> + kobject_put(&up->kobj);
> + }
>
> sched_destroy_user(up);
> key_put(up->uid_keyring);
> @@ -335,7 +335,7 @@ static void free_user(struct user_struct
> atomic_inc(&up->__count);
> spin_unlock_irqrestore(&uidhash_lock, flags);
>
> - INIT_WORK(&up->work, remove_user_sysfs_dir);
> + INIT_WORK(&up->work, cleanup_user_struct);
> schedule_work(&up->work);
> }
>
> --
> regards,
> Dhaval
prev parent reply other threads:[~2009-03-06 13:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-06 5:23 [PATCH] Fix a memory leak when freeing up non init usernamespaces users Dhaval Giani
2009-03-06 13:54 ` Serge E. Hallyn [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=20090306135458.GA30163@us.ibm.com \
--to=serue@us.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@in.ibm.com \
--cc=bharata@linux.vnet.ibm.com \
--cc=dhaval@linux.vnet.ibm.com \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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