linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	David Woodhouse <dwmw2@infradead.org>,
	Andi Kleen <andi@firstfloor.org>,
	the arch/x86 maintainers <x86@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Paul Turner <pjt@google.com>, Andrew Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linux-foundation.org>,
	Dave Hansen <dave.hansen@intel.com>,
	Jiri Kosina <jikos@kernel.org>, Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH] x86/alternatives: Fix optimize_nops() checking
Date: Wed, 10 Jan 2018 14:55:46 -0600	[thread overview]
Message-ID: <20180110205546.qn5kjil7icibfnkk@treble> (raw)
In-Reply-To: <CA+55aFzMzBwtfO1e=eC6oCx9mMMXPoRko0FvKKJrriUGqyQtEg@mail.gmail.com>

On Wed, Jan 10, 2018 at 12:26:25PM -0800, Linus Torvalds wrote:
> On Wed, Jan 10, 2018 at 12:15 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> >
> > I think .altinstruction relocations *do* work if they're for the first
> > instruction, and it's a jump or a call.
> 
> Yes - for the alternative that is in-line - not in the "altinstruction" section.
> 
> Because then the alternative is in the right spot at link-time already.
> 
> But the "altinstruction" section definitely should not have
> relocations.

I misspoke, it's really .altinstr_replacement which has the replacement
instructions.  And it has a bunch of relocations:

  Relocation section [ 8] '.rela.altinstr_replacement' for section [ 7] '.altinstr_replacement' at offset 0x14439710 contains 355 entries:

> I guess you could hack them up by hand by explicitly
> trying to take the difference between the non-altinstruction and the
> altinstruction into account, but it would be error-prone and fragile
> as hell.

apply_alternatives() already does that today.  It actually seems pretty
solid, except for the whole "only works on the first instruction" thing.

> > I think Boris had a patch floating around to add an instruction decoder
> > to alternatives, so you can do a call/jmp anywhere.
> 
> .. and no, we're not doing that. Christ.
> 
> People, we need to try to be *robust* here. That's doubly (triply!)
> true of things like altinstructions where people - very much by design
> - won't even *test* the alternatives very much, because very much by
> design the altinstructions are only used on certain architectures or
> in certain situations.
> 
> And we almost certainly don't actuially _need_ relocations. But we
> need to protect against the "oops, I didn't realize" issue, exactly
> because testing won't actually catch the odd cases.

If we need objtool to detect them, it's certainly possible.  But maybe I
missed the previous discussion -- what's the, um, alternative to
relocations, when we have calls and jumps being patched in?

> Because we don't want to be in the situation where some random poor
> user hits it because they have an old CPU that no developer has, and
> then the relocation will basically do completely random things.
> 
> Imagine just how crazy that would be to debug. You'd be basically
> executing insane code, and looking at the sources - or even the
> binaries - it would _look_ completely sane.

Well, I think we already made that deal with the devil when we added
alternatives/paravirt/smp_locks/jump_labels/kprobes/ftrace/bpf, etc.

-- 
Josh

  parent reply	other threads:[~2018-01-10 20:55 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-10  0:31 [PATCH] x86/retpoline: Fix NOSPEC_JMP for tip Andi Kleen
2018-01-10  0:39 ` Thomas Gleixner
2018-01-10  0:39 ` Linus Torvalds
2018-01-10  0:40   ` Thomas Gleixner
2018-01-10  0:45     ` Tom Lendacky
2018-01-10  0:50       ` Thomas Gleixner
2018-01-10  1:30       ` Andi Kleen
2018-01-10  1:36         ` Andi Kleen
2018-01-10  1:50           ` Thomas Gleixner
2018-01-10  1:57             ` Andi Kleen
2018-01-10  9:05         ` David Woodhouse
2018-01-10  0:51   ` Andi Kleen
2018-01-10  1:05     ` Thomas Gleixner
2018-01-10  7:15   ` David Woodhouse
2018-01-10 10:05     ` David Woodhouse
2018-01-10 11:28       ` [PATCH] x86/alternatives: Fix optimize_nops() checking Borislav Petkov
2018-01-10 11:36         ` David Woodhouse
2018-01-10 11:45           ` Borislav Petkov
2018-01-10 11:49             ` David Woodhouse
2018-01-10 11:57               ` Borislav Petkov
2018-01-10 11:58                 ` David Woodhouse
2018-01-10 17:33         ` [tip:x86/pti] " tip-bot for Borislav Petkov
2018-01-10 18:12         ` tip-bot for Borislav Petkov
2018-01-10 18:39         ` tip-bot for Borislav Petkov
2018-01-10 19:38         ` [PATCH] " Linus Torvalds
2018-01-10 19:55           ` Thomas Gleixner
2018-01-10 20:15             ` Josh Poimboeuf
2018-01-10 20:19               ` David Woodhouse
2018-01-10 20:26               ` Linus Torvalds
2018-01-10 20:33                 ` Peter Zijlstra
2018-01-10 20:36                   ` David Woodhouse
2018-01-10 20:49                   ` Linus Torvalds
2018-01-10 20:55                 ` Borislav Petkov
2018-01-10 21:05                   ` Linus Torvalds
2018-01-10 21:08                     ` David Woodhouse
2018-01-10 21:11                       ` Linus Torvalds
2018-01-10 21:16                         ` Josh Poimboeuf
2018-01-10 21:17                         ` Linus Torvalds
2018-01-10 21:27                           ` Josh Poimboeuf
2018-01-10 21:10                     ` Borislav Petkov
2018-01-10 20:55                 ` Josh Poimboeuf [this message]
2018-01-10 20:05           ` Borislav Petkov
2018-01-10 20:20             ` Linus Torvalds
2018-01-10 20:50               ` Borislav Petkov

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=20180110205546.qn5kjil7icibfnkk@treble \
    --to=jpoimboe@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=dwmw2@infradead.org \
    --cc=gregkh@linux-foundation.org \
    --cc=jikos@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=tim.c.chen@linux.intel.com \
    --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 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).