x86/pkeys: Add check for pkey "overflow"
authorDave Hansen <dave.hansen@linux.intel.com>
Wed, 22 Jan 2020 16:53:46 +0000 (08:53 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Oct 2020 18:40:08 +0000 (20:40 +0200)
commit33b2fd5fcb0afa50f69eecb93b025c3520e02db8
tree36a7f775bb92984348dc2ea3e1d578cc6a625a90
parent9ee952c3301e9099723ca08992a718f053b4a07f
x86/pkeys: Add check for pkey "overflow"

[ Upstream commit 16171bffc829272d5e6014bad48f680cb50943d9 ]

Alex Shi reported the pkey macros above arch_set_user_pkey_access()
to be unused.  They are unused, and even refer to a nonexistent
CONFIG option.

But, they might have served a good use, which was to ensure that
the code does not try to set values that would not fit in the
PKRU register.  As it stands, a too-large 'pkey' value would
be likely to silently overflow the u32 new_pkru_bits.

Add a check to look for overflows.  Also add a comment to remind
any future developer to closely examine the types used to store
pkey values if arch_max_pkey() ever changes.

This boots and passes the x86 pkey selftests.

Reported-by: Alex Shi <alex.shi@linux.alibaba.com>
Signed-off-by: Dave Hansen <dave.hansen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200122165346.AD4DA150@viggo.jf.intel.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/include/asm/pkeys.h
arch/x86/kernel/fpu/xstate.c