linux/arch/mips
David Howells ee18d64c1f KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
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 <stdio.h>
	#include <stdlib.h>
	#include <keyutils.h>

	#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 <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 21:29:22 +10:00
..
alchemy MIPS: MTX-1: Request button GPIO before setting its direction 2009-08-03 17:52:46 +01:00
ar7 MIPS: AR7: Override CFLAGS with -Werror 2009-08-03 17:52:46 +01:00
basler/excite platform driver: fix incorrect use of 'platform_bus_type' with 'struct device_driver' 2009-03-24 16:38:25 -07:00
bcm47xx MIPS: WGT634U: Add reset button support 2008-10-15 12:46:51 +01:00
boot [MIPS] checkfiles: Fix "need space after that ','" errors. 2007-10-11 23:46:15 +01:00
cavium-octeon MIPS: Octeon: Run IPI code with interrupts disabled. 2009-08-03 17:52:47 +01:00
cobalt Update Yoichi Yuasa's e-mail address 2009-07-03 15:45:29 +01:00
configs MIPS: Add support for Texas Instruments AR7 System-on-a-Chip 2009-07-03 15:45:23 +01:00
dec MIPS: Eleminate filenames from comments 2009-08-03 17:52:40 +01:00
emma MIPS: Eleminate filenames from comments 2009-08-03 17:52:40 +01:00
fw MIPS: Eleminate filenames from comments 2009-08-03 17:52:40 +01:00
gt64120/wrppmc Update Yoichi Yuasa's e-mail address 2009-07-03 15:45:29 +01:00
include/asm KEYS: Extend TIF_NOTIFY_RESUME to (almost) all architectures [try #6] 2009-09-02 21:29:19 +10:00
jazz MIPS: Jazz: Fix read buffer overflow 2009-08-03 17:52:47 +01:00
kernel KEYS: Add a keyctl to install a process's session keyring on its parent [try #6] 2009-09-02 21:29:22 +10:00
lasat cpumask: remove references to struct irqaction's mask field. 2009-03-30 22:05:14 +10:30
lemote/lm2e cpumask: remove references to struct irqaction's mask field. 2009-03-30 22:05:14 +10:30
lib MIPS: Fix __ndelay build error and add 'ull' suffix for 32-bit kernel 2009-06-17 11:06:24 +01:00
math-emu MIPS: Switch FPU emulator trap to BREAK instruction. 2008-10-30 14:44:34 +00:00
mipssim MIPS: MIPSsim: Fix unbalance brace in mipssim get_c0_compare_int() 2009-08-03 17:52:41 +01:00
mm MIPS: Drop mmap_sem in pagefault oom path 2009-08-03 17:52:40 +01:00
mti-malta [PATCH] MIPS: SMTC: Fix compile error 2009-08-03 17:52:41 +01:00
nxp MIPS: Use DIV_ROUND_CLOSEST 2009-08-03 17:52:46 +01:00
oprofile oprofile: more whitespace fixes 2008-10-15 20:55:51 +02:00
pci MIPS: Octeon PCIe: Make hardware and software bus numbers match. 2009-08-03 17:52:44 +01:00
pmc-sierra MIPS: Simplify and correct interrupt handling for MSP4200 2009-08-03 17:52:43 +01:00
power MIPS: Hibernation: Remove SMP TLB and cacheflushing code. 2009-06-24 18:34:39 +01:00
rb532 MIPS: RB532: Check irq number when handling GPIO interrupts 2009-06-17 11:06:27 +01:00
sgi-ip22 MIPS: IP22: Fix hang in power button interrupt handler 2009-05-20 18:53:13 +01:00
sgi-ip27 MIPS: Build fix - include <linux/smp.h> into all smp_processor_id() users. 2009-06-24 18:34:39 +01:00
sgi-ip32 MIPS: IP32: Remove unnecessary if not even harmful volatile keywords. 2009-05-22 13:52:06 +01:00
sibyte MIPS: Eleminate filenames from comments 2009-08-03 17:52:40 +01:00
sni MIPS: Build fix - include <linux/smp.h> into all smp_processor_id() users. 2009-06-24 18:34:39 +01:00
txx9 MIPS: RBTX4939: Fix IOC pin-enable register updating 2009-08-03 17:52:44 +01:00
vr41xx Update Yoichi Yuasa's e-mail address 2009-07-03 15:45:29 +01:00
Kconfig MIPS: Allow suspend and hibernation again on uniprocessor kernels. 2009-07-03 15:45:28 +01:00
Kconfig.debug MIPS: Kconfig: Fix the arch-specific header path 2008-12-12 18:12:23 +00:00
Makefile MIPS: Add support for Texas Instruments AR7 System-on-a-Chip 2009-07-03 15:45:23 +01:00