[PATCH] loongarch: stackprotector: Use get_random_canary() for stack canary init

Luo Qiu posted 1 patch 2 months, 1 week ago
arch/loongarch/include/asm/stackprotector.h | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
[PATCH] loongarch: stackprotector: Use get_random_canary() for stack canary init
Posted by Luo Qiu 2 months, 1 week ago
Replace the custom stack canary initialization with the
get_random_canary() helper, following the pattern established in commit
622754e84b10 ("stackprotector: actually use get_random_canary()").

Signed-off-by: Luo Qiu <luoqiu@kylinsec.com.cn>
---
 arch/loongarch/include/asm/stackprotector.h | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/loongarch/include/asm/stackprotector.h b/arch/loongarch/include/asm/stackprotector.h
index a1a965751a7b..42f6c3f69115 100644
--- a/arch/loongarch/include/asm/stackprotector.h
+++ b/arch/loongarch/include/asm/stackprotector.h
@@ -12,9 +12,6 @@
 #ifndef _ASM_STACKPROTECTOR_H
 #define _ASM_STACKPROTECTOR_H
 
-#include <linux/random.h>
-#include <linux/version.h>
-
 extern unsigned long __stack_chk_guard;
 
 /*
@@ -25,11 +22,7 @@ extern unsigned long __stack_chk_guard;
  */
 static __always_inline void boot_init_stack_canary(void)
 {
-	unsigned long canary;
-
-	/* Try to get a semi random initial value. */
-	get_random_bytes(&canary, sizeof(canary));
-	canary ^= LINUX_VERSION_CODE;
+	unsigned long canary = get_random_canary();
 
 	current->stack_canary = canary;
 	__stack_chk_guard = current->stack_canary;
-- 
2.53.0
Re: [PATCH] loongarch: stackprotector: Use get_random_canary() for stack canary init
Posted by Huacai Chen 2 months ago
Applied, thanks.

Huacai

On Thu, Apr 9, 2026 at 3:35 PM Luo Qiu <luoqiu@kylinsec.com.cn> wrote:
>
> Replace the custom stack canary initialization with the
> get_random_canary() helper, following the pattern established in commit
> 622754e84b10 ("stackprotector: actually use get_random_canary()").
>
> Signed-off-by: Luo Qiu <luoqiu@kylinsec.com.cn>
> ---
>  arch/loongarch/include/asm/stackprotector.h | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/arch/loongarch/include/asm/stackprotector.h b/arch/loongarch/include/asm/stackprotector.h
> index a1a965751a7b..42f6c3f69115 100644
> --- a/arch/loongarch/include/asm/stackprotector.h
> +++ b/arch/loongarch/include/asm/stackprotector.h
> @@ -12,9 +12,6 @@
>  #ifndef _ASM_STACKPROTECTOR_H
>  #define _ASM_STACKPROTECTOR_H
>
> -#include <linux/random.h>
> -#include <linux/version.h>
> -
>  extern unsigned long __stack_chk_guard;
>
>  /*
> @@ -25,11 +22,7 @@ extern unsigned long __stack_chk_guard;
>   */
>  static __always_inline void boot_init_stack_canary(void)
>  {
> -       unsigned long canary;
> -
> -       /* Try to get a semi random initial value. */
> -       get_random_bytes(&canary, sizeof(canary));
> -       canary ^= LINUX_VERSION_CODE;
> +       unsigned long canary = get_random_canary();
>
>         current->stack_canary = canary;
>         __stack_chk_guard = current->stack_canary;
> --
> 2.53.0
>