Patchwork m68k: fix clobbering a5 in setjmp() [BZ #24202]

login
register
mail settings
Submitter Sergei Trofimovich
Date Feb. 10, 2019, 11:29 p.m.
Message ID <20190210232910.22652-1-slyfox@gentoo.org>
Download mbox | patch
Permalink /patch/31392/
State New
Headers show

Comments

Sergei Trofimovich - Feb. 10, 2019, 11:29 p.m.
setjmp() uses C code to store current registers into jmp_buf
environment. -fstack-protector-all places canary into setjmp()
prologue and clobbers 'a5' before it gets saved.

The change inhibits stack canary injection to avoid clobber.

	[BZ #24202]
	* sysdeps/m68k/setjmp.c (*setjmp): Use
	inhibit_stack_protector.

CC: James Le Cuirot <chewi@gentoo.org>
CC: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
---
 ChangeLog             | 6 ++++++
 sysdeps/m68k/setjmp.c | 1 +
 2 files changed, 7 insertions(+)
Adhemerval Zanella Netto - Feb. 11, 2019, 2:12 p.m.
On 10/02/2019 21:29, Sergei Trofimovich wrote:
> setjmp() uses C code to store current registers into jmp_buf
> environment. -fstack-protector-all places canary into setjmp()
> prologue and clobbers 'a5' before it gets saved.
> 
> The change inhibits stack canary injection to avoid clobber.
> 
> 	[BZ #24202]
> 	* sysdeps/m68k/setjmp.c (*setjmp): Use
> 	inhibit_stack_protector.

LGTM. I am not seeing the stack smash issue with example provided
in BZ#24202 in my environment (gcc 6.2.1, Aranym2015Jan on 3.16.0-4-m68k),
however the fix shows the expected printed value.

> 
> CC: James Le Cuirot <chewi@gentoo.org>
> CC: Andreas Schwab <schwab@linux-m68k.org>
> Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
> ---
>  ChangeLog             | 6 ++++++
>  sysdeps/m68k/setjmp.c | 1 +
>  2 files changed, 7 insertions(+)
> 
> diff --git a/ChangeLog b/ChangeLog
> index c143073ca7..c1e8dd9c3a 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,9 @@
> +2019-02-10  Sergei Trofimovich  <slyfox@gentoo.org>
> +
> +	[BZ #24202]
> +	* sysdeps/m68k/setjmp.c (*setjmp): Use
> +	inhibit_stack_protector.
> +
>  2019-02-06  Joseph Myers  <joseph@codesourcery.com>
>  
>  	* elf/dl-load.h (_dl_postprocess_loadcmd): Use __always_inline
> diff --git a/sysdeps/m68k/setjmp.c b/sysdeps/m68k/setjmp.c
> index 39ab7178a0..62bd281119 100644
> --- a/sysdeps/m68k/setjmp.c
> +++ b/sysdeps/m68k/setjmp.c
> @@ -19,6 +19,7 @@
>  
>  /* Save the current program position in ENV and return 0.  */
>  int
> +inhibit_stack_protector
>  #if defined BSD_SETJMP
>  # undef setjmp
>  # define savemask 1
>

Patch

diff --git a/ChangeLog b/ChangeLog
index c143073ca7..c1e8dd9c3a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@ 
+2019-02-10  Sergei Trofimovich  <slyfox@gentoo.org>
+
+	[BZ #24202]
+	* sysdeps/m68k/setjmp.c (*setjmp): Use
+	inhibit_stack_protector.
+
 2019-02-06  Joseph Myers  <joseph@codesourcery.com>
 
 	* elf/dl-load.h (_dl_postprocess_loadcmd): Use __always_inline
diff --git a/sysdeps/m68k/setjmp.c b/sysdeps/m68k/setjmp.c
index 39ab7178a0..62bd281119 100644
--- a/sysdeps/m68k/setjmp.c
+++ b/sysdeps/m68k/setjmp.c
@@ -19,6 +19,7 @@ 
 
 /* Save the current program position in ENV and return 0.  */
 int
+inhibit_stack_protector
 #if defined BSD_SETJMP
 # undef setjmp
 # define savemask 1