x86/pkey: Fix undefined behaviour with PKRU_WD_BIT
Subsystems (2)
PATCH 1/1 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.
---
CC: Thomas Gleixner <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: Dave Hansen <[email protected]>
CC: [email protected]
CC: "H. Peter Anvin" <[email protected]>
Noticed by code inspection only. I can't actually provoke the compiler into generating incorrect logic as far as this shift is concerned, so haven't included a fixes tag.
If wanted, it is:
except it will collide with the very recent code movement in 784a46618f634.
--- arch/x86/include/asm/pkru.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/pkru.h +2 -2
@@ -4,8 +4,8 @@#include <asm/cpufeature.h> -#define PKRU_AD_BIT 0x1 -#define PKRU_WD_BIT 0x2 +#define PKRU_AD_BIT 0x1u +#define PKRU_WD_BIT 0x2u#define PKRU_BITS_PER_PKEY 2#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
Signature · 1 line
2.11.0
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 7aa3e3011ef3e0a9c36417eafca7894a028e5df6 Gitweb: https://git.kernel.org/tip/7aa3e3011ef3e0a9c36417eafca7894a028e5df6 Author: Andrew Cooper <[email protected]> AuthorDate: Thu, 16 Dec 2021 00:08:56 Committer: Dave Hansen <[email protected]> CommitterDate: Thu, 16 Dec 2021 09:39:40 -08:00
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, so haven't included a fixes tag.
[
dhansen: add stable@ tag, plus minor changelog massaging,
For anyone doing backports, these #defines were in arch/x86/include/asm/pgtable.h before 784a46618f6.
]
--- arch/x86/include/asm/pkru.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/pkru.h +2 -2
@@ -4,8 +4,8 @@#include <asm/cpufeature.h> -#define PKRU_AD_BIT 0x1 -#define PKRU_WD_BIT 0x2 +#define PKRU_AD_BIT 0x1u +#define PKRU_WD_BIT 0x2u#define PKRU_BITS_PER_PKEY 2#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: e9836ee0043ebd02ba1d049cf8b9e6daa30ad2cd Gitweb: https://git.kernel.org/tip/e9836ee0043ebd02ba1d049cf8b9e6daa30ad2cd Author: Andrew Cooper <[email protected]> AuthorDate: Thu, 16 Dec 2021 00:08:56 Committer: Dave Hansen <[email protected]> CommitterDate: Thu, 16 Dec 2021 11:55:51 -08:00
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 784a46618f6.
]
--- arch/x86/include/asm/pkru.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/pkru.h +2 -2
@@ -4,8 +4,8 @@#include <asm/cpufeature.h> -#define PKRU_AD_BIT 0x1 -#define PKRU_WD_BIT 0x2 +#define PKRU_AD_BIT 0x1u +#define PKRU_WD_BIT 0x2u#define PKRU_BITS_PER_PKEY 2#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: aa1701e20a847dba6c406545dcba6a8755fa6406 Gitweb: https://git.kernel.org/tip/aa1701e20a847dba6c406545dcba6a8755fa6406 Author: Andrew Cooper <[email protected]> AuthorDate: Thu, 16 Dec 2021 00:08:56 Committer: Borislav Petkov <[email protected]> CommitterDate: Sun, 19 Dec 2021 14:09:41 +01:00
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 784a46618f6.
]
--- arch/x86/include/asm/pkru.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/pkru.h +2 -2
@@ -4,8 +4,8 @@#include <asm/cpufeature.h> -#define PKRU_AD_BIT 0x1 -#define PKRU_WD_BIT 0x2 +#define PKRU_AD_BIT 0x1u +#define PKRU_WD_BIT 0x2u#define PKRU_BITS_PER_PKEY 2#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 57690554abe135fee81d6ac33cc94d75a7e224bb Gitweb: https://git.kernel.org/tip/57690554abe135fee81d6ac33cc94d75a7e224bb Author: Andrew Cooper <[email protected]> AuthorDate: Thu, 16 Dec 2021 00:08:56 Committer: Borislav Petkov <[email protected]> CommitterDate: Sun, 19 Dec 2021 22:44:34 +01:00
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 784a46618f6.
]
--- arch/x86/include/asm/pkru.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/pkru.h +2 -2
@@ -4,8 +4,8 @@#include <asm/cpufeature.h> -#define PKRU_AD_BIT 0x1 -#define PKRU_WD_BIT 0x2 +#define PKRU_AD_BIT 0x1u +#define PKRU_WD_BIT 0x2u#define PKRU_BITS_PER_PKEY 2#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS