arm64: ptr auth: Use get_random_u64 instead of _bytes
PATCH v2 1/1 arm64: ptr auth: Use get_random_u64 instead of _bytes
get_random_bytes() is approximately 4x the cost of two get_random_u64() calls, because the former implements anti-backtracking.
Because these are authentication keys, useless to an attacker as soon as the kernel stops using them, there is no security benefit from anti-backtracking.
---
v2: Took out all the clever bitmap-based stuff and made a simple
boring helper function to replace get_random_bytes(&key, 16).
arch/arm64/include/asm/pointer_auth.h | 16 +++++++++++----- arch/arm64/kernel/pointer_auth.c | 10 +++++----- 2 files changed, 16 insertions(+), 10 deletions(-)
arch/arm64/include/asm/pointer_auth.h +11 -5
@@ -30,17 +30,23 @@ struct ptrauth_keys {struct ptrauth_key apga; }; +static inline void __ptrauth_key_init (struct ptrauth_key *key) +{ + key->lo =get_random_u64 (); + key->hi =get_random_u64 (); +} +static inline void ptrauth_keys_init (struct ptrauth_keys *keys) {if (system_supports_address_auth ()) { -get_random_bytes (&keys->apia,sizeof (keys->apia)); -get_random_bytes (&keys->apib,sizeof (keys->apib)); -get_random_bytes (&keys->apda,sizeof (keys->apda)); -get_random_bytes (&keys->apdb,sizeof (keys->apdb)); +__ptrauth_key_init (&keys->apia); +__ptrauth_key_init (&keys->apib); +__ptrauth_key_init (&keys->apda); +__ptrauth_key_init (&keys->apdb); }if (system_supports_generic_auth ()) -get_random_bytes (&keys->apga,sizeof (keys->apga)); +__ptrauth_key_init (&keys->apga); }#define __ptrauth_key_install (k, v) \
arch/arm64/kernel/pointer_auth.c +5 -5
@@ -31,15 +31,15 @@ int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg)return -EINVAL ;if (arg &PR_PAC_APIAKEY ) -get_random_bytes (&keys->apia,sizeof (keys->apia)); +__ptrauth_key_init (&keys->apia);if (arg &PR_PAC_APIBKEY ) -get_random_bytes (&keys->apib,sizeof (keys->apib)); +__ptrauth_key_init (&keys->apib);if (arg &PR_PAC_APDAKEY ) -get_random_bytes (&keys->apda,sizeof (keys->apda)); +__ptrauth_key_init (&keys->apda);if (arg &PR_PAC_APDBKEY ) -get_random_bytes (&keys->apdb,sizeof (keys->apdb)); +__ptrauth_key_init (&keys->apdb);if (arg &PR_PAC_APGAKEY ) -get_random_bytes (&keys->apga,sizeof (keys->apga)); +__ptrauth_key_init (&keys->apga);ptrauth_keys_switch (keys);
Signature · 6 lines
2.26.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
This seems to have been sent twice, so I'm replying to the latest copy.
Quoted 8 lines · George Spelvin
get_random_bytes()is approximately 4x the cost of twoget_random_u64()calls, because the former implements anti-backtracking.Because these are authentication keys, useless to an attacker as soon as the kernel stops using them, there is no security benefit from anti-backtracking.
Quoted 5 lines
Signed-off-by George Spelvin <[email protected]>Cc Mark Rutland <[email protected]>Cc Will Deacon <[email protected]>Cc Catalin Marinas <[email protected]>
Given my understanding from discussion on the prior version the conversion is sound, it doesn't matter that we expose the keys via ptrace, and the code looks nicer, so:
I assume Will or Catalin will pick this up when they next pick up patches.
Mark.
Quoted 68 lines
---
v2: Took out all the clever bitmap-based stuff and made a simple
boring helper function to replaceget_random_bytes(&key, 16).arch/arm64/include/asm/pointer_auth.h | 16 +++++++++++----- arch/arm64/kernel/pointer_auth.c | 10 +++++----- 2 files changed, 16 insertions(+), 10 deletions(-)arch/arm64/include/asm/pointer_auth.h +11
-5@@ -30,17 +30,23 @@ struct ptrauth_keys {struct ptrauth_key apga; }; +static inline void __ptrauth_key_init (struct ptrauth_key *key) +{ + key->lo =get_random_u64 (); + key->hi =get_random_u64 (); +} +static inline void ptrauth_keys_init (struct ptrauth_keys *keys) {if (system_supports_address_auth ()) { -get_random_bytes (&keys->apia,sizeof (keys->apia)); -get_random_bytes (&keys->apib,sizeof (keys->apib)); -get_random_bytes (&keys->apda,sizeof (keys->apda)); -get_random_bytes (&keys->apdb,sizeof (keys->apdb)); +__ptrauth_key_init (&keys->apia); +__ptrauth_key_init (&keys->apib); +__ptrauth_key_init (&keys->apda); +__ptrauth_key_init (&keys->apdb); }if (system_supports_generic_auth ()) -get_random_bytes (&keys->apga,sizeof (keys->apga)); +__ptrauth_key_init (&keys->apga); }#define __ptrauth_key_install (k, v) \arch/arm64/kernel/pointer_auth.c +5
-5@@ -31,15 +31,15 @@ int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg)return -EINVAL ;if (arg &PR_PAC_APIAKEY ) -get_random_bytes (&keys->apia,sizeof (keys->apia)); +__ptrauth_key_init (&keys->apia);if (arg &PR_PAC_APIBKEY ) -get_random_bytes (&keys->apib,sizeof (keys->apib)); +__ptrauth_key_init (&keys->apib);if (arg &PR_PAC_APDAKEY ) -get_random_bytes (&keys->apda,sizeof (keys->apda)); +__ptrauth_key_init (&keys->apda);if (arg &PR_PAC_APDBKEY ) -get_random_bytes (&keys->apdb,sizeof (keys->apdb)); +__ptrauth_key_init (&keys->apdb);if (arg &PR_PAC_APGAKEY ) -get_random_bytes (&keys->apga,sizeof (keys->apga)); +__ptrauth_key_init (&keys->apga);ptrauth_keys_switch (keys);Signature · 1 line
2.26.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerHi George,
Quoted 13 lines · George Spelvin
get_random_bytes()is approximately 4x the cost of twoget_random_u64()calls, because the former implements anti-backtracking.Because these are authentication keys, useless to an attacker as soon as the kernel stops using them, there is no security benefit from anti-backtracking.
Signed-off-by George Spelvin <[email protected]>Cc Mark Rutland <[email protected]>Cc Will Deacon <[email protected]>Cc Catalin Marinas <[email protected]>
Quoted 7 lines
---
v2: Took out all the clever bitmap-based stuff and made a simple
boring helper function to replaceget_random_bytes(&key, 16).arch/arm64/include/asm/pointer_auth.h | 16 +++++++++++----- arch/arm64/kernel/pointer_auth.c | 10 +++++----- 2 files changed, 16 insertions(+), 10 deletions(-)
Please can you resend this against the arm64 for-next/ptr-auth branch [1]? I can't apply it as-is.
Thanks,
Will
[1] https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/ptr-auth
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerQuoted 18 lines · Will Deacon
Quoted 17 lines · George Spelvin
get_random_bytes()is approximately 4x the cost of twoget_random_u64()calls, because the former implements anti-backtracking.Because these are authentication keys, useless to an attacker as soon as the kernel stops using them, there is no security benefit from anti-backtracking.
Signed-off-by George Spelvin <[email protected]>Cc Mark Rutland <[email protected]>Cc Will Deacon <[email protected]>Cc Catalin Marinas <[email protected]>---
v2: Took out all the clever bitmap-based stuff and made a simple
boring helper function to replaceget_random_bytes(&key, 16).
Quoted 6 lines
Quoted 3 lines
arch/arm64/include/asm/pointer_auth.h | 16 +++++++++++----- arch/arm64/kernel/pointer_auth.c | 10 +++++----- 2 files changed, 16 insertions(+), 10 deletions(-)Please can you resend this against the arm64 for-next/ptr-auth branch [1]? I can't apply it as-is.
Any update on this one?
Cheers,
Will
Quoted 1 line
[1] https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/ptr-auth
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel