linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Andy Lutomirski <luto@amacapital.net>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Ingo Molnar <mingo@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 11:51:23 -0800	[thread overview]
Message-ID: <CA+55aFxP+V6Wbq5Xw_NOksiWouEMg4gjBJgeGa-qFyxDMnTmcA@mail.gmail.com> (raw)
In-Reply-To: <20170112140215.rh247gwk55fjzmg7@treble>

[-- Attachment #1: Type: text/plain, Size: 3363 bytes --]

On Thu, Jan 12, 2017 at 6:02 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>
> Just to clarify, I think you're asking if, for versions of gcc which
> don't support -mpreferred-stack-boundary=3, objtool can analyze all C
> functions to ensure their stacks are 16-byte aligned.
>
> It's certainly possible, but I don't see how that solves the problem.
> The stack will still be misaligned by entry code.  Or am I missing
> something?

I think the argument is that we *could* try to align things, if we
just had some tool that actually then verified that we aren't missing
anything.

I'm not entirely happy with checking the generated code, though,
because as Ingo says, you have a 50:50 chance of just getting it right
by mistake. So I'd much rather have some static tool that checks
things at a code level (ie coccinelle or sparse).

Almost totally untested "sparse" patch appended. The problem with
sparse, obviously, is that few enough people run it, and it gives a
lot of other warnings. But maybe Herbert can test whether this would
actually have caught his situation, doing something like an
allmodconfig build with "C=2" to force a sparse run on everything, and
redirecting the warnings to stderr.

But this patch does seem to give a warning for the patch that Herbert
had, and that caused problems.

And in fact it seems to find a few other possible problems (most, but
not all, in crypto). This run was with the broken chacha20 patch
applied, to verify that I get a warning for that case:

   arch/x86/crypto/chacha20_glue.c:70:13: warning: symbol 'state' has
excessive alignment (16)
   arch/x86/crypto/aesni-intel_glue.c:724:12: warning: symbol 'iv' has
excessive alignment (16)
   arch/x86/crypto/aesni-intel_glue.c:803:12: warning: symbol 'iv' has
excessive alignment (16)
   crypto/shash.c:82:12: warning: symbol 'ubuf' has excessive alignment (16)
   crypto/shash.c:118:12: warning: symbol 'ubuf' has excessive alignment (16)
   drivers/char/hw_random/via-rng.c:89:14: warning: symbol 'buf' has
excessive alignment (16)
   net/bridge/netfilter/ebtables.c:1809:31: warning: symbol 'tinfo'
has excessive alignment (64)
   drivers/crypto/padlock-sha.c:85:14: warning: symbol 'buf' has
excessive alignment (16)
   drivers/crypto/padlock-sha.c:147:14: warning: symbol 'buf' has
excessive alignment (16)
   drivers/crypto/padlock-sha.c:304:12: warning: symbol 'buf' has
excessive alignment (16)
   drivers/crypto/padlock-sha.c:388:12: warning: symbol 'buf' has
excessive alignment (16)
   net/openvswitch/actions.c:797:33: warning: symbol 'ovs_rt' has
excessive alignment (64)
   drivers/net/ethernet/neterion/vxge/vxge-config.c:1006:38: warning:
symbol 'vpath' has excessive alignment (64)

although I think at least some of these happen to be ok.

There are a few places that clearly don't care about exact alignment,
and use "__attribute__((aligned))" without any specific alignment
value.

It's just sparse that thinks that implies 16-byte alignment (it
doesn't, really - it's unspecified, and is telling gcc to use "maximum
useful alignment", so who knows _what_ gcc will assume).

But some of them may well be real issues - if the alignment is about
correctness rather than anything else.

Anyway, the advantage of this kind of source-level check is that it
should really catch things regardless of "luck" wrt alignment.

                    Linus

[-- Attachment #2: patch.diff --]
[-- Type: text/plain, Size: 887 bytes --]

 flow.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/flow.c b/flow.c
index 7db9548..c876869 100644
--- a/flow.c
+++ b/flow.c
@@ -601,6 +601,20 @@ static void simplify_one_symbol(struct entrypoint *ep, struct symbol *sym)
 	unsigned long mod;
 	int all, stores, complex;
 
+	/*
+	 * Warn about excessive local variable alignment.
+	 *
+	 * This needs to be linked up with some flag to enable
+	 * it, and specify the alignment. The 'max_int_alignment'
+	 * just happens to be what we want for the kernel for x86-64.
+	 */
+	mod = sym->ctype.modifiers;
+	if (!(mod & (MOD_NONLOCAL | MOD_STATIC))) {
+		unsigned int alignment = sym->ctype.alignment;
+		if (alignment > max_int_alignment)
+			warning(sym->pos, "symbol '%s' has excessive alignment (%u)", show_ident(sym->ident), alignment);
+	}
+
 	/* Never used as a symbol? */
 	pseudo = sym->pseudo;
 	if (!pseudo)

  reply	other threads:[~2017-01-12 19:51 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 [this message]
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
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=CA+55aFxP+V6Wbq5Xw_NOksiWouEMg4gjBJgeGa-qFyxDMnTmcA@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --cc=ard.biesheuvel@linaro.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=jpoimboe@redhat.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /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).