From: Andrew Morton <akpm@linux-foundation.org>
To: David Howells <dhowells@redhat.com>
Cc: torvalds@linux-foundation.org, kwc@citi.umich.edu,
arunsr@cse.iitk.ac.in, dwalsh@redhat.com,
linux-security-module@vger.kernel.org, dhowells@redhat.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] KEYS: Don't generate user and user session keyrings unless they're accessed
Date: Thu, 13 Mar 2008 15:20:59 -0700 [thread overview]
Message-ID: <20080313152059.90681241.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080313191437.28959.4396.stgit@warthog.procyon.org.uk>
On Thu, 13 Mar 2008 19:14:37 +0000
David Howells <dhowells@redhat.com> wrote:
> Don't generate the per-UID user and user session keyrings unless they're
> explicitly accessed. This solves a problem during a login process whereby
> set*uid() is called before the SELinux PAM module, resulting in the per-UID
> keyrings having the wrong security labels.
>
> This also cures the problem of multiple per-UID keyrings sometimes appearing
> due to PAM modules (including pam_keyinit) setuiding and causing user_structs
> to come into and go out of existence whilst the session keyring pins the user
> keyring. This is achieved by first searching for extant per-UID keyrings before
> inventing new ones.
>
> The serial bound argument is also dropped from find_keyring_by_name() as it's
> not currently made use of (setting it to 0 disables the feature).
>
> ..
>
> -/* Initial keyrings */
> -extern struct key root_user_keyring;
> -extern struct key root_session_keyring;
hm, I didn't realise that the keys code had special knowlege of "root".
How does that play alongside the containers stuff?
> --- a/kernel/user.c
> +++ b/kernel/user.c
> ...
> +#ifdef CONFIG_KEYS
> + new->uid_keyring = new->session_keyring = NULL;
> +#endif
new->uid_keyring = NULL;
new->session_keyring = NULL;
would be more conventional.
But better would be to teach alloc_uid() about kmem_cache_zalloc() then
take a chainsaw to it.
It's sorely tempting to say that initialising an atomic_t with memset(0) is
OK. Heck, if it ever becomes not OK then we're screwed anwyay, because
vast tracts of code assumes that atomic_set(uninitalised_atomic, 0) works
OK.
I'll queue this up:
From: Andrew Morton <akpm@linux-foundation.org>
Use kmem_cache_zalloc(), remove large amounts of initialsiation code and
ifdeffery.
Note: this assumes that memset(*atomic_t, 0) correctly initialises the
atomic_t. This is true for all present archtiectures and if it becomes false
for a future architecture then we'll need to make large changes all over the
place anyway.
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
kernel/user.c | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff -puN kernel/user.c~alloc_uid-cleanup kernel/user.c
--- a/kernel/user.c~alloc_uid-cleanup
+++ a/kernel/user.c
@@ -356,7 +356,7 @@ void free_uid(struct user_struct *up)
local_irq_restore(flags);
}
-struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
+struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
{
struct hlist_head *hashent = uidhashentry(ns, uid);
struct user_struct *up, *new;
@@ -371,26 +371,12 @@ struct user_struct * alloc_uid(struct us
spin_unlock_irq(&uidhash_lock);
if (!up) {
- new = kmem_cache_alloc(uid_cachep, GFP_KERNEL);
+ new = kmem_cache_zalloc(uid_cachep, GFP_KERNEL);
if (!new)
goto out_unlock;
new->uid = uid;
atomic_set(&new->__count, 1);
- atomic_set(&new->processes, 0);
- atomic_set(&new->files, 0);
- atomic_set(&new->sigpending, 0);
-#ifdef CONFIG_INOTIFY_USER
- atomic_set(&new->inotify_watches, 0);
- atomic_set(&new->inotify_devs, 0);
-#endif
-#ifdef CONFIG_POSIX_MQUEUE
- new->mq_bytes = 0;
-#endif
- new->locked_shm = 0;
-#ifdef CONFIG_KEYS
- new->uid_keyring = new->session_keyring = NULL;
-#endif
if (sched_create_user(new) < 0)
goto out_free_user;
_
next prev parent reply other threads:[~2008-03-13 22:22 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-13 19:14 [PATCH 1/3] KEYS: Allow clients to set key perms in key_create_or_update() David Howells
2008-03-13 19:14 ` [PATCH 2/3] KEYS: Don't generate user and user session keyrings unless they're accessed David Howells
2008-03-13 22:20 ` Andrew Morton [this message]
2008-03-14 2:30 ` David Howells
2008-03-13 19:14 ` [PATCH 3/3] KEYS: Make the keyring quotas controllable through /proc/sys David Howells
2008-03-13 22:28 ` Andrew Morton
2008-03-14 2:39 ` David Howells
2008-03-14 11:46 ` David Howells
2008-03-13 22:47 ` Andrew Morton
2008-03-14 2:30 ` David Howells
2008-03-19 0:04 ` Andrew Morton
2008-03-19 11:19 ` David Howells
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=20080313152059.90681241.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=arunsr@cse.iitk.ac.in \
--cc=dhowells@redhat.com \
--cc=dwalsh@redhat.com \
--cc=kwc@citi.umich.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=torvalds@linux-foundation.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.