linux/arch/sh/kernel
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
..
cpu sh: sh7724 ddr self-refresh changes 2009-08-15 12:58:50 +09:00
vsyscall [S390] arch_setup_additional_pages arguments 2008-12-25 13:38:54 +01:00
.gitignore sh: Add an arch/sh/kernel/.gitignore 2008-07-29 08:29:32 +09:00
asm-offsets.c sh: hibernation support 2009-03-10 12:55:40 +09:00
cpufreq.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6 2007-10-13 09:49:04 -07:00
crash_dump.c kdump: make elfcorehdr_addr independent of CONFIG_PROC_VMCORE 2008-10-20 08:52:39 -07:00
debugtraps.S sh: Generic kgdb stub support. 2008-12-22 18:44:04 +09:00
disassemble.c sh: Add a simple code dumper for SUPERH32 show_regs(). 2008-12-22 18:43:49 +09:00
early_printk.c serial: sh-sci: Reorder the SCxTDR write after the TDxE clear. 2008-11-13 17:46:06 +09:00
entry-common.S sh: Generic kgdb stub support. 2008-12-22 18:44:04 +09:00
ftrace.c sh: Fix dynamic ftrace's NOP action. 2009-06-11 19:00:58 +01:00
gpio.c sh: use gpiolib 2009-01-27 14:49:10 +09:00
head_32.S sh: convert to use __HEAD and HEAD_TEXT macros. 2009-04-26 09:20:39 -07:00
head_64.S sh: convert to use __HEAD and HEAD_TEXT macros. 2009-04-26 09:20:39 -07:00
idle.c sh: Provide cpu_idle_wait() to fix up cpuidle/SMP build. 2009-06-23 17:30:17 +09:00
init_task.c mm: consolidate init_mm definition 2009-06-16 19:47:28 -07:00
io_generic.c sh: More I/O routine overhauling. 2008-10-04 05:25:52 +09:00
io_trapped.c sh: Rename opcode_t to insn_size_t. 2009-05-09 16:02:08 +09:00
io.c sh: pci: Consolidate pci_iomap() and use the generic I/O base. 2009-04-20 16:38:00 +09:00
irq.c sh: irq: Provide an arch_probe_nr_irqs() that wraps the machvec def. 2009-05-22 01:36:13 +09:00
kgdb.c sh: Rename opcode_t to insn_size_t. 2009-05-09 16:02:08 +09:00
kprobes.c sh: kprobes: kretprobe_trampoline needs to be global. 2008-09-09 08:13:28 +09:00
localtimer.c sh: Move dummy clockevents broadcast timer to its new home. 2009-05-03 18:29:27 +09:00
machine_kexec.c sh: disallow kexec virtual entry 2009-03-20 18:56:04 +09:00
machvec.c sh: boot word / mode pin support V2 2009-06-01 15:44:49 +09:00
Makefile sh: Have 32-bit use arch/sh/kernel/Makefile_32. 2008-01-28 13:18:41 +09:00
Makefile_32 sh: Kill off the remnants of the old timer code. 2009-05-12 19:53:55 +09:00
Makefile_64 sh: Kill off the remnants of the old timer code. 2009-05-12 19:53:55 +09:00
module.c module: cleanup FIXME comments about trimming exception table entries. 2009-06-12 21:47:05 +09:30
process_32.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6 2009-06-18 14:07:35 -07:00
process_64.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6 2009-06-18 14:07:35 -07:00
ptrace_32.c sh: Add ptrace support for NOMMU debugging 2009-05-09 00:11:27 +09:00
ptrace_64.c sh: Provide linux/regset.h interface for SH-5. 2008-12-22 18:44:04 +09:00
relocate_kernel.S sh: add kexec jump support 2009-03-18 18:57:43 +09:00
setup.c sh: rework mode pin code 2009-06-11 09:08:53 +03:00
sh_bios.c sh: Kill off sh_bios_in_gdb_mode(). 2008-12-22 18:44:44 +09:00
sh_ksyms_32.c sh: irq: Convert from irq_desc[] to irq_to_desc(). 2009-05-22 01:26:16 +09:00
sh_ksyms_64.c sh: Convert sh64 to use the generic checksum code. 2009-06-15 00:00:42 +09:00
signal_32.c KEYS: Add a keyctl to install a process's session keyring on its parent [try #6] 2009-09-02 21:29:22 +10:00
signal_64.c KEYS: Add a keyctl to install a process's session keyring on its parent [try #6] 2009-09-02 21:29:22 +10:00
smp.c cpumask: Use accessors for cpu_*_mask: sh 2009-06-14 18:24:16 +09:00
stacktrace.c sh: latencytop support. 2008-09-13 01:44:03 +09:00
swsusp.c sh: hibernation support 2009-03-10 12:55:40 +09:00
sys_sh32.c [CVE-2009-0029] Remove __attribute__((weak)) from sys_pipe/sys_pipe2 2009-01-14 14:15:15 +01:00
sys_sh64.c unified (weak) sys_pipe implementation 2008-05-03 13:50:33 -07:00
sys_sh.c sh: remove stray markers. 2009-06-18 13:38:26 +09:00
syscalls_32.S sh: Wire up sys_perf_counter_open. 2009-06-12 01:33:22 +03:00
syscalls_64.S sh: Wire up sys_perf_counter_open. 2009-06-12 01:33:22 +03:00
time.c sh: Bump the earlytimer probe devices up. 2009-06-14 20:02:30 +09:00
topology.c sh: replace remaining __FUNCTION__ occurrences 2008-03-06 11:18:22 +09:00
traps_32.c sh: Rename opcode_t to insn_size_t. 2009-05-09 16:02:08 +09:00
traps_64.c sh: Always fixup unaligned userspace accesses on sh64. 2009-05-08 20:32:56 +09:00
traps.c sh: unbreak WARN_ON() 2009-06-17 15:39:52 +09:00
vmlinux.lds.S sh: include empty_zero_page in text 2009-05-11 18:42:14 +09:00