<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/security/keys, branch v2.6.32</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v2.6.32</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v2.6.32'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2009-10-15T22:19:58Z</updated>
<entry>
<title>KEYS: get_instantiation_keyring() should inc the keyring refcount in all cases</title>
<updated>2009-10-15T22:19:58Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2009-10-15T09:14:35Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=21279cfa107af07ef985539ac0de2152b9cba5f5'/>
<id>urn:sha1:21279cfa107af07ef985539ac0de2152b9cba5f5</id>
<content type='text'>
The destination keyring specified to request_key() and co. is made available to
the process that instantiates the key (the slave process started by
/sbin/request-key typically).  This is passed in the request_key_auth struct as
the dest_keyring member.

keyctl_instantiate_key and keyctl_negate_key() call get_instantiation_keyring()
to get the keyring to attach the newly constructed key to at the end of
instantiation.  This may be given a specific keyring into which a link will be
made later, or it may be asked to find the keyring passed to request_key().  In
the former case, it returns a keyring with the refcount incremented by
lookup_user_key(); in the latter case, it returns the keyring from the
request_key_auth struct - and does _not_ increment the refcount.

The latter case will eventually result in an oops when the keyring prematurely
runs out of references and gets destroyed.  The effect may take some time to
show up as the key is destroyed lazily.

To fix this, the keyring returned by get_instantiation_keyring() must always
have its refcount incremented, no matter where it comes from.

This can be tested by setting /etc/request-key.conf to:

#OP	TYPE	DESCRIPTION	CALLOUT INFO	PROGRAM ARG1 ARG2 ARG3 ...
#======	=======	===============	===============	===============================
create  *	test:*		*		|/bin/false %u %g %d %{user:_display}
negate	*	*		*		/bin/keyctl negate %k 10 @u

and then doing:

	keyctl add user _display aaaaaaaa @u
        while keyctl request2 user test:x test:x @u &amp;&amp;
        keyctl list @u;
        do
                keyctl request2 user test:x test:x @u;
                sleep 31;
                keyctl list @u;
        done

which will oops eventually.  Changing the negate line to have @u rather than
%S at the end is important as that forces the latter case by passing a special
keyring ID rather than an actual keyring ID.

Reported-by: Alexander Zangerl &lt;az@bond.edu.au&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Tested-by: Alexander Zangerl &lt;az@bond.edu.au&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Have the garbage collector set its timer for live expired keys</title>
<updated>2009-09-23T18:03:47Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2009-09-16T14:54:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=606531c316d30e9639473a6da09ee917125ab467'/>
<id>urn:sha1:606531c316d30e9639473a6da09ee917125ab467</id>
<content type='text'>
The key garbage collector sets a timer to start a new collection cycle at the
point the earliest key to expire should be considered garbage.  However, it
currently only does this if the key it is considering hasn't yet expired.

If the key being considering has expired, but hasn't yet reached the collection
time then it is ignored, and won't be collected until some other key provokes a
round of collection.

Make the garbage collector set the timer for the earliest key that hasn't yet
passed its collection time, rather than the earliest key that hasn't yet
expired.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Fix garbage collector</title>
<updated>2009-09-14T23:11:02Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2009-09-14T16:26:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=c08ef808ef24df32e25fbd949fe5310172f3c408'/>
<id>urn:sha1:c08ef808ef24df32e25fbd949fe5310172f3c408</id>
<content type='text'>
Fix a number of problems with the new key garbage collector:

 (1) A rogue semicolon in keyring_gc() was causing the initial count of dead
     keys to be miscalculated.

 (2) A missing return in keyring_gc() meant that under certain circumstances,
     the keyring semaphore would be unlocked twice.

 (3) The key serial tree iterator (key_garbage_collector()) part of the garbage
     collector has been modified to:

     (a) Complete each scan of the keyrings before setting the new timer.

     (b) Only set the new timer for keys that have yet to expire.  This means
         that the new timer is now calculated correctly, and the gc doesn't
         get into a loop continually scanning for keys that have expired, and
         preventing other things from happening, like RCU cleaning up the old
         keyring contents.

     (c) Perform an extra scan if any keys were garbage collected in this one
     	 as a key might become garbage during a scan, and (b) could mean we
     	 don't set the timer again.

 (4) Made key_schedule_gc() take the time at which to do a collection run,
     rather than the time at which the key expires.  This means the collection
     of dead keys (key type unregistered) can happen immediately.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Unlock tasklist when exiting early from keyctl_session_to_parent</title>
<updated>2009-09-14T23:10:59Z</updated>
<author>
<name>Marc Dionne</name>
<email>marc.c.dionne@gmail.com</email>
</author>
<published>2009-09-14T11:46:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5c84342a3e147a23752276650340801c237d0e56'/>
<id>urn:sha1:5c84342a3e147a23752276650340801c237d0e56</id>
<content type='text'>
When we exit early from keyctl_session_to_parent because of permissions or
because the session keyring is the same as the parent, we need to unlock the
tasklist.

The missing unlock causes the system to hang completely when using
keyctl(KEYCTL_SESSION_TO_PARENT) with a keyring shared with the parent.

Signed-off-by: Marc Dionne &lt;marc.c.dionne@gmail.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]</title>
<updated>2009-09-02T11:29:22Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2009-09-02T08:14:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ee18d64c1f632043a02e6f5ba5e045bb26a5465f'/>
<id>urn:sha1:ee18d64c1f632043a02e6f5ba5e045bb26a5465f</id>
<content type='text'>
Add a keyctl to install a process's session keyring onto its parent.  This
replaces the parent's session keyring.  Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again.  Normally this
will be after a wait*() syscall.

To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.

The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.

Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME.  This allows the
replacement to be performed at the point the parent process resumes userspace
execution.

This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership.  However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.

This can be tested with the following program:

	#include &lt;stdio.h&gt;
	#include &lt;stdlib.h&gt;
	#include &lt;keyutils.h&gt;

	#define KEYCTL_SESSION_TO_PARENT	18

	#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)

	int main(int argc, char **argv)
	{
		key_serial_t keyring, key;
		long ret;

		keyring = keyctl_join_session_keyring(argv[1]);
		OSERROR(keyring, "keyctl_join_session_keyring");

		key = add_key("user", "a", "b", 1, keyring);
		OSERROR(key, "add_key");

		ret = keyctl(KEYCTL_SESSION_TO_PARENT);
		OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");

		return 0;
	}

Compiled and linked with -lkeyutils, you should see something like:

	[dhowells@andromeda ~]$ keyctl show
	Session Keyring
	       -3 --alswrv   4043  4043  keyring: _ses
	355907932 --alswrv   4043    -1   \_ keyring: _uid.4043
	[dhowells@andromeda ~]$ /tmp/newpag
	[dhowells@andromeda ~]$ keyctl show
	Session Keyring
	       -3 --alswrv   4043  4043  keyring: _ses
	1055658746 --alswrv   4043  4043   \_ user: a
	[dhowells@andromeda ~]$ /tmp/newpag hello
	[dhowells@andromeda ~]$ keyctl show
	Session Keyring
	       -3 --alswrv   4043  4043  keyring: hello
	340417692 --alswrv   4043  4043   \_ user: a

Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Do some whitespace cleanups [try #6]</title>
<updated>2009-09-02T11:29:16Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2009-09-02T08:14:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=7b1b9164598286fe93927ff41eed2a2609fd9056'/>
<id>urn:sha1:7b1b9164598286fe93927ff41eed2a2609fd9056</id>
<content type='text'>
Do some whitespace cleanups in the key management code.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Acked-by: Serge Hallyn &lt;serue@us.ibm.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Make /proc/keys use keyid not numread as file position [try #6]</title>
<updated>2009-09-02T11:29:14Z</updated>
<author>
<name>Serge E. Hallyn</name>
<email>serue@us.ibm.com</email>
</author>
<published>2009-09-02T08:14:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ad73a717e0fc6949c44e587ca5d63c273a30e6f5'/>
<id>urn:sha1:ad73a717e0fc6949c44e587ca5d63c273a30e6f5</id>
<content type='text'>
Make the file position maintained by /proc/keys represent the ID of the key
just read rather than the number of keys read.  This should make it faster to
perform a lookup as we don't have to scan the key ID tree from the beginning to
find the current position.

Signed-off-by: Serge E. Hallyn &lt;serue@us.ibm.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Add garbage collection for dead, revoked and expired keys. [try #6]</title>
<updated>2009-09-02T11:29:11Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2009-09-02T08:14:00Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5d135440faf7db8d566de0c6fab36b16cf9cfc3b'/>
<id>urn:sha1:5d135440faf7db8d566de0c6fab36b16cf9cfc3b</id>
<content type='text'>
Add garbage collection for dead, revoked and expired keys.  This involved
erasing all links to such keys from keyrings that point to them.  At that
point, the key will be deleted in the normal manner.

Keyrings from which garbage collection occurs are shrunk and their quota
consumption reduced as appropriate.

Dead keys (for which the key type has been removed) will be garbage collected
immediately.

Revoked and expired keys will hang around for a number of seconds, as set in
/proc/sys/kernel/keys/gc_delay before being automatically removed.  The default
is 5 minutes.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Flag dead keys to induce EKEYREVOKED [try #6]</title>
<updated>2009-09-02T11:29:09Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2009-09-02T08:13:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=f041ae2f99d49adc914153a34a2d0e14e4389d90'/>
<id>urn:sha1:f041ae2f99d49adc914153a34a2d0e14e4389d90</id>
<content type='text'>
Set the KEY_FLAG_DEAD flag on keys for which the type has been removed.  This
causes the key_permission() function to return EKEYREVOKED in response to
various commands.  It does not, however, prevent unlinking or clearing of
keyrings from detaching the key.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Acked-by: Serge Hallyn &lt;serue@us.ibm.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Allow keyctl_revoke() on keys that have SETATTR but not WRITE perm [try #6]</title>
<updated>2009-09-02T11:29:06Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2009-09-02T08:13:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0c2c9a3fc77e8b60d43d9bd2ca46eb4dddb0ff76'/>
<id>urn:sha1:0c2c9a3fc77e8b60d43d9bd2ca46eb4dddb0ff76</id>
<content type='text'>
Allow keyctl_revoke() to operate on keys that have SETATTR but not WRITE
permission, rather than only on keys that have WRITE permission.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Acked-by: Serge Hallyn &lt;serue@us.ibm.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
</feed>
