All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: Nathan Huckleberry <nhuck15@gmail.com>,
	Russell King <linux@armlinux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	clang-built-linux@googlegroups.com,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	Lvqiang Huang <lvqiang.huang@unisoc.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Miles Chen <miles.chen@mediatek.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/4] ARM: backtrace-clang: check for NULL lr
Date: Thu, 30 Jul 2020 13:51:09 -0700	[thread overview]
Message-ID: <20200730205112.2099429-2-ndesaulniers@google.com> (raw)
In-Reply-To: <20200730205112.2099429-1-ndesaulniers@google.com>

If the link register was zeroed out, do not attempt to use it for
address calculations for which there are currently no fixup handlers,
which can lead to a panic during unwind. Since panicking triggers
another unwind, this can lead to an infinite loop.  If this occurs
during start_kernel(), this can prevent a kernel from booting.

commit 59b6359dd92d ("ARM: 8702/1: head-common.S: Clear lr before jumping to start_kernel()")
intentionally zeros out the link register in __mmap_switched which tail
calls into start kernel. Test for this condition so that we can stop
unwinding when initiated within start_kernel() correctly.

Cc: stable@vger.kernel.org
Fixes: commit 6dc5fd93b2f1 ("ARM: 8900/1: UNWINDER_FRAME_POINTER implementation for Clang")
Reported-by: Miles Chen <miles.chen@mediatek.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 arch/arm/lib/backtrace-clang.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/lib/backtrace-clang.S b/arch/arm/lib/backtrace-clang.S
index 6174c45f53a5..5388ac664c12 100644
--- a/arch/arm/lib/backtrace-clang.S
+++ b/arch/arm/lib/backtrace-clang.S
@@ -144,6 +144,8 @@ for_each_frame:	tst	frame, mask		@ Check for address exceptions
  */
 1003:		ldr	sv_lr, [sv_fp, #4]	@ get saved lr from next frame
 
+		tst	sv_lr, #0		@ If there's no previous lr,
+		beq	finished_setup		@ we're done.
 		ldr	r0, [sv_lr, #-4]	@ get call instruction
 		ldr	r3, .Lopcode+4
 		and	r2, r3, r0		@ is this a bl call
-- 
2.28.0.163.g6104cc2f0b6-goog


WARNING: multiple messages have this Message-ID (diff)
From: Nick Desaulniers <ndesaulniers@google.com>
To: Nathan Huckleberry <nhuck15@gmail.com>,
	Russell King <linux@armlinux.org.uk>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	clang-built-linux@googlegroups.com,
	Miles Chen <miles.chen@mediatek.com>,
	linux-mediatek@lists.infradead.org,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lvqiang Huang <lvqiang.huang@unisoc.com>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/4] ARM: backtrace-clang: check for NULL lr
Date: Thu, 30 Jul 2020 13:51:09 -0700	[thread overview]
Message-ID: <20200730205112.2099429-2-ndesaulniers@google.com> (raw)
In-Reply-To: <20200730205112.2099429-1-ndesaulniers@google.com>

If the link register was zeroed out, do not attempt to use it for
address calculations for which there are currently no fixup handlers,
which can lead to a panic during unwind. Since panicking triggers
another unwind, this can lead to an infinite loop.  If this occurs
during start_kernel(), this can prevent a kernel from booting.

commit 59b6359dd92d ("ARM: 8702/1: head-common.S: Clear lr before jumping to start_kernel()")
intentionally zeros out the link register in __mmap_switched which tail
calls into start kernel. Test for this condition so that we can stop
unwinding when initiated within start_kernel() correctly.

Cc: stable@vger.kernel.org
Fixes: commit 6dc5fd93b2f1 ("ARM: 8900/1: UNWINDER_FRAME_POINTER implementation for Clang")
Reported-by: Miles Chen <miles.chen@mediatek.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 arch/arm/lib/backtrace-clang.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/lib/backtrace-clang.S b/arch/arm/lib/backtrace-clang.S
index 6174c45f53a5..5388ac664c12 100644
--- a/arch/arm/lib/backtrace-clang.S
+++ b/arch/arm/lib/backtrace-clang.S
@@ -144,6 +144,8 @@ for_each_frame:	tst	frame, mask		@ Check for address exceptions
  */
 1003:		ldr	sv_lr, [sv_fp, #4]	@ get saved lr from next frame
 
+		tst	sv_lr, #0		@ If there's no previous lr,
+		beq	finished_setup		@ we're done.
 		ldr	r0, [sv_lr, #-4]	@ get call instruction
 		ldr	r3, .Lopcode+4
 		and	r2, r3, r0		@ is this a bl call
-- 
2.28.0.163.g6104cc2f0b6-goog


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

WARNING: multiple messages have this Message-ID (diff)
From: Nick Desaulniers <ndesaulniers@google.com>
To: Nathan Huckleberry <nhuck15@gmail.com>,
	Russell King <linux@armlinux.org.uk>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	clang-built-linux@googlegroups.com,
	Miles Chen <miles.chen@mediatek.com>,
	linux-mediatek@lists.infradead.org,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lvqiang Huang <lvqiang.huang@unisoc.com>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/4] ARM: backtrace-clang: check for NULL lr
Date: Thu, 30 Jul 2020 13:51:09 -0700	[thread overview]
Message-ID: <20200730205112.2099429-2-ndesaulniers@google.com> (raw)
In-Reply-To: <20200730205112.2099429-1-ndesaulniers@google.com>

If the link register was zeroed out, do not attempt to use it for
address calculations for which there are currently no fixup handlers,
which can lead to a panic during unwind. Since panicking triggers
another unwind, this can lead to an infinite loop.  If this occurs
during start_kernel(), this can prevent a kernel from booting.

commit 59b6359dd92d ("ARM: 8702/1: head-common.S: Clear lr before jumping to start_kernel()")
intentionally zeros out the link register in __mmap_switched which tail
calls into start kernel. Test for this condition so that we can stop
unwinding when initiated within start_kernel() correctly.

Cc: stable@vger.kernel.org
Fixes: commit 6dc5fd93b2f1 ("ARM: 8900/1: UNWINDER_FRAME_POINTER implementation for Clang")
Reported-by: Miles Chen <miles.chen@mediatek.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 arch/arm/lib/backtrace-clang.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/lib/backtrace-clang.S b/arch/arm/lib/backtrace-clang.S
index 6174c45f53a5..5388ac664c12 100644
--- a/arch/arm/lib/backtrace-clang.S
+++ b/arch/arm/lib/backtrace-clang.S
@@ -144,6 +144,8 @@ for_each_frame:	tst	frame, mask		@ Check for address exceptions
  */
 1003:		ldr	sv_lr, [sv_fp, #4]	@ get saved lr from next frame
 
+		tst	sv_lr, #0		@ If there's no previous lr,
+		beq	finished_setup		@ we're done.
 		ldr	r0, [sv_lr, #-4]	@ get call instruction
 		ldr	r3, .Lopcode+4
 		and	r2, r3, r0		@ is this a bl call
-- 
2.28.0.163.g6104cc2f0b6-goog


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-07-30 20:51 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-30 20:51 [PATCH 0/4] CONFIG_UNWINDER_FRAME_POINTER fixes+cleanups Nick Desaulniers
2020-07-30 20:51 ` Nick Desaulniers
2020-07-30 20:51 ` Nick Desaulniers
2020-07-30 20:51 ` Nick Desaulniers [this message]
2020-07-30 20:51   ` [PATCH 1/4] ARM: backtrace-clang: check for NULL lr Nick Desaulniers
2020-07-30 20:51   ` Nick Desaulniers
2020-08-07 18:07   ` Nathan Huckleberry
2020-08-07 18:07     ` Nathan Huckleberry
2020-08-07 18:07     ` Nathan Huckleberry
2020-07-30 20:51 ` [PATCH 2/4] ARM: backtrace-clang: add fixup for lr dereference Nick Desaulniers
2020-07-30 20:51   ` Nick Desaulniers
2020-07-30 20:51   ` Nick Desaulniers
2020-08-01 23:18   ` Sasha Levin
2020-08-03 18:13     ` Nick Desaulniers
2020-08-04  6:27       ` Greg KH
2020-08-06  1:24   ` Sasha Levin
2020-08-06 22:38   ` Nathan Huckleberry
2020-08-06 22:38     ` Nathan Huckleberry
2020-08-06 22:38     ` Nathan Huckleberry
2020-08-10 22:33     ` Nick Desaulniers
2020-08-10 22:33       ` Nick Desaulniers
2020-08-10 22:33       ` Nick Desaulniers
2020-08-20  0:13       ` Nick Desaulniers
2020-08-20  0:13         ` Nick Desaulniers
2020-08-20  0:13         ` Nick Desaulniers
2020-08-13 16:25   ` Sasha Levin
2020-08-19 23:56   ` Sasha Levin
2020-07-30 20:51 ` [PATCH 3/4] ARM: backtrace-clang: give labels more descriptive names Nick Desaulniers
2020-07-30 20:51   ` Nick Desaulniers
2020-07-30 20:51   ` Nick Desaulniers
2020-08-06 22:39   ` Nathan Huckleberry
2020-08-06 22:39     ` Nathan Huckleberry
2020-08-06 22:39     ` Nathan Huckleberry
2020-08-10 22:32     ` Nick Desaulniers
2020-08-10 22:32       ` Nick Desaulniers
2020-08-10 22:32       ` Nick Desaulniers
2020-07-30 20:51 ` [PATCH 4/4] ARM: backtrace: use more descriptive labels Nick Desaulniers
2020-07-30 20:51   ` Nick Desaulniers
2020-07-30 20:51   ` Nick Desaulniers
2020-08-06  1:24 ` [PATCH 0/4] CONFIG_UNWINDER_FRAME_POINTER fixes+cleanups Sasha Levin

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=20200730205112.2099429-2-ndesaulniers@google.com \
    --to=ndesaulniers@google.com \
    --cc=0x7f454c46@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=lvqiang.huang@unisoc.com \
    --cc=matthias.bgg@gmail.com \
    --cc=miles.chen@mediatek.com \
    --cc=nhuck15@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=zhang.lyra@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.