Skip to content

Commit 5769055

Browse files
andyhhpsuryasaimadhu
authored andcommitted
x86/pkey: Fix undefined behaviour with PKRU_WD_BIT
Both __pkru_allows_write() and arch_set_user_pkey_access() shift PKRU_WD_BIT (a signed constant) by up to 30 bits, hitting the sign bit. Use unsigned constants instead. Clearly pkey 15 has not been used in combination with UBSAN yet. Noticed by code inspection only. I can't actually provoke the compiler into generating incorrect logic as far as this shift is concerned. [ dhansen: add stable@ tag, plus minor changelog massaging, For anyone doing backports, these #defines were in arch/x86/include/asm/pgtable.h before 784a466. ] Fixes: 33a709b ("mm/gup, x86/mm/pkeys: Check VMAs and PTEs for protection keys") Signed-off-by: Andrew Cooper <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 2f5b351 commit 5769055

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/include/asm/pkru.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#include <asm/cpufeature.h>
66

7-
#define PKRU_AD_BIT 0x1
8-
#define PKRU_WD_BIT 0x2
7+
#define PKRU_AD_BIT 0x1u
8+
#define PKRU_WD_BIT 0x2u
99
#define PKRU_BITS_PER_PKEY 2
1010

1111
#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS

0 commit comments

Comments
 (0)