[lkml]   [2021]   [Dec]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 4.14 18/29] x86/pkey: Fix undefined behaviour with PKRU_WD_BIT
From: Andrew Cooper <>

commit 57690554abe135fee81d6ac33cc94d75a7e224bb upstream.

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

dhansen: add stable@ tag, plus minor changelog massaging,

For anyone doing backports, these #defines were in
arch/x86/include/asm/pgtable.h before 784a46618f6.

Fixes: 33a709b25a76 ("mm/gup, x86/mm/pkeys: Check VMAs and PTEs for protection keys")
Signed-off-by: Andrew Cooper <>
Signed-off-by: Dave Hansen <>
Signed-off-by: Borislav Petkov <>
Signed-off-by: Greg Kroah-Hartman <>
arch/x86/include/asm/pgtable.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1220,8 +1220,8 @@ static inline pmd_t pmd_swp_clear_soft_d

-#define PKRU_AD_BIT 0x1
-#define PKRU_WD_BIT 0x2
+#define PKRU_AD_BIT 0x1u
+#define PKRU_WD_BIT 0x2u

static inline bool __pkru_allows_read(u32 pkru, u16 pkey)

 \ /
  Last update: 2021-12-27 16:39    [W:0.125 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site