Browse Source

lib: prevent coldboot_lottery from overflowing

HSM_STOP will trigger multiple executions of sbi_init, atomic_add_return may
trigger coldboot_lottery overflow

Signed-off-by: Xiang Wang <merle@hardenedlinux.org>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Xiang Wang 4 years ago
parent
commit
4d93586bfa
1 changed files with 1 additions and 1 deletions
  1. 1 1
      lib/sbi/sbi_init.c

+ 1 - 1
lib/sbi/sbi_init.c

@@ -285,7 +285,7 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)
 	    sbi_platform_hart_invalid(plat, hartid))
 		sbi_hart_hang();
 
-	if (atomic_add_return(&coldboot_lottery, 1) == 1)
+	if (arch_atomic_xchg(&coldboot_lottery, 1) == 0)
 		coldboot = TRUE;
 
 	if (coldboot)