linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andy Lutomirski <luto@kernel.org>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: Re: x86-64: Maintain 16-byte stack alignment
Date: Thu, 12 Jan 2017 08:49:14 -0600	[thread overview]
Message-ID: <20170112144914.qmc5lgocp6vfq3b6@treble> (raw)
In-Reply-To: <20170112074601.GB30151@gmail.com>

On Thu, Jan 12, 2017 at 08:46:01AM +0100, Ingo Molnar wrote:
> 
> * Herbert Xu <herbert@gondor.apana.org.au> wrote:
> 
> > On Tue, Jan 10, 2017 at 09:05:28AM -0800, Linus Torvalds wrote:
> > >
> > > I'm pretty sure we have random asm code that may not maintain a
> > > 16-byte stack alignment when it calls other code (including, in some
> > > cases, calling C code).
> > > 
> > > So I'm not at all convinced that this is a good idea. We shouldn't
> > > expect 16-byte alignment to be something trustworthy.
> > 
> > So what if we audited all the x86 assembly code to fix this? Would
> > it then be acceptable to do a 16-byte aligned stack?
> 
> Audits for small but deadly details that isn't checked automatically by tooling 
> would inevitably bitrot again - and in this particular case there's a 50% chance 
> that a new, buggy change would test out to be 'fine' on a kernel developer's own 
> box - and break on different configs, different hw or with unrelated (and 
> innocent) kernel changes, sometime later - spreading the pain unnecessarily.
> 
> So my feeling is that we really need improved tooling for this (and yes, the GCC 
> toolchain should have handled this correctly).
> 
> But fortunately we have related tooling in the kernel: could objtool handle this? 
> My secret hope was always that objtool would grow into a kind of life insurance 
> against toolchain bogosities (which is a must for things like livepatching or a 
> DWARF unwinder - but I digress).

Are we talking about entry code, or other asm code?  Because objtool
audits *most* asm code, but entry code is way too specialized for
objtool to understand.

(I do have a pending objtool rewrite which would make it very easy to
ensure 16-byte stack alignment.  But again, objtool can only understand
callable C or asm functions, not entry code.)

Another approach would be to solve this problem with unwinder warnings,
*if* there's enough test coverage.

I recently made some changes to try to standardize the "end" of the
stack, so that the stack pointer is always a certain value before
calling into C code.  I also added some warnings to the unwinder to
ensure that it always reaches that point on the stack.  So if the "end"
of the stack were adjusted by a word by adding padding to pt_regs, the
unwinder warnings could help preserve that.

We could take that a step further by adding an unwinder check to ensure
that *every* frame is 16-byte aligned if -mpreferred-stack-boundary=3
isn't used.

Yet another step would be to add a debug feature which does stack sanity
checking from a periodic NMI, to flush out these unwinder warnings.

(Though I've found that current 0-day and fuzzing efforts, combined with
lockdep and perf's frequent unwinder usage, are already doing a great
job at flushing out unwinder warnings.)

The only question is if there would be enough test coverage,
particularly with those versions of gcc which don't have
-mpreferred-stack-boundary=3.

-- 
Josh

  reply	other threads:[~2017-01-12 14:49 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10 14:33 x86-64: Maintain 16-byte stack alignment Herbert Xu
2017-01-10 14:39 ` Herbert Xu
2017-01-10 17:05   ` Linus Torvalds
2017-01-10 17:09     ` Andy Lutomirski
2017-01-11  3:11     ` Herbert Xu
2017-01-11  3:30       ` Linus Torvalds
2017-01-11  4:17         ` Linus Torvalds
2017-01-11  4:35           ` Herbert Xu
2017-01-11  6:01             ` Andy Lutomirski
2017-01-12  6:21               ` Andy Lutomirski
2017-01-12  7:40                 ` Ingo Molnar
2017-01-12 14:02                 ` Josh Poimboeuf
2017-01-12 19:51                   ` Linus Torvalds
2017-01-12 20:08                     ` Andy Lutomirski
2017-01-12 20:15                       ` Josh Poimboeuf
2017-01-12 20:55                         ` Josh Poimboeuf
2017-01-12 21:40                           ` Linus Torvalds
2017-01-13  8:38                             ` Herbert Xu
2017-01-13  1:46                         ` Andy Lutomirski
2017-01-13  3:11                           ` Josh Poimboeuf
2017-01-13  3:23                             ` Andy Lutomirski
2017-01-13  4:27                               ` Josh Poimboeuf
     [not found]                                 ` <CA+55aFzRrSwGxxfZk-RUEnsz=xhcSmOwE1CenfCPBWtsS9MwDw@mail.gmail.com>
2017-01-13  5:07                                   ` Josh Poimboeuf
2017-01-13  8:43                                     ` Herbert Xu
2017-01-13  8:42                                   ` Herbert Xu
2017-01-13  8:39                           ` Herbert Xu
2017-01-13  8:36                       ` Herbert Xu
2017-01-13 13:07                         ` Josh Poimboeuf
     [not found]             ` <CA+55aFw+Z_ieo6DzTVB6_-TvQ0jj60s=T0mvXfqkBVFdKFPw_Q@mail.gmail.com>
2017-01-11  8:06               ` Ard Biesheuvel
2017-01-11  8:09                 ` Herbert Xu
2017-01-11 18:20                   ` Andy Lutomirski
2017-01-12  7:05     ` Herbert Xu
2017-01-12  7:46       ` Ingo Molnar
2017-01-12 14:49         ` Josh Poimboeuf [this message]
2017-01-12  7:51       ` Andy Lutomirski
2017-01-12  8:04         ` Herbert Xu
2017-01-12  8:18           ` Ingo Molnar
2017-01-12 15:03         ` Josh Poimboeuf
2017-01-12 15:06           ` Herbert Xu
2017-01-12 15:18             ` Josh Poimboeuf
2017-01-12 15:10           ` Josh Poimboeuf
2017-01-10 17:30 ` Ard Biesheuvel
2017-01-10 19:00   ` Andy Lutomirski
2017-01-10 19:16     ` Ard Biesheuvel
2017-01-10 19:22       ` Andy Lutomirski
2017-01-10 20:00         ` Ard Biesheuvel
2017-01-10 23:25           ` Andy Lutomirski
2017-01-11  3:26             ` Herbert Xu
2017-01-11  3:26         ` Herbert Xu
2017-01-11  3:16     ` Herbert Xu
2017-01-11  3:15   ` Herbert Xu
2017-01-12  6:12   ` Herbert Xu
2017-01-12  8:01     ` Ard Biesheuvel
2017-01-12  8:06       ` Herbert Xu

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=20170112144914.qmc5lgocp6vfq3b6@treble \
    --to=jpoimboe@redhat.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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).