android_kernel_xiaomi_sm8350/arch/parisc/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
..
.gitignore parisc: add arch/parisc/kernel/.gitignore 2008-10-10 16:32:28 +00:00
asm-offsets.c parisc: move pdc_result to real2.S 2008-10-10 16:32:28 +00:00
binfmt_elf32.c [PATCH] remove unused ibcs2/PER_SVR4 in SET_PERSONALITY 2008-10-16 15:40:05 +02:00
cache.c parisc: ensure broadcast tlb purge runs single threaded 2009-07-03 03:34:09 +00:00
drivers.c parisc: add uevent helper for parisc bus 2009-01-05 19:11:59 +00:00
entry.S KEYS: Extend TIF_NOTIFY_RESUME to (almost) all architectures [try #6] 2009-09-02 21:29:19 +10:00
firmware.c parisc: expose 32/64-bit capabilities in cpuinfo 2009-03-31 02:51:33 +00:00
ftrace.c parisc: add ftrace (function and graph tracer) functionality 2009-03-31 02:51:34 +00:00
hardware.c [PARISC] add back Crestone Peak cpu 2008-03-15 19:12:19 -07:00
head.S parisc: hijack jump to start_kernel 2008-10-10 16:32:30 +00:00
hpmc.S parisc: export length of os_hpmc vector 2009-01-05 19:18:27 +00:00
init_task.c mm: consolidate init_mm definition 2009-06-16 19:47:28 -07:00
inventory.c parisc: inventory.c, fix bloated stack frame 2009-07-03 03:34:11 +00:00
irq.c parisc: remove obsolete hw_interrupt_type 2009-07-03 03:34:08 +00:00
Makefile parisc: add ftrace (function and graph tracer) functionality 2009-03-31 02:51:34 +00:00
module.c parisc: Fix GOT overflow during module load on 64bit kernel 2009-08-02 12:34:08 +02:00
pa7300lc.c
pacache.S Revert "parisc: fix trivial section name warnings" 2008-06-13 10:49:45 -04:00
parisc_ksyms.c parisc: add ftrace (function and graph tracer) functionality 2009-03-31 02:51:34 +00:00
pci-dma.c parisc: ensure broadcast tlb purge runs single threaded 2009-07-03 03:34:09 +00:00
pci.c parisc: remove CVS keywords 2009-07-03 03:34:06 +00:00
pdc_chassis.c
pdc_cons.c parisc: Use DEFINE_SPINLOCK 2009-01-05 19:13:18 +00:00
perf_asm.S Revert "parisc: fix trivial section name warnings" 2008-06-13 10:49:45 -04:00
perf_images.h
perf.c parisc: Replace NR_CPUS in parisc code 2009-01-05 19:09:02 +00:00
process.c Remove multiple KERN_ prefixes from printk formats 2009-07-08 10:30:03 -07:00
processor.c parisc: processor.c, fix bloated stack frame 2009-07-03 03:34:11 +00:00
ptrace.c parisc: fix bug in compat_arch_ptrace 2008-11-20 13:09:17 -08:00
real2.S parisc: move pdc_result to real2.S 2008-10-10 16:32:28 +00:00
setup.c parisc: remove CVS keywords 2009-07-03 03:34:06 +00:00
signal32.c parisc: fix off by one in setup_sigcontext32 2008-06-13 10:49:55 -04:00
signal32.h
signal.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 Merge branch 'rusty-cpumask-parisc' into parisc 2009-04-02 01:43:14 +00:00
stacktrace.c parisc: add LATENCYTOP_SUPPORT and CONFIG_STACKTRACE_SUPPORT 2009-03-31 02:51:34 +00:00
sys32.h
sys_parisc32.c parisc: remove dead code from sys_parisc32.c 2009-07-03 03:34:10 +00:00
sys_parisc.c unified (weak) sys_pipe implementation 2008-05-03 13:50:33 -07:00
syscall_table.S parisc: perf: wire up sys_perf_counter_open 2009-07-03 03:34:12 +00:00
syscall.S parisc: document light weight syscall ABI 2009-03-31 02:51:35 +00:00
time.c parisc: fix "delay!" timer handling 2009-07-03 03:34:09 +00:00
topology.c parisc: Replace NR_CPUS in parisc code 2009-01-05 19:09:02 +00:00
traps.c Remove multiple KERN_ prefixes from printk formats 2009-07-08 10:30:03 -07:00
unaligned.c arch/parisc/kernel/unaligned.c: use time_* macros 2008-05-15 10:38:54 -04:00
unwind.c parisc: fix GFP_KERNEL use while atomic in unwinder 2009-01-05 18:15:25 +00:00
vmlinux.lds.S parisc: add ftrace (function and graph tracer) functionality 2009-03-31 02:51:34 +00:00