Skip to contentSkip to conversation

ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE

PATCH In review Takashi Iwai 3 participants 4 messages Nov 18, 2021 – Nov 19, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE

When CONFIG_FORTIFY_SOURCE is set, memcpy() checks the potential buffer overflow and panics. The code in sofcpga bootstrapping contains the memcpy() calls are mistakenly translated as the shorter size, hence it triggers a panic as if it were overflowing.

This patch changes the secondary_trampoline and *_end definitions to arrays for avoiding the false-positive crash above.

---

v1->v2: Use arrays for trampoline area instead of hackish workaround
with __NO_FORTIFY

 arch/arm/mach-socfpga/core.h    | 2 +-
 arch/arm/mach-socfpga/platsmp.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/arm/mach-socfpga/core.h +1 -1
index fc2608b18a0d..18f01190dcfd 100644
@@ -33,7 +33,7 @@ extern void __iomem *sdr_ctl_base_addr;
 u32 socfpga_sdram_self_refresh(u32 sdr_base);
 extern unsigned int socfpga_sdram_self_refresh_sz;
 
-extern char secondary_trampoline, secondary_trampoline_end;
+extern char secondary_trampoline[], secondary_trampoline_end[];
 
 extern unsigned long socfpga_cpu1start_addr;
 
arch/arm/mach-socfpga/platsmp.c +4 -4
index fbb80b883e5d..201191cf68f3 100644
@@ -20,14 +20,14 @@
 
 static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
 {
-	int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
+	int trampoline_size = secondary_trampoline_end - secondary_trampoline;
 
 	if (socfpga_cpu1start_addr) {
 		/* This will put CPU #1 into reset. */
 		writel(RSTMGR_MPUMODRST_CPU1,
 		       rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST);
 
-		memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
+		memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
 
 		writel(__pa_symbol(secondary_startup),
 		       sys_manager_base_addr + (socfpga_cpu1start_addr & 0x000000ff));
@@ -45,12 +45,12 @@ static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
 
 static int socfpga_a10_boot_secondary(unsigned int cpu, struct task_struct *idle)
 {
-	int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
+	int trampoline_size = secondary_trampoline_end - secondary_trampoline;
 
 	if (socfpga_cpu1start_addr) {
 		writel(RSTMGR_MPUMODRST_CPU1, rst_manager_base_addr +
 		       SOCFPGA_A10_RSTMGR_MODMPURST);
-		memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
+		memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
 
 		writel(__pa_symbol(secondary_startup),
 		       sys_manager_base_addr + (socfpga_cpu1start_addr & 0x00000fff));
Signature · 1 line
2.26.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Takashi Iwai

When CONFIG_FORTIFY_SOURCE is set, memcpy() checks the potential buffer overflow and panics. The code in sofcpga bootstrapping contains the memcpy() calls are mistakenly translated as the shorter size, hence it triggers a panic as if it were overflowing.

Quoted 7 lines

This patch changes the secondary_trampoline and *_end definitions to arrays for avoiding the false-positive crash above.

Thanks!

Signature · 1 line
Kees Cook
maintainer
#2 lore raw
In reply to Takashi Iwai

Hi Iwai,

Should this have the following tag:

Fixes 9c4566a117a6 ("ARM: socfpga: Enable SMP for socfpga")

As well?

Quoted 71 lines · Takashi Iwai

When CONFIG_FORTIFY_SOURCE is set, memcpy() checks the potential buffer overflow and panics. The code in sofcpga bootstrapping contains the memcpy() calls are mistakenly translated as the shorter size, hence it triggers a panic as if it were overflowing.

This patch changes the secondary_trampoline and *_end definitions to arrays for avoiding the false-positive crash above.

---

v1->v2: Use arrays for trampoline area instead of hackish workaround
with __NO_FORTIFY

  arch/arm/mach-socfpga/core.h    | 2 +-
  arch/arm/mach-socfpga/platsmp.c | 8 ++++----
  2 files changed, 5 insertions(+), 5 deletions(-)
arch/arm/mach-socfpga/core.h +1 -1
index fc2608b18a0d..18f01190dcfd 100644
@@ -33,7 +33,7 @@ extern void __iomem *sdr_ctl_base_addr;
  u32 socfpga_sdram_self_refresh(u32 sdr_base);
  extern unsigned int socfpga_sdram_self_refresh_sz;
 
-extern char secondary_trampoline, secondary_trampoline_end;
+extern char secondary_trampoline[], secondary_trampoline_end[];
 
  extern unsigned long socfpga_cpu1start_addr;
 
arch/arm/mach-socfpga/platsmp.c +4 -4
index fbb80b883e5d..201191cf68f3 100644
@@ -20,14 +20,14 @@
 
  static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
  {
-	int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
+	int trampoline_size = secondary_trampoline_end - secondary_trampoline;
 
  	if (socfpga_cpu1start_addr) {
  		/* This will put CPU #1 into reset. */
  		writel(RSTMGR_MPUMODRST_CPU1,
  		       rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST);
 
-		memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
+		memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
 
  		writel(__pa_symbol(secondary_startup),
  		       sys_manager_base_addr + (socfpga_cpu1start_addr & 0x000000ff));
@@ -45,12 +45,12 @@ static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
 
  static int socfpga_a10_boot_secondary(unsigned int cpu, struct task_struct *idle)
  {
-	int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
+	int trampoline_size = secondary_trampoline_end - secondary_trampoline;
 
  	if (socfpga_cpu1start_addr) {
  		writel(RSTMGR_MPUMODRST_CPU1, rst_manager_base_addr +
  		       SOCFPGA_A10_RSTMGR_MODMPURST);
-		memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
+		memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
 
  		writel(__pa_symbol(secondary_startup),
  		       sys_manager_base_addr + (socfpga_cpu1start_addr & 0x00000fff));
#3 lore raw
Quoted 8 lines · Dinh Nguyen

Hi Iwai,

Should this have the following tag:

Fixes 9c4566a117a6 ("ARM: socfpga: Enable SMP for socfpga")

As well?

Yes, that'd be helpful, too.

thanks,

Takashi

Quoted 68 lines · Takashi Iwai
Quoted 65 lines

When CONFIG_FORTIFY_SOURCE is set, memcpy() checks the potential buffer overflow and panics. The code in sofcpga bootstrapping contains the memcpy() calls are mistakenly translated as the shorter size, hence it triggers a panic as if it were overflowing.

This patch changes the secondary_trampoline and *_end definitions to arrays for avoiding the false-positive crash above.

---

v1->v2: Use arrays for trampoline area instead of hackish workaround
with __NO_FORTIFY

  arch/arm/mach-socfpga/core.h    | 2 +-
  arch/arm/mach-socfpga/platsmp.c | 8 ++++----
  2 files changed, 5 insertions(+), 5 deletions(-)
arch/arm/mach-socfpga/core.h +1 -0
index fc2608b18a0d..18f01190dcfd 100644
@@ -33,7 +33,7 @@ extern void __iomem *sdr_ctl_base_addr;
  u32 socfpga_sdram_self_refresh(u32 sdr_base);
  extern unsigned int socfpga_sdram_self_refresh_sz;
  -extern char secondary_trampoline, secondary_trampoline_end;
+extern char secondary_trampoline[], secondary_trampoline_end[];
    extern unsigned long socfpga_cpu1start_addr;
  diff --git a/arch/arm/mach-socfpga/platsmp.c

b/arch/arm/mach-socfpga/platsmp.c
index fbb80b883e5d..201191cf68f3 100644

arch/arm/mach-socfpga/platsmp.c +4 -3
@@ -20,14 +20,14 @@
    static int socfpga_boot_secondary(unsigned int cpu, struct
 task_struct *idle)
  {
-	int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
+	int trampoline_size = secondary_trampoline_end - secondary_trampoline;
    	if (socfpga_cpu1start_addr) {
  		/* This will put CPU #1 into reset. */
  		writel(RSTMGR_MPUMODRST_CPU1,
  		       rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST);
  -		memcpy(phys_to_virt(0), &secondary_trampoline,
 trampoline_size);
+		memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
    		writel(__pa_symbol(secondary_startup),
  		       sys_manager_base_addr + (socfpga_cpu1start_addr & 0x000000ff));
@@ -45,12 +45,12 @@ static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
    static int socfpga_a10_boot_secondary(unsigned int cpu, struct
 task_struct *idle)
  {
-	int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
+	int trampoline_size = secondary_trampoline_end - secondary_trampoline;
    	if (socfpga_cpu1start_addr) {
  		writel(RSTMGR_MPUMODRST_CPU1, rst_manager_base_addr +
  		       SOCFPGA_A10_RSTMGR_MODMPURST);
-		memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
+		memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
    		writel(__pa_symbol(secondary_startup),
  		       sys_manager_base_addr + (socfpga_cpu1start_addr & 0x00000fff));