Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754305AbZCFNzV (ORCPT ); Fri, 6 Mar 2009 08:55:21 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754013AbZCFNzH (ORCPT ); Fri, 6 Mar 2009 08:55:07 -0500 Received: from e34.co.us.ibm.com ([32.97.110.152]:33264 "EHLO e34.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753435AbZCFNzF (ORCPT ); Fri, 6 Mar 2009 08:55:05 -0500 Date: Fri, 6 Mar 2009 07:54:58 -0600 From: "Serge E. Hallyn" To: Dhaval Giani Cc: lkml , Ingo Molnar , Andrew Morton , Balbir Singh , Bharata B Rao , dhowells@redhat.com Subject: Re: [PATCH] Fix a memory leak when freeing up non init usernamespaces users Message-ID: <20090306135458.GA30163@us.ibm.com> References: <20090306052319.GD4809@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090306052319.GD4809@linux.vnet.ibm.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2351 Lines: 73 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 > Signed-off-by: Dhaval Giani > Acked-by: Serge Hallyn > Tested-by: Serge Hallyn 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/