linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE
@ 2021-11-18 14:25 Takashi Iwai
  2021-11-18 17:20 ` Kees Cook
  2021-11-18 22:08 ` Dinh Nguyen
  0 siblings, 2 replies; 4+ messages in thread
From: Takashi Iwai @ 2021-11-18 14:25 UTC (permalink / raw)
  To: Dinh Nguyen; +Cc: Kees Cook, Ivan T . Ivanov, linux-arm-kernel, linux-kernel

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.

Suggested-by: Kees Cook <keescook@chromium.org>
Buglink: https://bugzilla.suse.com/show_bug.cgi?id=1192473
Link: https://lore.kernel.org/r/20211117193244.31162-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---

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(-)

diff --git a/arch/arm/mach-socfpga/core.h b/arch/arm/mach-socfpga/core.h
index fc2608b18a0d..18f01190dcfd 100644
--- a/arch/arm/mach-socfpga/core.h
+++ b/arch/arm/mach-socfpga/core.h
@@ -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
--- a/arch/arm/mach-socfpga/platsmp.c
+++ b/arch/arm/mach-socfpga/platsmp.c
@@ -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));
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE
  2021-11-18 14:25 [PATCH v2] ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE Takashi Iwai
@ 2021-11-18 17:20 ` Kees Cook
  2021-11-18 22:08 ` Dinh Nguyen
  1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2021-11-18 17:20 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Dinh Nguyen, Ivan T . Ivanov, linux-arm-kernel, linux-kernel

On Thu, Nov 18, 2021 at 03:25:08PM +0100, Takashi Iwai wrote:
> 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.
> 
> Suggested-by: Kees Cook <keescook@chromium.org>
> Buglink: https://bugzilla.suse.com/show_bug.cgi?id=1192473
> Link: https://lore.kernel.org/r/20211117193244.31162-1-tiwai@suse.de
> Signed-off-by: Takashi Iwai <tiwai@suse.de>

Reviewed-by: Kees Cook <keescook@chromium.org>

Thanks!

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE
  2021-11-18 14:25 [PATCH v2] ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE Takashi Iwai
  2021-11-18 17:20 ` Kees Cook
@ 2021-11-18 22:08 ` Dinh Nguyen
  2021-11-19 13:37   ` Takashi Iwai
  1 sibling, 1 reply; 4+ messages in thread
From: Dinh Nguyen @ 2021-11-18 22:08 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Kees Cook, Ivan T . Ivanov, linux-arm-kernel, linux-kernel

Hi Iwai,

Should this have the following tag:

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

As well?

On 11/18/21 8:25 AM, Takashi Iwai wrote:
> 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.
> 
> Suggested-by: Kees Cook <keescook@chromium.org>
> Buglink: https://bugzilla.suse.com/show_bug.cgi?id=1192473
> Link: https://lore.kernel.org/r/20211117193244.31162-1-tiwai@suse.de
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> 
> 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(-)
> 
> diff --git a/arch/arm/mach-socfpga/core.h b/arch/arm/mach-socfpga/core.h
> index fc2608b18a0d..18f01190dcfd 100644
> --- a/arch/arm/mach-socfpga/core.h
> +++ b/arch/arm/mach-socfpga/core.h
> @@ -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
> --- a/arch/arm/mach-socfpga/platsmp.c
> +++ b/arch/arm/mach-socfpga/platsmp.c
> @@ -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));
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE
  2021-11-18 22:08 ` Dinh Nguyen
@ 2021-11-19 13:37   ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2021-11-19 13:37 UTC (permalink / raw)
  To: Dinh Nguyen
  Cc: Takashi Iwai, Kees Cook, Ivan T . Ivanov, linux-arm-kernel, linux-kernel

On Thu, 18 Nov 2021 23:08:27 +0100,
Dinh Nguyen wrote:
> 
> 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

> 
> On 11/18/21 8:25 AM, Takashi Iwai wrote:
> > 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.
> >
> > Suggested-by: Kees Cook <keescook@chromium.org>
> > Buglink: https://bugzilla.suse.com/show_bug.cgi?id=1192473
> > Link: https://lore.kernel.org/r/20211117193244.31162-1-tiwai@suse.de
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >
> > 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(-)
> >
> > diff --git a/arch/arm/mach-socfpga/core.h b/arch/arm/mach-socfpga/core.h
> > index fc2608b18a0d..18f01190dcfd 100644
> > --- a/arch/arm/mach-socfpga/core.h
> > +++ b/arch/arm/mach-socfpga/core.h
> > @@ -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
> > --- a/arch/arm/mach-socfpga/platsmp.c
> > +++ b/arch/arm/mach-socfpga/platsmp.c
> > @@ -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));
> >
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-19 13:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18 14:25 [PATCH v2] ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE Takashi Iwai
2021-11-18 17:20 ` Kees Cook
2021-11-18 22:08 ` Dinh Nguyen
2021-11-19 13:37   ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).