linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: linux@armlinux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] [ARM] Fix stack alignment when processing backtraces
Date: Mon, 31 Oct 2016 08:51:26 +0000	[thread overview]
Message-ID: <20161031085126.GT1041@n2100.armlinux.org.uk> (raw)
In-Reply-To: <20161018170510.GA12248@obsidianresearch.com>

On Tue, Oct 18, 2016 at 11:05:10AM -0600, Jason Gunthorpe wrote:
> The dumpstm helper within c_backtrace pushed 5 dwords onto the stack
> causing the stack to become unaligned and then calls printk. This
> causes memory corruption in the kernel which assumes AAPCS calling
> convention.
> 
> Since this bit of asm doesn't use the standard prologue just add
> another register to restore alignment.
> 
> Fixes: 7ab3f8d595a1b ("[ARM] Add ability to dump exception stacks to kernel backtraces")
> Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
> ---
>  arch/arm/lib/backtrace.S | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> In my case the kernel was hitting a WARN_ON during boot and then
> reliably failed to start the compiled-in initramfs.
> 
> I'm inferring that the stack misalignment caused some kind of memory
> corruption which wiped out the unpacked initramfs.
> 
> Saw with gcc 5.4.0 on a kirkwood armv5te
> 
> diff --git a/arch/arm/lib/backtrace.S b/arch/arm/lib/backtrace.S
> index fab5a50503ae..25e1cce19991 100644
> --- a/arch/arm/lib/backtrace.S
> +++ b/arch/arm/lib/backtrace.S
> @@ -116,7 +116,8 @@ ENDPROC(c_backtrace)
>  #define reg   r5
>  #define stack r6
>  
> -.Ldumpstm:	stmfd	sp!, {instr, reg, stack, r7, lr}
> +	        /* Must maintain 8 byte stack alignment */
> +.Ldumpstm:	stmfd	sp!, {r3, instr, reg, stack, r7, lr}
>  		mov	stack, r0
>  		mov	instr, r1
>  		mov	reg, #10
> @@ -140,7 +141,7 @@ ENDPROC(c_backtrace)
>  		teq	r7, #0
>  		adrne	r0, .Lcr
>  		blne	printk
> -		ldmfd	sp!, {instr, reg, stack, r7, pc}
> +		ldmfd	sp!, {r3, instr, reg, stack, r7, pc}

I'd prefer r8 to get used rather than r3, as it makes it look like
r3 is somehow required to be preserved when that's not the case.
Makes the code slightly more difficult to understand.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

  parent reply	other threads:[~2016-10-31  8:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18 17:05 [PATCH] [ARM] Fix stack alignment when processing backtraces Jason Gunthorpe
2016-10-28 17:57 ` Jason Gunthorpe
2016-10-31  8:51 ` Russell King - ARM Linux [this message]
2016-10-31 16:26   ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161031085126.GT1041@n2100.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).