All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Madhavan T. Venkataraman" <madvenka@linux.microsoft.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Julien Thierry <jthierry@redhat.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Brown <broonie@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Miroslav Benes <mbenes@suse.cz>, Will Deacon <will@kernel.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [RFC PATCH 0/3] arm64: Implement reliable stack trace
Date: Tue, 2 Feb 2021 17:32:32 -0600	[thread overview]
Message-ID: <d3448b84-393c-8a5b-e0eb-0c81ac4a60a6@linux.microsoft.com> (raw)
In-Reply-To: <20210202100547.GA59049@C02TD0UTHF1T.local>



On 2/2/21 4:05 AM, Mark Rutland wrote:
> I think that practically speaking it's necessary to track all potential
> paths through functions that may alter the shadow stack or the shadow
> stack pointer to ensure that the manipulation is well-balanced and that
> the shadow stack pointer isn't corrupted.
> 
> Practically speaking, this requires decoding a significant number of
> instructions, and tracing through all potential paths a function may
> take.

I thought about it some more since you don't like the shadow stack that much.
I think I can achieve what I want with a simpler design without any shadow
stack and with better performance than a shadow stack. It needs a slightly
changed prolog and epilog. Please review this and comment.

In this design, I need 8 bytes of storage for recording the current frame pointer
address. Space at the bottom of the stack can be reserved for this easily.
I will use cur_fp to refer to the value at that memory location.

For this discussion, fp refers to the frame pointer register and sp refers to the
stack pointer register.

The goal is - even if a function modifies fp and/or does not restore sp to its
correct value at the end, the prolog and epilog should manage it so that everything
works. To do this, the current frame pointer address is stored in fp as well as cur_fp.
Even if fp is modified, cur_fp will still point to the correct frame address.

Prolog
=======

The original prolog is:

- Push fp and return address on the stack
- fp = sp


The new prolog is:

- Save cur_fp on the stack
- Push fp, return address on the stack
- fp = sp
- cur_fp = fp

Epilog
======

The original epilog is:

- Pop fp and return address

The new epilog is:

- sp = cur_fp
- Pop fp and return address
- Restore cur_fp from the stack


I think this is pretty simple.

Unwinder
========


The unwinder will start the stack walk from cur_fp instead of fp. At each frame,
it will use the saved cur_fp instead of the saved fp. 

Also, at each step, it can know if fp was actually changed by the function in
the frame. The unwinder can optionally issue warnings.


Compiler issue
===============

This solution is geared towards the kernel only. It assumes that the stack
has a fixed size and alignment so the bottom of the stack can be reached
from the current sp.

So, the compiler has to support two prologs and epilogs, one pair for apps
and one pair for the kernel.

Since this is just a tiny bit of code, I don't think this is a problem.

Finally, objtool can verify the prolog and epilog.

Is this general solution acceptable? We can always work out details.

Madhavan

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

  parent reply	other threads:[~2021-02-02 23:33 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12 17:26 [RFC PATCH 0/3] arm64: Implement reliable stack trace Mark Brown
2020-10-12 17:26 ` [RFC PATCH 1/3] arm64: remove EL0 exception frame record Mark Brown
2020-10-12 17:26 ` [RFC PATCH 2/3] arm64: stacktrace: Report when we reach the end of the stack Mark Brown
2020-10-13 11:07   ` Mark Rutland
2020-10-12 17:26 ` [RFC PATCH 3/3] arm64: stacktrace: Implement reliable stacktrace Mark Brown
2020-10-13 10:42   ` Mark Brown
2020-10-13 11:42   ` Mark Rutland
2020-10-13 16:12     ` Mark Brown
2020-10-15 13:33   ` Miroslav Benes
2020-10-15 15:57     ` Mark Brown
2020-10-16 10:13       ` Miroslav Benes
2020-10-16 12:30         ` Mark Brown
2020-10-15 13:39 ` [RFC PATCH 0/3] arm64: Implement reliable stack trace Miroslav Benes
2020-10-15 14:16   ` Mark Rutland
2020-10-15 15:49     ` Mark Brown
2020-10-15 21:29       ` Josh Poimboeuf
2020-10-15 21:29         ` Josh Poimboeuf
2020-10-16 11:14         ` Mark Rutland
2020-10-16 11:14           ` Mark Rutland
2020-10-20 10:03           ` Mark Rutland
2020-10-20 10:03             ` Mark Rutland
2020-10-20 15:58             ` Josh Poimboeuf
2020-10-20 15:58               ` Josh Poimboeuf
2020-10-16 12:15         ` Mark Brown
2020-10-16 12:15           ` Mark Brown
2020-10-19 23:41           ` Josh Poimboeuf
2020-10-19 23:41             ` Josh Poimboeuf
2020-10-20 15:39             ` Mark Brown
2020-10-20 15:39               ` Mark Brown
2020-10-20 16:28               ` Josh Poimboeuf
2020-10-20 16:28                 ` Josh Poimboeuf
2021-01-27 14:02 ` Madhavan T. Venkataraman
2021-01-27 16:40   ` Mark Rutland
2021-01-27 17:11     ` Mark Brown
2021-01-27 17:24   ` Madhavan T. Venkataraman
2021-01-27 19:54 ` Madhavan T. Venkataraman
2021-01-28 14:22   ` Mark Brown
2021-01-28 15:26     ` Josh Poimboeuf
2021-01-29 21:39       ` Madhavan T. Venkataraman
2021-02-01  3:20         ` Madhavan T. Venkataraman
2021-02-01 14:39         ` Mark Brown
2021-01-30  4:38       ` Madhavan T. Venkataraman
2021-02-01 15:21       ` Madhavan T. Venkataraman
2021-02-01 15:46         ` Madhavan T. Venkataraman
2021-02-01 16:02         ` Mark Rutland
2021-02-01 16:22           ` Mark Brown
2021-02-01 21:40             ` Madhavan T. Venkataraman
2021-02-01 21:38           ` Madhavan T. Venkataraman
2021-02-01 23:00             ` Josh Poimboeuf
2021-02-02  2:29               ` Madhavan T. Venkataraman
2021-02-02  3:36                 ` Josh Poimboeuf
2021-02-02 10:05             ` Mark Rutland
2021-02-02 13:33               ` Madhavan T. Venkataraman
2021-02-02 13:35               ` Madhavan T. Venkataraman
2021-02-02 23:32               ` Madhavan T. Venkataraman [this message]
2021-02-03 16:53                 ` Mark Rutland
2021-02-03 19:03                   ` Madhavan T. Venkataraman
2021-02-05  2:36                     ` Madhavan T. Venkataraman
2021-02-01 21:59     ` Madhavan T. Venkataraman
2021-02-02 13:36       ` Mark Brown

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=d3448b84-393c-8a5b-e0eb-0c81ac4a60a6@linux.microsoft.com \
    --to=madvenka@linux.microsoft.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=jpoimboe@redhat.com \
    --cc=jthierry@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=mbenes@suse.cz \
    --cc=will@kernel.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 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.