powerpc/pkeys: Give all threads control of their key permissions
authorRam Pai <linuxram@us.ibm.com>
Tue, 17 Jul 2018 13:51:02 +0000 (06:51 -0700)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 24 Jul 2018 11:32:33 +0000 (21:32 +1000)
commita57a04c76e06822e4377831611364c846b7202ca
tree881c198161348d30faf31ed660c7c86328fe12c8
parentdbc3f77c2fea2875e4fd64e2dee57b9a2bda38e8
powerpc/pkeys: Give all threads control of their key permissions

Currently in a multithreaded application, a key allocated by one
thread is not usable by other threads. By "not usable" we mean that
other threads are unable to change the access permissions for that
key for themselves.

When a new key is allocated in one thread, the corresponding UAMOR
bits for that thread get enabled, however the UAMOR bits for that key
for all other threads remain disabled.

Other threads have no way to set permissions on the key, and the
current default permissions are that read/write is enabled for all
keys, which means the key has no effect for other threads. Although
that may be the desired behaviour in some circumstances, having all
threads able to control their permissions for the key is more
flexible.

The current behaviour also differs from the x86 behaviour, which is
problematic for users.

To fix this, enable the UAMOR bits for all keys, at process
creation (in start_thread(), ie exec time). Since the contents of
UAMOR are inherited at fork, all threads are capable of modifying the
permissions on any key.

This is technically an ABI break on powerpc, but pkey support is fairly
new on powerpc and not widely used, and this brings us into
line with x86.

Fixes: cf43d3b26452 ("powerpc: Enable pkey subsystem")
Cc: stable@vger.kernel.org # v4.16+
Tested-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Ram Pai <linuxram@us.ibm.com>
[mpe: Reword some of the changelog]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/mm/pkeys.c