From: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: Linux Containers
<containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>,
"Eric W. Biederman"
<ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
Subject: Re: [PATCH RFC] User namespaces: general cleanups
Date: Tue, 14 Oct 2008 16:43:27 -0500 [thread overview]
Message-ID: <20081014214327.GA28545@us.ibm.com> (raw)
In-Reply-To: <29703.1224006618-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Quoting David Howells (dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org):
> Serge E. Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> wrote:
>
> > Hmm, with this patch, with CONFIG_KEYS=y users in child user_namespaces
> > never get freed. Ones in the init_user_ns do, and with CONFIG_KEYS=n,
> > those in child user_namespaces do as well.
> >
> > I don't see anything obvious in copy_creds() that would cause this...
>
> Try looking in lookup_user_key(). Also, can you try the attached patch?
That patch seems to fix it! Also seemed fine under ltp.
> I've also attached a better version of your debugging patch, one that
> differentiates between allocated and reused user_structs.
>
> David
> ---
> From: David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>
> CRED: Fix creds refcounting in lookup_user_key()
>
> Make lookup_user_key() drop at all return points the reference to the current
> creds that it took at the top of the function
>
> Signed-off-by: David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Tested-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
> ---
>
> security/keys/process_keys.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
>
> diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
> index e40f61d..2d6076d 100644
> --- a/security/keys/process_keys.c
> +++ b/security/keys/process_keys.c
> @@ -667,6 +667,7 @@ try_again:
> goto invalid_key;
>
> error:
> + put_cred(cred);
> return key_ref;
>
> invalid_key:
>
> ---
> >From e00a2d98dd1086b0c863d8b416df33280c7c2574 Mon Sep 17 00:00:00 2001
> From: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
> Date: Mon, 13 Oct 2008 16:36:05 -0500
> Subject: [PATCH 1/1] creds: print user_struct refcounts
>
> print user_struct refcounts at alloc, and print msg at uid free.
Yup, except you've tossed the user namespace refcounting checks :)
(But that's ok, we all know user namespaces are bug-free.)
Anyway, will you push the refcounting fix to James? Then I'll
resend the user namespaces patch merged with your patch (if you
don't mind) plus the clearing of groups and keyrings for a new
user-namespace tomorrow.
thanks,
-serge
> Signed-off-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> ---
>
> kernel/user.c | 12 +++++++++++-
> 1 files changed, 11 insertions(+), 1 deletions(-)
>
>
> diff --git a/kernel/user.c b/kernel/user.c
> index d476307..073296e 100644
> --- a/kernel/user.c
> +++ b/kernel/user.c
> @@ -317,6 +317,7 @@ done:
> static inline void free_user(struct user_struct *up, unsigned long flags)
> {
> /* restore back the count */
> + printk(KERN_NOTICE "%s: freeing a uid (%d)\n", __func__, up->uid);
> atomic_inc(&up->__count);
> spin_unlock_irqrestore(&uidhash_lock, flags);
>
> @@ -337,6 +338,7 @@ static inline void uids_mutex_unlock(void) { }
> */
> static inline void free_user(struct user_struct *up, unsigned long flags)
> {
> + printk(KERN_NOTICE "%s: freeing a uid (%d)\n", __func__, up->uid);
> uid_hash_remove(up);
> spin_unlock_irqrestore(&uidhash_lock, flags);
> sched_destroy_user(up);
> @@ -422,16 +424,24 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
> key_put(new->uid_keyring);
> key_put(new->session_keyring);
> kmem_cache_free(uid_cachep, new);
> + printk(KERN_NOTICE "%s: reuse a uid (%d) (cnt %u)\n",
> + __func__, uid, atomic_read(&up->__count));
> +
> } else {
> uid_hash_insert(new, hashent);
> up = new;
> + printk(KERN_NOTICE "%s: alloced a uid (%d) (cnt %u)\n",
> + __func__, uid, atomic_read(&up->__count));
> +
> }
> spin_unlock_irq(&uidhash_lock);
>
> + } else {
> + printk(KERN_NOTICE "%s: reuse a uid (%d) (cnt %u)\n",
> + __func__, uid, atomic_read(&up->__count));
> }
>
> uids_mutex_unlock();
> -
> return up;
>
> out_destoy_sched:
next prev parent reply other threads:[~2008-10-14 21:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-10 1:19 [PATCH RFC] User namespaces: general cleanups Serge E. Hallyn
[not found] ` <20081010011917.GA8046-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-10-10 10:06 ` David Howells
[not found] ` <30854.1223633214-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-10-10 17:06 ` Serge E. Hallyn
2008-10-13 16:01 ` Serge E. Hallyn
[not found] ` <20081013214108.GA4701-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-10-13 23:10 ` David Howells
[not found] ` <5306.1223939456-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-10-14 14:33 ` Serge E. Hallyn
[not found] ` <20081013160144.GA10359-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-10-13 21:41 ` Serge E. Hallyn
2008-10-14 17:50 ` David Howells
[not found] ` <29703.1224006618-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-10-14 21:43 ` Serge E. Hallyn [this message]
[not found] ` <20081014214327.GA28545-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-10-14 21:47 ` David Howells
2008-10-10 12:58 ` Keys and namespaces David Howells
[not found] ` <414.1223643503-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-10-10 16:46 ` Serge E. Hallyn
2008-10-10 22:30 ` Eric W. Biederman
[not found] ` <m1hc7k13s2.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-10-13 16:27 ` Serge E. Hallyn
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=20081014214327.GA28545@us.ibm.com \
--to=serue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
--cc=dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.