mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joao Moreira <joao@overdrivepizza.com>
To: Kees Cook <keescook@chromium.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	x86@kernel.org, Sami Tolvanen <samitolvanen@google.com>,
	linux-kernel@vger.kernel.org, Mark Rutland <mark.rutland@arm.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>
Subject: Re: [PATCH] x86/ibt: Implement FineIBT
Date: Tue, 18 Oct 2022 12:59:42 -0700	[thread overview]
Message-ID: <5094174a77cdc44cf50c346bf1617555@overdrivepizza.com> (raw)
In-Reply-To: <202210181020.79AF7F7@keescook>

>> 
>>    o IBT WAIT-FOR-ENDBR state is a speculation stop; by placing
>>      the hash validation in the immediate instruction after
>>      the branch target there is a minimal speculation window
>>      and the whole is a viable defence against SpectreBHB.
> 
> I still think it's worth noting it does technically weaken the
> "attacker-controlled executable memory content injection" attack
> requirements, too. While an attacker needs to make sure they place an
> ENDBR at the start of their injected code, they no longer need to also
> learn and inject the CFI hash too, as the malicious code can just not
> do the check at all. The difference in protection currently isn't much.
> 
> It's not a very difficult requirement to get attacker-controlled bytes
> into executable memory, as there are already existing APIs that provide
> this to varying degrees of reachability, utility, and discoverability 
> --
> for example, BPF JIT when constant blinding isn't enabled (the 
> unfortunate
> default). And with the hashes currently being deterministic, there's no
> secret that needs to be exposed first; an attack can just calculate it.
> An improvement for kCFI would be to mutate all the hashes both at build
> time (perhaps using the same seed infrastructure that randstruct 
> depends
> on for sharing a seed across compilation units), and at boot time, so
> an actual .text content exposure is needed to find the target hash 
> value.
> 
If we look back at how well ASLR did over the years I think we can't 
really rely that randomizing the hashes will solve anything. So what you 
are suggesting is that we flip a "viable defence against SpectreBHB" for 
a randomization-based scheme, when what we really should be doing is 
getting constant blinding enabled by default.

In fact, even if an attacker is able to inject an ENDBR at the target 
through operation constants as you suggest, there is still the need for 
an info-leak to figure out the address of the ENDBR. I bet this is not a 
problem for any skilled attacker as much as figuring out the randomized 
hashes shouldn't be. Unfortunately no CFI scheme I know that relies on 
anything at the callee-side is fully reliable if an attacker can 
manipulate executable pages, and randomizing hashes won't change that. 
So I don't think there is a strong enough difference here. ClangCFI 
perhaps could be better in that perspective, but as we know it would 
bring many other drawbacks.

At this point I feel like going on is a bit of bike-shedding, but if 
this really matters, below is how to use randomization on FineIBT. Maybe 
with lot less entropy, but just ideas thrown that could be improved over 
time (don't take this as a serious proposal):

Assuming we got 16 bytes padding to play with on each function prologue, 
you can randomize between 0-11 in which offset you emit the ENDBR 
instruction. Caller/Callee would look like (hopefully I did not mess-up 
offset):

<caller>:
and 0xf3, r11b
call *r11

<callee>:
nop
nop
nop
endbr // <- this position is randomized/patched during boot time.
nop
nop
...

And of course, you get more entropy as you increase the padding nop 
area.

  parent reply	other threads:[~2022-10-18 19:59 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18 13:35 Peter Zijlstra
2022-10-18 14:43 ` David Laight
2022-10-18 15:58   ` Joao Moreira
2022-10-18 17:20     ` Kees Cook
2022-10-18 20:09       ` Joao Moreira
2022-10-19  5:33         ` Kees Cook
2022-10-18 21:27     ` David Laight
2022-10-18 14:47 ` Peter Zijlstra
2022-10-18 18:09 ` Kees Cook
2022-10-18 19:56   ` Peter Zijlstra
2022-10-18 23:31     ` Josh Poimboeuf
2022-10-19  5:22       ` Kees Cook
2022-10-19 11:38       ` Peter Zijlstra
2022-10-19  5:14     ` Kees Cook
2022-10-18 19:59   ` Peter Zijlstra
2022-10-18 21:09     ` Peter Zijlstra
2022-10-19  5:05     ` Kees Cook
2022-10-19 12:03       ` Peter Zijlstra
2022-10-19 15:22         ` Sami Tolvanen
2022-10-20 11:04           ` Peter Zijlstra
2022-10-18 19:59   ` Joao Moreira [this message]
2022-10-19  5:32     ` Kees Cook
2022-10-19 19:35       ` Joao Moreira
2022-10-18 20:05   ` Peter Zijlstra
2022-10-19  5:00     ` Kees Cook
2022-10-18 20:09   ` Peter Zijlstra
2022-10-18 20:17     ` Joao Moreira
2022-10-18 20:30       ` Peter Zijlstra
2022-10-19  4:48         ` Joao Moreira
2022-10-19  5:19           ` Kees Cook
2022-10-31 19:13             ` Joao Moreira
2022-11-01 21:39               ` Kees Cook
2022-11-01 21:50                 ` Joao Moreira
2024-05-06 17:36                   ` Kees Cook
2024-05-07  1:45                     ` Joao Moreira
2022-10-19  5:18         ` Kees Cook
2022-10-19  5:16     ` Kees Cook
2022-10-20 11:05   ` Peter Zijlstra
2022-10-18 23:38 ` Josh Poimboeuf
2022-10-19  7:29   ` Peter Zijlstra
2022-10-21 23:08 ` Josh Poimboeuf
2022-10-22 15:03   ` Peter Zijlstra
2022-10-24 17:15     ` Sami Tolvanen
2022-10-24 18:38       ` Joao Moreira

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=5094174a77cdc44cf50c346bf1617555@overdrivepizza.com \
    --to=joao@overdrivepizza.com \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=peterz@infradead.org \
    --cc=samitolvanen@google.com \
    --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

all inboxes | Powered by JetHome®