linux/security/keys
David Howells 3ecf1b4f34 KEYS: keyctl_get_keyring_ID() should create a session keyring if create flag set
The keyctl call:

	keyctl_get_keyring_ID(KEY_SPEC_SESSION_KEYRING, 1)

should create a session keyring if the process doesn't have one of its own
because the create flag argument is set - rather than subscribing to and
returning the user-session keyring as:

	keyctl_get_keyring_ID(KEY_SPEC_SESSION_KEYRING, 0)

will do.

This can be tested by commenting out pam_keyinit in the /etc/pam.d files and
running the following program a couple of times in a row:

	#include <stdio.h>
	#include <stdlib.h>
	#include <keyutils.h>
	int main(int argc, char *argv[])
	{
		key_serial_t uk, usk, sk, nsk;
		uk  = keyctl_get_keyring_ID(KEY_SPEC_USER_KEYRING, 0);
		usk = keyctl_get_keyring_ID(KEY_SPEC_USER_SESSION_KEYRING, 0);
		sk  = keyctl_get_keyring_ID(KEY_SPEC_SESSION_KEYRING, 0);
		nsk = keyctl_get_keyring_ID(KEY_SPEC_SESSION_KEYRING, 1);
		printf("keys: %08x %08x %08x %08x\n", uk, usk, sk, nsk);
		return 0;
	}

Without this patch, I see:

	keys: 3975ddc7 119c0c66 119c0c66 119c0c66
	keys: 3975ddc7 119c0c66 119c0c66 119c0c66

With this patch, I see:

	keys: 2cb4997b 34112878 34112878 17db2ce3
	keys: 2cb4997b 34112878 34112878 39f3c73e

As can be seen, the session keyring starts off the same as the user-session
keyring each time, but with the patch a new session keyring is created when
the create flag is set.

Reported-by: Greg Wettstein <greg@enjellic.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Tested-by: Greg Wettstein <greg@enjellic.com>
Signed-off-by: James Morris <jmorris@namei.org>
2011-08-23 09:57:34 +10:00
..
Makefile encrypted-keys: add ecryptfs format support 2011-06-27 09:11:17 -04:00
compat.c KEYS: Add an iovec version of KEYCTL_INSTANTIATE 2011-03-08 11:17:22 +11:00
ecryptfs_format.c encrypted-keys: add ecryptfs format support 2011-06-27 09:11:17 -04:00
ecryptfs_format.h encrypted-keys: add ecryptfs format support 2011-06-27 09:11:17 -04:00
encrypted.c encrypted-keys: add ecryptfs format support 2011-06-27 09:11:17 -04:00
encrypted.h encrypted-keys: rename encrypted_defined files to encrypted 2011-01-24 10:27:57 +11:00
gc.c KEYS: Fix up comments in key management code 2011-01-21 14:59:30 -08:00
internal.h KEYS: Improve /proc/keys 2011-03-17 11:59:32 +11:00
key.c KEYS: Add a new keyctl op to reject a key with a specified error code 2011-03-08 11:17:18 +11:00
keyctl.c KEYS: Make request_key() and co. return an error for a negative key 2011-03-17 11:59:49 +11:00
keyring.c rcu: treewide: Do not use rcu_read_lock_held when calling rcu_dereference_check 2011-07-08 22:21:58 +02:00
permission.c KEYS: Fix up comments in key management code 2011-01-21 14:59:30 -08:00
proc.c KEYS: Improve /proc/keys 2011-03-17 11:59:32 +11:00
process_keys.c KEYS: keyctl_get_keyring_ID() should create a session keyring if create flag set 2011-08-23 09:57:34 +10:00
request_key.c KEYS: Fix error handling in construct_key_and_link() 2011-06-21 18:31:45 -07:00
request_key_auth.c KEYS: Don't return EAGAIN to keyctl_assume_authority() 2011-06-14 15:03:29 +10:00
sysctl.c sysctl: Drop & in front of every proc_handler. 2009-11-18 08:37:40 -08:00
trusted.c Create Documentation/security/, 2011-05-19 15:59:38 -07:00
trusted.h trusted-keys: rename trusted_defined files to trusted 2011-01-24 10:14:22 +11:00
user_defined.c Merge branch 'next' into for-linus 2011-05-24 22:55:24 +10:00