From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Michal Marek <mmarek@suse.cz>,
Peter Zijlstra <peterz@infradead.org>,
Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andi Kleen <andi@firstfloor.org>, Pedro Alves <palves@redhat.com>,
Namhyung Kim <namhyung@gmail.com>,
Bernd Petrovitsch <bernd@petrovitsch.priv.at>,
Chris J Arges <chris.j.arges@canonical.com>,
live-patching@vger.kernel.org,
Matt Fleming <matt.fleming@intel.com>
Subject: Re: [PATCH v10 19/20] x86/asm/efi: Create a stack frame in efi_call()
Date: Fri, 14 Aug 2015 09:07:12 -0500 [thread overview]
Message-ID: <20150814140712.GB341@treble.redhat.com> (raw)
In-Reply-To: <20150814091159.GA2865@codeblueprint.co.uk>
On Fri, Aug 14, 2015 at 10:11:59AM +0100, Matt Fleming wrote:
> On Thu, 13 Aug, at 10:10:40PM, Josh Poimboeuf wrote:
> > efi_call() is a callable non-leaf function which doesn't honor
> > CONFIG_FRAME_POINTER, which can result in bad stack traces.
> >
> > Create a stack frame for it when CONFIG_FRAME_POINTER is enabled.
> >
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > Cc: Matt Fleming <matt.fleming@intel.com>
> > ---
> > arch/x86/platform/efi/efi_stub_64.S | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
> > index 86d0f9e..0df2dcc 100644
> > --- a/arch/x86/platform/efi/efi_stub_64.S
> > +++ b/arch/x86/platform/efi/efi_stub_64.S
> > @@ -11,6 +11,7 @@
> > #include <asm/msr.h>
> > #include <asm/processor-flags.h>
> > #include <asm/page_types.h>
> > +#include <asm/frame.h>
> >
> > #define SAVE_XMM \
> > mov %rsp, %rax; \
> > @@ -74,6 +75,7 @@
> > .endm
> >
> > ENTRY(efi_call)
> > + FRAME_BEGIN
> > SAVE_XMM
> > mov (%rsp), %rax
> > mov 8(%rax), %rax
> > @@ -88,6 +90,7 @@ ENTRY(efi_call)
> > RESTORE_PGT
> > addq $48, %rsp
> > RESTORE_XMM
> > + FRAME_END
> > ret
> > ENDPROC(efi_call)
>
> You mention that stackvalidate will recursively validate the frame
> pointers in all code paths. Since we're calling into firmware code from
> efi_call(), we don't need to do anything special here right?
>
> I'm guessing stackvalidate would just stop since it has no way of
> knowing the target address of the %call instruction, but I just wanted
> to check (especially since the firmware ABI is different).
It recursively follows all code paths *inside* each function, including
jumps. It doesn't try to follow calls across functions, which can't be
done reliably because of function pointers. Instead it just verifies
that each function follows the calling conventions.
The result of creating a stack frame is that the *caller* of the
function shows up in the stack trace. So this patch ensures that
efi_call()'s caller would show up if, for example, the stack was dumped
from an interrupt which occurred in efi_call() between FRAME_BEGIN and
FRAME_END.
As to whether it helps in case the stack is dumped from firmware code
(or from an interrupt to firmware), it really depends on what the
firmware does:
- If it follows frame pointer convention, great (but I'm guessing this
is unlikely...)
- If it doesn't follow frame pointer convention, but still leaves rbp
alone, then efi_call() would be skipped in the stack trace but
efi_call()'s caller and the rest of the stack would still show up.
- If it trashes rbp, then we're out of luck and there's no stack trace.
But regardless of what firmware does, this patch still helps in the case
where the stack is dumped starting from efi_call().
> Reviewed-by: Matt Fleming <matt.fleming@intel.com>
Thanks!
--
Josh
next prev parent reply other threads:[~2015-08-14 14:07 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-14 3:10 [PATCH v10 00/20] Compile-time stack validation Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 01/20] x86/asm: Frame pointer macro cleanup Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 02/20] x86/asm: Add C versions of frame pointer macros Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 03/20] x86/stackvalidate: Compile-time stack validation Josh Poimboeuf
2015-08-15 7:23 ` Andrew Morton
2015-08-15 12:49 ` Josh Poimboeuf
2015-08-19 10:01 ` Ingo Molnar
2015-08-20 4:00 ` Josh Poimboeuf
2015-08-21 7:54 ` Ingo Molnar
2015-08-21 13:32 ` Josh Poimboeuf
2015-08-22 9:17 ` Ingo Molnar
2015-08-14 3:10 ` [PATCH v10 04/20] x86/stackvalidate: Add file and directory ignores Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 05/20] x86/stackvalidate: Add ignore macros Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 06/20] x86/xen: Add stack frame dependency to hypercall inline asm calls Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 07/20] x86/paravirt: Add stack frame dependency to PVOP " Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 08/20] x86/paravirt: Create a stack frame in PV_CALLEE_SAVE_REGS_THUNK Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 09/20] x86/amd: Set ELF function type for vide() Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 10/20] x86/reboot: Add ljmp instructions to stackvalidate whitelist Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 11/20] x86/xen: Add xen_cpuid() and xen_setup_gdt() to stackvalidate whitelists Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 12/20] x86/asm/crypto: Create stack frames in aesni-intel_asm.S Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 13/20] x86/asm/crypto: Move .Lbswap_mask data to .rodata section Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 14/20] x86/asm/crypto: Move jump_table " Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 15/20] x86/asm/crypto: Create stack frames in clmul_ghash_mul/update() Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 16/20] x86/asm/entry: Create stack frames in thunk functions Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 17/20] x86/asm/acpi: Create a stack frame in do_suspend_lowlevel() Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 18/20] x86/asm: Create stack frames in rwsem functions Josh Poimboeuf
2015-08-14 3:10 ` [PATCH v10 19/20] x86/asm/efi: Create a stack frame in efi_call() Josh Poimboeuf
2015-08-14 9:11 ` Matt Fleming
2015-08-14 14:07 ` Josh Poimboeuf [this message]
2015-08-14 3:10 ` [PATCH v10 20/20] x86/asm/power: Create stack frames in hibernate_asm_64.S Josh Poimboeuf
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=20150814140712.GB341@treble.redhat.com \
--to=jpoimboe@redhat.com \
--cc=andi@firstfloor.org \
--cc=bernd@petrovitsch.priv.at \
--cc=bp@alien8.de \
--cc=chris.j.arges@canonical.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=luto@kernel.org \
--cc=matt.fleming@intel.com \
--cc=matt@codeblueprint.co.uk \
--cc=mingo@redhat.com \
--cc=mmarek@suse.cz \
--cc=namhyung@gmail.com \
--cc=palves@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@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.