Discussion:
A more general possible meltdown/spectre countermeasure
Eric McCorkle
2018-01-05 22:02:11 UTC
Permalink
Re-posting to -hackers and -arch. I'm going to start working on
something like this over the weekend.

-------- Forwarded Message --------
Subject: A more general possible meltdown/spectre countermeasure
Date: Thu, 4 Jan 2018 23:05:40 -0500
From: Eric McCorkle <***@metricspace.net>
To: freebsd-***@freebsd.org <freebsd-***@freebsd.org>

I've thought more about how to deal with meltdown/spectre, and I have an
idea I'd like to put forward. However, I'm still in something of a
panic mode, so I'm not certain as to its effectiveness. Needless to
say, I welcome any feedback on this, and I may be completely off-base.

I'm calling this a "countermeasure" as opposed to a "mitigation", as
it's something that requires modification of code as opposed to a
drop-in patch.

== Summary ==

Provide a kernel and userland API by which memory allocation can be done
with extended attributes. In userland, this could be accomplished by
extending MMAP flags, and I could imagine a malloc-with-attributes flag.
In kernel space, this must already exist, as drivers need to allocate
memory with various MTRR-type attributes set.

The immediate aim here is to store sensitive information that must
remain memory-resident in non-cacheable memory locations (or, if more
effective attribute combinations exist, using those instead). See the
rationale for the argument why this should work.

Assuming the rationale holds, then the attack surface should be greatly
reduced. Attackers would need to grab sensitive data out of stack
frames or similar locations if/when it gets copied there for faster use.
Moreover, if this is done right, it could dovetail nicely into a
framework for storing and processing sensitive assets in more secure
hardware[0] (like smart cards, the FPGAs I posted earlier, or other
options).

The obvious downside is that you take a performance hit storing things
in non-cacheable locations, especially if you plan on doing heavy
computation in that memory (say, encryption/decryption). However, this
is almost certainly going to be less than the projected 30-50%
performance hit from other mitigations. Also, this technique should
work against spectre as well as meltdown (assuming the rationale holds).

The second downside is that you have to modify code for this to work,
and you have to be careful not to keep copies of sensitive information
around too long (this gets tricky in userland, where you might get
interrupted and switched out).


[0]: Full disclosure, enabling open hardware implementations of this
kind of thing is something of an agenda of mine.

== Rationale ==

(Again, I'm tired, rushed, and somewhat panicked so my logic could be
faulty at any point, so please point it out if it is)

The rationale for why this should work relies on assumptions about
out-of-order pipelines that cannot be guaranteed to hold, but are
extremely likely to be true.

As background, these attacks depend on out-of-order execution performing
operations that end up affecting cache and branch-prediction state,
ultimately storing information about sensitive data in these
side-channels before the fault conditions are detected and acted upon.
I'll borrow terminology from the paper, using "transient instructions"
to refer to speculatively executed instructions that will eventually be
cancelled by a fault.

These attacks depend entirely on transient instructions being able to
get sensitive information into the processor core and then perform some
kind of instruction on them before the fault condition cancels them.
Therefore, anything that prevents them from doing this *should* counter
the attack. If the actual sensitive data never makes it to the core
before the fault is detected, the dependent memory accesses/branches
never get executed and the data never makes it to the side-channels.

Another assumption here is that CPU architects are going to want to
squash faulted instructions ASAP and stop issuing along those
speculative branches, so as to reclaim execution units. So I'm assuming
once a fault comes back from address translation, then transient
execution stops dead.

Now, break down the cases for whether the address containing sensitive
data is in cache and TLB or not. (I'm assuming here that caches are
virtually-indexed, which enables cache lookups to bypass address
translation.)

* In cache, in TLB: You end up basically racing between the cache and
TLB, which will very likely end up detecting the fault before the data
arrives, but at the very worst, you get one or two cycles of transient
instruction execution before the fault.

* In cache, not in TLB: Virtually-indexed tagged means you get a cache
lookup racing a page-table walk. The cache lookup beats the page table
walk by potentially hundreds (maybe thousands) of cycles, giving you a
bunch of transient instructions before a fault gets triggered. This is
the main attack case.

* Not in cache, in TLB: Memory access requires address translation,
which comes back almost immediately as a fault.

* Not in cache, not in TLB: You have to do a page table walk before you
can fetch the location, as you have to go out to physical memory (and
therefore need a physical address). The page table walk will come back
with a fault, stopping the attack.

So, unless I'm missing something here, both non-cached cases defeat the
meltdown attack, as you *cannot* get the data unless you do address
translation first (and therefore detect faults).

As for why this defeats the spectre attack, the logic is similar: you've
jumped into someone else's executable code, hoping to scoop up enough
information into your branch predictor before the fault kicks you out.
However, to capture anything about sensitive information in your
side-channels, the transient instructions need to actually get it into
the core before a fault gets detected. The same case analysis as above
applies, so you never actually get the sensitive info into the core
before a fault comes back and you get squashed.


[1]: A physically-indexed cache would be largely immune to this attack,
as you'd have to do address translation before doing a cache lookup.


I have some ideas that can build on this, but I'd like to get some
feedback first.
_______________________________________________
freebsd-***@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-security
To unsubscribe, send any mail to "freebsd-security-***@freebsd.org"
Warner Losh
2018-01-05 22:10:27 UTC
Permalink
I think this is fatally flawed.

The side channel is the cache. Not the data at risk.

Any mapped memory, cached or not, can be used to influence the cache.
Storing stuff in uncached memory won't affect the side channel one bit.

Basically, all attacks boil down to tricking the processor, at elevated
privs, to doing something like

a = foo[offset];

where foo + offset are designed to communicate information by populating a
cache line. offset need not be cached itself and can be the result of
simple computations that depend on anything accessible at all in the kernel.

Warner
Post by Eric McCorkle
Re-posting to -hackers and -arch. I'm going to start working on
something like this over the weekend.
-------- Forwarded Message --------
Subject: A more general possible meltdown/spectre countermeasure
Date: Thu, 4 Jan 2018 23:05:40 -0500
I've thought more about how to deal with meltdown/spectre, and I have an
idea I'd like to put forward. However, I'm still in something of a
panic mode, so I'm not certain as to its effectiveness. Needless to
say, I welcome any feedback on this, and I may be completely off-base.
I'm calling this a "countermeasure" as opposed to a "mitigation", as
it's something that requires modification of code as opposed to a
drop-in patch.
== Summary ==
Provide a kernel and userland API by which memory allocation can be done
with extended attributes. In userland, this could be accomplished by
extending MMAP flags, and I could imagine a malloc-with-attributes flag.
In kernel space, this must already exist, as drivers need to allocate
memory with various MTRR-type attributes set.
The immediate aim here is to store sensitive information that must
remain memory-resident in non-cacheable memory locations (or, if more
effective attribute combinations exist, using those instead). See the
rationale for the argument why this should work.
Assuming the rationale holds, then the attack surface should be greatly
reduced. Attackers would need to grab sensitive data out of stack
frames or similar locations if/when it gets copied there for faster use.
Moreover, if this is done right, it could dovetail nicely into a
framework for storing and processing sensitive assets in more secure
hardware[0] (like smart cards, the FPGAs I posted earlier, or other
options).
The obvious downside is that you take a performance hit storing things
in non-cacheable locations, especially if you plan on doing heavy
computation in that memory (say, encryption/decryption). However, this
is almost certainly going to be less than the projected 30-50%
performance hit from other mitigations. Also, this technique should
work against spectre as well as meltdown (assuming the rationale holds).
The second downside is that you have to modify code for this to work,
and you have to be careful not to keep copies of sensitive information
around too long (this gets tricky in userland, where you might get
interrupted and switched out).
[0]: Full disclosure, enabling open hardware implementations of this
kind of thing is something of an agenda of mine.
== Rationale ==
(Again, I'm tired, rushed, and somewhat panicked so my logic could be
faulty at any point, so please point it out if it is)
The rationale for why this should work relies on assumptions about
out-of-order pipelines that cannot be guaranteed to hold, but are
extremely likely to be true.
As background, these attacks depend on out-of-order execution performing
operations that end up affecting cache and branch-prediction state,
ultimately storing information about sensitive data in these
side-channels before the fault conditions are detected and acted upon.
I'll borrow terminology from the paper, using "transient instructions"
to refer to speculatively executed instructions that will eventually be
cancelled by a fault.
These attacks depend entirely on transient instructions being able to
get sensitive information into the processor core and then perform some
kind of instruction on them before the fault condition cancels them.
Therefore, anything that prevents them from doing this *should* counter
the attack. If the actual sensitive data never makes it to the core
before the fault is detected, the dependent memory accesses/branches
never get executed and the data never makes it to the side-channels.
Another assumption here is that CPU architects are going to want to
squash faulted instructions ASAP and stop issuing along those
speculative branches, so as to reclaim execution units. So I'm assuming
once a fault comes back from address translation, then transient
execution stops dead.
Now, break down the cases for whether the address containing sensitive
data is in cache and TLB or not. (I'm assuming here that caches are
virtually-indexed, which enables cache lookups to bypass address
translation.)
* In cache, in TLB: You end up basically racing between the cache and
TLB, which will very likely end up detecting the fault before the data
arrives, but at the very worst, you get one or two cycles of transient
instruction execution before the fault.
* In cache, not in TLB: Virtually-indexed tagged means you get a cache
lookup racing a page-table walk. The cache lookup beats the page table
walk by potentially hundreds (maybe thousands) of cycles, giving you a
bunch of transient instructions before a fault gets triggered. This is
the main attack case.
* Not in cache, in TLB: Memory access requires address translation,
which comes back almost immediately as a fault.
* Not in cache, not in TLB: You have to do a page table walk before you
can fetch the location, as you have to go out to physical memory (and
therefore need a physical address). The page table walk will come back
with a fault, stopping the attack.
So, unless I'm missing something here, both non-cached cases defeat the
meltdown attack, as you *cannot* get the data unless you do address
translation first (and therefore detect faults).
As for why this defeats the spectre attack, the logic is similar: you've
jumped into someone else's executable code, hoping to scoop up enough
information into your branch predictor before the fault kicks you out.
However, to capture anything about sensitive information in your
side-channels, the transient instructions need to actually get it into
the core before a fault gets detected. The same case analysis as above
applies, so you never actually get the sensitive info into the core
before a fault comes back and you get squashed.
[1]: A physically-indexed cache would be largely immune to this attack,
as you'd have to do address translation before doing a cache lookup.
I have some ideas that can build on this, but I'd like to get some
feedback first.
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-security
"
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-arch
Eric McCorkle
2018-01-05 22:15:26 UTC
Permalink
Right, but you have to get the value "foo" into the pipeline in order
for it to affect the side-channels. This technique attempts to stop
that from happening.

Unless I made a mistake, non-cached memory reads force address
translation to happen first, which detects faults and blocks the
meltdown attack.

It also stops spectre with very high probability, as it's very unlikely
that an uncached load will arrive before the speculative thread gets
squashed.
Post by Warner Losh
I think this is fatally flawed.
The side channel is the cache. Not the data at risk.
Any mapped memory, cached or not, can be used to influence the cache.
Storing stuff in uncached memory won't affect the side channel one bit.
Basically, all attacks boil down to tricking the processor, at elevated
privs, to doing something like
a = foo[offset];
where foo + offset are designed to communicate information by populating
a cache line. offset need not be cached itself and can be the result of
simple computations that depend on anything accessible at all in the kernel.
Warner
Re-posting to -hackers and -arch.  I'm going to start working on
something like this over the weekend.
-------- Forwarded Message --------
Subject: A more general possible meltdown/spectre countermeasure
Date: Thu, 4 Jan 2018 23:05:40 -0500
I've thought more about how to deal with meltdown/spectre, and I have an
idea I'd like to put forward.  However, I'm still in something of a
panic mode, so I'm not certain as to its effectiveness.  Needless to
say, I welcome any feedback on this, and I may be completely off-base.
I'm calling this a "countermeasure" as opposed to a "mitigation", as
it's something that requires modification of code as opposed to a
drop-in patch.
== Summary ==
Provide a kernel and userland API by which memory allocation can be done
with extended attributes.  In userland, this could be accomplished by
extending MMAP flags, and I could imagine a malloc-with-attributes flag.
 In kernel space, this must already exist, as drivers need to allocate
memory with various MTRR-type attributes set.
The immediate aim here is to store sensitive information that must
remain memory-resident in non-cacheable memory locations (or, if more
effective attribute combinations exist, using those instead).  See the
rationale for the argument why this should work.
Assuming the rationale holds, then the attack surface should be greatly
reduced.  Attackers would need to grab sensitive data out of stack
frames or similar locations if/when it gets copied there for faster use.
 Moreover, if this is done right, it could dovetail nicely into a
framework for storing and processing sensitive assets in more secure
hardware[0] (like smart cards, the FPGAs I posted earlier, or other
options).
The obvious downside is that you take a performance hit storing things
in non-cacheable locations, especially if you plan on doing heavy
computation in that memory (say, encryption/decryption).  However, this
is almost certainly going to be less than the projected 30-50%
performance hit from other mitigations.  Also, this technique should
work against spectre as well as meltdown (assuming the rationale holds).
The second downside is that you have to modify code for this to work,
and you have to be careful not to keep copies of sensitive information
around too long (this gets tricky in userland, where you might get
interrupted and switched out).
[0]: Full disclosure, enabling open hardware implementations of this
kind of thing is something of an agenda of mine.
== Rationale ==
(Again, I'm tired, rushed, and somewhat panicked so my logic could be
faulty at any point, so please point it out if it is)
The rationale for why this should work relies on assumptions about
out-of-order pipelines that cannot be guaranteed to hold, but are
extremely likely to be true.
As background, these attacks depend on out-of-order execution performing
operations that end up affecting cache and branch-prediction state,
ultimately storing information about sensitive data in these
side-channels before the fault conditions are detected and acted upon.
I'll borrow terminology from the paper, using "transient instructions"
to refer to speculatively executed instructions that will eventually be
cancelled by a fault.
These attacks depend entirely on transient instructions being able to
get sensitive information into the processor core and then perform some
kind of instruction on them before the fault condition cancels them.
Therefore, anything that prevents them from doing this *should* counter
the attack.  If the actual sensitive data never makes it to the core
before the fault is detected, the dependent memory accesses/branches
never get executed and the data never makes it to the side-channels.
Another assumption here is that CPU architects are going to want to
squash faulted instructions ASAP and stop issuing along those
speculative branches, so as to reclaim execution units.  So I'm assuming
once a fault comes back from address translation, then transient
execution stops dead.
Now, break down the cases for whether the address containing sensitive
data is in cache and TLB or not.  (I'm assuming here that caches are
virtually-indexed, which enables cache lookups to bypass address
translation.)
* In cache, in TLB: You end up basically racing between the cache and
TLB, which will very likely end up detecting the fault before the data
arrives, but at the very worst, you get one or two cycles of transient
instruction execution before the fault.
* In cache, not in TLB: Virtually-indexed tagged means you get a cache
lookup racing a page-table walk.  The cache lookup beats the page table
walk by potentially hundreds (maybe thousands) of cycles, giving you a
bunch of transient instructions before a fault gets triggered.  This is
the main attack case.
* Not in cache, in TLB: Memory access requires address translation,
which comes back almost immediately as a fault.
* Not in cache, not in TLB: You have to do a page table walk before you
can fetch the location, as you have to go out to physical memory (and
therefore need a physical address).  The page table walk will come back
with a fault, stopping the attack.
So, unless I'm missing something here, both non-cached cases defeat the
meltdown attack, as you *cannot* get the data unless you do address
translation first (and therefore detect faults).
As for why this defeats the spectre attack, the logic is similar: you've
jumped into someone else's executable code, hoping to scoop up enough
information into your branch predictor before the fault kicks you out.
However, to capture anything about sensitive information in your
side-channels, the transient instructions need to actually get it into
the core before a fault gets detected.  The same case analysis as above
applies, so you never actually get the sensitive info into the core
before a fault comes back and you get squashed.
[1]: A physically-indexed cache would be largely immune to this attack,
as you'd have to do address translation before doing a cache lookup.
I have some ideas that can build on this, but I'd like to get some
feedback first.
_______________________________________________
mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
To unsubscribe, send any mail to
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
To unsubscribe, send any mail to
Warner Losh
2018-01-05 22:22:21 UTC
Permalink
While you might be right, I've seen no indication that a cache miss would
defeat these attacks in the public and non-public data I've looked at, even
though a large number of alternatives to the published workarounds have
been discussed. I'm therefore somewhat skeptical this would be effective.
I'm open, however, to data that changes that skepticism...

Warner
Post by Eric McCorkle
Right, but you have to get the value "foo" into the pipeline in order
for it to affect the side-channels. This technique attempts to stop
that from happening.
Unless I made a mistake, non-cached memory reads force address
translation to happen first, which detects faults and blocks the
meltdown attack.
It also stops spectre with very high probability, as it's very unlikely
that an uncached load will arrive before the speculative thread gets
squashed.
Post by Warner Losh
I think this is fatally flawed.
The side channel is the cache. Not the data at risk.
Any mapped memory, cached or not, can be used to influence the cache.
Storing stuff in uncached memory won't affect the side channel one bit.
Basically, all attacks boil down to tricking the processor, at elevated
privs, to doing something like
a = foo[offset];
where foo + offset are designed to communicate information by populating
a cache line. offset need not be cached itself and can be the result of
simple computations that depend on anything accessible at all in the
kernel.
Post by Warner Losh
Warner
Re-posting to -hackers and -arch. I'm going to start working on
something like this over the weekend.
-------- Forwarded Message --------
Subject: A more general possible meltdown/spectre countermeasure
Date: Thu, 4 Jan 2018 23:05:40 -0500
I've thought more about how to deal with meltdown/spectre, and I
have an
Post by Warner Losh
idea I'd like to put forward. However, I'm still in something of a
panic mode, so I'm not certain as to its effectiveness. Needless to
say, I welcome any feedback on this, and I may be completely
off-base.
Post by Warner Losh
I'm calling this a "countermeasure" as opposed to a "mitigation", as
it's something that requires modification of code as opposed to a
drop-in patch.
== Summary ==
Provide a kernel and userland API by which memory allocation can be
done
Post by Warner Losh
with extended attributes. In userland, this could be accomplished by
extending MMAP flags, and I could imagine a malloc-with-attributes
flag.
Post by Warner Losh
In kernel space, this must already exist, as drivers need to
allocate
Post by Warner Losh
memory with various MTRR-type attributes set.
The immediate aim here is to store sensitive information that must
remain memory-resident in non-cacheable memory locations (or, if more
effective attribute combinations exist, using those instead). See
the
Post by Warner Losh
rationale for the argument why this should work.
Assuming the rationale holds, then the attack surface should be
greatly
Post by Warner Losh
reduced. Attackers would need to grab sensitive data out of stack
frames or similar locations if/when it gets copied there for faster
use.
Post by Warner Losh
Moreover, if this is done right, it could dovetail nicely into a
framework for storing and processing sensitive assets in more secure
hardware[0] (like smart cards, the FPGAs I posted earlier, or other
options).
The obvious downside is that you take a performance hit storing
things
Post by Warner Losh
in non-cacheable locations, especially if you plan on doing heavy
computation in that memory (say, encryption/decryption). However,
this
Post by Warner Losh
is almost certainly going to be less than the projected 30-50%
performance hit from other mitigations. Also, this technique should
work against spectre as well as meltdown (assuming the rationale
holds).
Post by Warner Losh
The second downside is that you have to modify code for this to work,
and you have to be careful not to keep copies of sensitive
information
Post by Warner Losh
around too long (this gets tricky in userland, where you might get
interrupted and switched out).
[0]: Full disclosure, enabling open hardware implementations of this
kind of thing is something of an agenda of mine.
== Rationale ==
(Again, I'm tired, rushed, and somewhat panicked so my logic could be
faulty at any point, so please point it out if it is)
The rationale for why this should work relies on assumptions about
out-of-order pipelines that cannot be guaranteed to hold, but are
extremely likely to be true.
As background, these attacks depend on out-of-order execution
performing
Post by Warner Losh
operations that end up affecting cache and branch-prediction state,
ultimately storing information about sensitive data in these
side-channels before the fault conditions are detected and acted
upon.
Post by Warner Losh
I'll borrow terminology from the paper, using "transient
instructions"
Post by Warner Losh
to refer to speculatively executed instructions that will eventually
be
Post by Warner Losh
cancelled by a fault.
These attacks depend entirely on transient instructions being able to
get sensitive information into the processor core and then perform
some
Post by Warner Losh
kind of instruction on them before the fault condition cancels them.
Therefore, anything that prevents them from doing this *should*
counter
Post by Warner Losh
the attack. If the actual sensitive data never makes it to the core
before the fault is detected, the dependent memory accesses/branches
never get executed and the data never makes it to the side-channels.
Another assumption here is that CPU architects are going to want to
squash faulted instructions ASAP and stop issuing along those
speculative branches, so as to reclaim execution units. So I'm
assuming
Post by Warner Losh
once a fault comes back from address translation, then transient
execution stops dead.
Now, break down the cases for whether the address containing
sensitive
Post by Warner Losh
data is in cache and TLB or not. (I'm assuming here that caches are
virtually-indexed, which enables cache lookups to bypass address
translation.)
* In cache, in TLB: You end up basically racing between the cache and
TLB, which will very likely end up detecting the fault before the
data
Post by Warner Losh
arrives, but at the very worst, you get one or two cycles of
transient
Post by Warner Losh
instruction execution before the fault.
* In cache, not in TLB: Virtually-indexed tagged means you get a
cache
Post by Warner Losh
lookup racing a page-table walk. The cache lookup beats the page
table
Post by Warner Losh
walk by potentially hundreds (maybe thousands) of cycles, giving you
a
Post by Warner Losh
bunch of transient instructions before a fault gets triggered. This
is
Post by Warner Losh
the main attack case.
* Not in cache, in TLB: Memory access requires address translation,
which comes back almost immediately as a fault.
* Not in cache, not in TLB: You have to do a page table walk before
you
Post by Warner Losh
can fetch the location, as you have to go out to physical memory (and
therefore need a physical address). The page table walk will come
back
Post by Warner Losh
with a fault, stopping the attack.
So, unless I'm missing something here, both non-cached cases defeat
the
Post by Warner Losh
meltdown attack, as you *cannot* get the data unless you do address
translation first (and therefore detect faults).
you've
Post by Warner Losh
jumped into someone else's executable code, hoping to scoop up enough
information into your branch predictor before the fault kicks you
out.
Post by Warner Losh
However, to capture anything about sensitive information in your
side-channels, the transient instructions need to actually get it
into
Post by Warner Losh
the core before a fault gets detected. The same case analysis as
above
Post by Warner Losh
applies, so you never actually get the sensitive info into the core
before a fault comes back and you get squashed.
[1]: A physically-indexed cache would be largely immune to this
attack,
Post by Warner Losh
as you'd have to do address translation before doing a cache lookup.
I have some ideas that can build on this, but I'd like to get some
feedback first.
_______________________________________________
mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
To unsubscribe, send any mail to
_______________________________________________
list
Post by Warner Losh
https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
To unsubscribe, send any mail to
Eric McCorkle
2018-01-05 22:31:54 UTC
Permalink
Well, the only way to find out would be to try it out.

However, unless I'm missing something, if you're trying to pull a
meltdown attack, you try and fetch from the kernel. If that location
isn't cached (or if your cache is physically indexed), you need the
physical address (otherwise you don't know where to look), and thus have
to go through address translation, at which point you detect that the
page isn't accessible and fault. In the mean time, you can't
speculatively execute any of the operations that load up the
side-channels, because you don't have the sensitive data.

The reason you can pull off a meltdown attack at all is that a
virtually-indexed cache lets you get the data in parallel with address
translation (breaking the dependency between address translation and
fetching data), which takes 1000s of cycles for a TLB miss, during which
you have the data and can launch a whole bunch of transient ops.

Again, these are uncharted waters we're in; so it's entirely possible
I'm missing something here.
Post by Warner Losh
While you might be right, I've seen no indication that a cache miss
would defeat these attacks in the public and non-public data I've looked
at, even though a large number of alternatives to the published
workarounds have been discussed. I'm therefore somewhat skeptical this
would be effective. I'm open, however, to data that changes that
skepticism...
Warner
Right, but you have to get the value "foo" into the pipeline in order
for it to affect the side-channels.  This technique attempts to stop
that from happening.
Unless I made a mistake, non-cached memory reads force address
translation to happen first, which detects faults and blocks the
meltdown attack.
It also stops spectre with very high probability, as it's very unlikely
that an uncached load will arrive before the speculative thread gets
squashed.
Post by Warner Losh
I think this is fatally flawed.
The side channel is the cache. Not the data at risk.
Any mapped memory, cached or not, can be used to influence the cache.
Storing stuff in uncached memory won't affect the side channel one bit.
Basically, all attacks boil down to tricking the processor, at elevated
privs, to doing something like
a = foo[offset];
where foo + offset are designed to communicate information by populating
a cache line. offset need not be cached itself and can be the result of
simple computations that depend on anything accessible at all in the kernel.
Warner
     Re-posting to -hackers and -arch.  I'm going to start working on
     something like this over the weekend.
     -------- Forwarded Message --------
     Subject: A more general possible meltdown/spectre countermeasure
     Date: Thu, 4 Jan 2018 23:05:40 -0500
     I've thought more about how to deal with meltdown/spectre, and
I have an
Post by Warner Losh
     idea I'd like to put forward.  However, I'm still in something
of a
Post by Warner Losh
     panic mode, so I'm not certain as to its effectiveness. 
Needless to
Post by Warner Losh
     say, I welcome any feedback on this, and I may be completely
off-base.
Post by Warner Losh
     I'm calling this a "countermeasure" as opposed to a
"mitigation", as
Post by Warner Losh
     it's something that requires modification of code as opposed to a
     drop-in patch.
     == Summary ==
     Provide a kernel and userland API by which memory allocation
can be done
Post by Warner Losh
     with extended attributes.  In userland, this could be
accomplished by
Post by Warner Losh
     extending MMAP flags, and I could imagine a
malloc-with-attributes flag.
Post by Warner Losh
      In kernel space, this must already exist, as drivers need to
allocate
Post by Warner Losh
     memory with various MTRR-type attributes set.
     The immediate aim here is to store sensitive information that must
     remain memory-resident in non-cacheable memory locations (or,
if more
Post by Warner Losh
     effective attribute combinations exist, using those instead). 
See the
Post by Warner Losh
     rationale for the argument why this should work.
     Assuming the rationale holds, then the attack surface should
be greatly
Post by Warner Losh
     reduced.  Attackers would need to grab sensitive data out of stack
     frames or similar locations if/when it gets copied there for
faster use.
Post by Warner Losh
      Moreover, if this is done right, it could dovetail nicely into a
     framework for storing and processing sensitive assets in more
secure
Post by Warner Losh
     hardware[0] (like smart cards, the FPGAs I posted earlier, or
other
Post by Warner Losh
     options).
     The obvious downside is that you take a performance hit
storing things
Post by Warner Losh
     in non-cacheable locations, especially if you plan on doing heavy
     computation in that memory (say, encryption/decryption). 
However, this
Post by Warner Losh
     is almost certainly going to be less than the projected 30-50%
     performance hit from other mitigations.  Also, this technique
should
Post by Warner Losh
     work against spectre as well as meltdown (assuming the
rationale holds).
Post by Warner Losh
     The second downside is that you have to modify code for this
to work,
Post by Warner Losh
     and you have to be careful not to keep copies of sensitive
information
Post by Warner Losh
     around too long (this gets tricky in userland, where you might get
     interrupted and switched out).
     [0]: Full disclosure, enabling open hardware implementations
of this
Post by Warner Losh
     kind of thing is something of an agenda of mine.
     == Rationale ==
     (Again, I'm tired, rushed, and somewhat panicked so my logic
could be
Post by Warner Losh
     faulty at any point, so please point it out if it is)
     The rationale for why this should work relies on assumptions about
     out-of-order pipelines that cannot be guaranteed to hold, but are
     extremely likely to be true.
     As background, these attacks depend on out-of-order execution
performing
Post by Warner Losh
     operations that end up affecting cache and branch-prediction
state,
Post by Warner Losh
     ultimately storing information about sensitive data in these
     side-channels before the fault conditions are detected and
acted upon.
Post by Warner Losh
     I'll borrow terminology from the paper, using "transient
instructions"
Post by Warner Losh
     to refer to speculatively executed instructions that will
eventually be
Post by Warner Losh
     cancelled by a fault.
     These attacks depend entirely on transient instructions being
able to
Post by Warner Losh
     get sensitive information into the processor core and then
perform some
Post by Warner Losh
     kind of instruction on them before the fault condition cancels
them.
Post by Warner Losh
     Therefore, anything that prevents them from doing this
*should* counter
Post by Warner Losh
     the attack.  If the actual sensitive data never makes it to
the core
Post by Warner Losh
     before the fault is detected, the dependent memory
accesses/branches
Post by Warner Losh
     never get executed and the data never makes it to the
side-channels.
Post by Warner Losh
     Another assumption here is that CPU architects are going to
want to
Post by Warner Losh
     squash faulted instructions ASAP and stop issuing along those
     speculative branches, so as to reclaim execution units.  So
I'm assuming
Post by Warner Losh
     once a fault comes back from address translation, then transient
     execution stops dead.
     Now, break down the cases for whether the address containing
sensitive
Post by Warner Losh
     data is in cache and TLB or not.  (I'm assuming here that
caches are
Post by Warner Losh
     virtually-indexed, which enables cache lookups to bypass address
     translation.)
     * In cache, in TLB: You end up basically racing between the
cache and
Post by Warner Losh
     TLB, which will very likely end up detecting the fault before
the data
Post by Warner Losh
     arrives, but at the very worst, you get one or two cycles of
transient
Post by Warner Losh
     instruction execution before the fault.
     * In cache, not in TLB: Virtually-indexed tagged means you get
a cache
Post by Warner Losh
     lookup racing a page-table walk.  The cache lookup beats the
page table
Post by Warner Losh
     walk by potentially hundreds (maybe thousands) of cycles,
giving you a
Post by Warner Losh
     bunch of transient instructions before a fault gets
triggered.  This is
Post by Warner Losh
     the main attack case.
     * Not in cache, in TLB: Memory access requires address
translation,
Post by Warner Losh
     which comes back almost immediately as a fault.
     * Not in cache, not in TLB: You have to do a page table walk
before you
Post by Warner Losh
     can fetch the location, as you have to go out to physical
memory (and
Post by Warner Losh
     therefore need a physical address).  The page table walk will
come back
Post by Warner Losh
     with a fault, stopping the attack.
     So, unless I'm missing something here, both non-cached cases
defeat the
Post by Warner Losh
     meltdown attack, as you *cannot* get the data unless you do
address
Post by Warner Losh
     translation first (and therefore detect faults).
     As for why this defeats the spectre attack, the logic is
similar: you've
Post by Warner Losh
     jumped into someone else's executable code, hoping to scoop up
enough
Post by Warner Losh
     information into your branch predictor before the fault kicks
you out.
Post by Warner Losh
     However, to capture anything about sensitive information in your
     side-channels, the transient instructions need to actually get
it into
Post by Warner Losh
     the core before a fault gets detected.  The same case analysis
as above
Post by Warner Losh
     applies, so you never actually get the sensitive info into the
core
Post by Warner Losh
     before a fault comes back and you get squashed.
     [1]: A physically-indexed cache would be largely immune to
this attack,
Post by Warner Losh
     as you'd have to do address translation before doing a cache
lookup.
Post by Warner Losh
     I have some ideas that can build on this, but I'd like to get some
     feedback first.
     _______________________________________________
     mailing list
     https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
Post by Warner Losh
     <https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>
Post by Warner Losh
     To unsubscribe, send any mail to
     _______________________________________________
mailing list
Post by Warner Losh
     https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
     <https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>
Post by Warner Losh
     To unsubscribe, send any mail to
Warner Losh
2018-01-05 23:08:19 UTC
Permalink
Wouldn't you have to also unmap it from the direct map for this to be
effective?

Warner
Post by Eric McCorkle
Well, the only way to find out would be to try it out.
However, unless I'm missing something, if you're trying to pull a
meltdown attack, you try and fetch from the kernel. If that location
isn't cached (or if your cache is physically indexed), you need the
physical address (otherwise you don't know where to look), and thus have
to go through address translation, at which point you detect that the
page isn't accessible and fault. In the mean time, you can't
speculatively execute any of the operations that load up the
side-channels, because you don't have the sensitive data.
The reason you can pull off a meltdown attack at all is that a
virtually-indexed cache lets you get the data in parallel with address
translation (breaking the dependency between address translation and
fetching data), which takes 1000s of cycles for a TLB miss, during which
you have the data and can launch a whole bunch of transient ops.
Again, these are uncharted waters we're in; so it's entirely possible
I'm missing something here.
Post by Warner Losh
While you might be right, I've seen no indication that a cache miss
would defeat these attacks in the public and non-public data I've looked
at, even though a large number of alternatives to the published
workarounds have been discussed. I'm therefore somewhat skeptical this
would be effective. I'm open, however, to data that changes that
skepticism...
Warner
Right, but you have to get the value "foo" into the pipeline in order
for it to affect the side-channels. This technique attempts to stop
that from happening.
Unless I made a mistake, non-cached memory reads force address
translation to happen first, which detects faults and blocks the
meltdown attack.
It also stops spectre with very high probability, as it's very
unlikely
Post by Warner Losh
that an uncached load will arrive before the speculative thread gets
squashed.
Post by Warner Losh
I think this is fatally flawed.
The side channel is the cache. Not the data at risk.
Any mapped memory, cached or not, can be used to influence the
cache.
Post by Warner Losh
Post by Warner Losh
Storing stuff in uncached memory won't affect the side channel one
bit.
Post by Warner Losh
Post by Warner Losh
Basically, all attacks boil down to tricking the processor, at
elevated
Post by Warner Losh
Post by Warner Losh
privs, to doing something like
a = foo[offset];
where foo + offset are designed to communicate information by
populating
Post by Warner Losh
Post by Warner Losh
a cache line. offset need not be cached itself and can be the
result of
Post by Warner Losh
Post by Warner Losh
simple computations that depend on anything accessible at all in
the kernel.
Post by Warner Losh
Post by Warner Losh
Warner
On Fri, Jan 5, 2018 at 3:02 PM, Eric McCorkle <
Re-posting to -hackers and -arch. I'm going to start working
on
Post by Warner Losh
Post by Warner Losh
something like this over the weekend.
-------- Forwarded Message --------
Subject: A more general possible meltdown/spectre
countermeasure
Post by Warner Losh
Post by Warner Losh
Date: Thu, 4 Jan 2018 23:05:40 -0500
I've thought more about how to deal with meltdown/spectre, and
I have an
Post by Warner Losh
idea I'd like to put forward. However, I'm still in something
of a
Post by Warner Losh
panic mode, so I'm not certain as to its effectiveness.
Needless to
Post by Warner Losh
say, I welcome any feedback on this, and I may be completely
off-base.
Post by Warner Losh
I'm calling this a "countermeasure" as opposed to a
"mitigation", as
Post by Warner Losh
it's something that requires modification of code as opposed
to a
Post by Warner Losh
Post by Warner Losh
drop-in patch.
== Summary ==
Provide a kernel and userland API by which memory allocation
can be done
Post by Warner Losh
with extended attributes. In userland, this could be
accomplished by
Post by Warner Losh
extending MMAP flags, and I could imagine a
malloc-with-attributes flag.
Post by Warner Losh
In kernel space, this must already exist, as drivers need to
allocate
Post by Warner Losh
memory with various MTRR-type attributes set.
The immediate aim here is to store sensitive information that
must
Post by Warner Losh
Post by Warner Losh
remain memory-resident in non-cacheable memory locations (or,
if more
Post by Warner Losh
effective attribute combinations exist, using those instead).
See the
Post by Warner Losh
rationale for the argument why this should work.
Assuming the rationale holds, then the attack surface should
be greatly
Post by Warner Losh
reduced. Attackers would need to grab sensitive data out of
stack
Post by Warner Losh
Post by Warner Losh
frames or similar locations if/when it gets copied there for
faster use.
Post by Warner Losh
Moreover, if this is done right, it could dovetail nicely
into a
Post by Warner Losh
Post by Warner Losh
framework for storing and processing sensitive assets in more
secure
Post by Warner Losh
hardware[0] (like smart cards, the FPGAs I posted earlier, or
other
Post by Warner Losh
options).
The obvious downside is that you take a performance hit
storing things
Post by Warner Losh
in non-cacheable locations, especially if you plan on doing
heavy
Post by Warner Losh
Post by Warner Losh
computation in that memory (say, encryption/decryption).
However, this
Post by Warner Losh
is almost certainly going to be less than the projected 30-50%
performance hit from other mitigations. Also, this technique
should
Post by Warner Losh
work against spectre as well as meltdown (assuming the
rationale holds).
Post by Warner Losh
The second downside is that you have to modify code for this
to work,
Post by Warner Losh
and you have to be careful not to keep copies of sensitive
information
Post by Warner Losh
around too long (this gets tricky in userland, where you might
get
Post by Warner Losh
Post by Warner Losh
interrupted and switched out).
[0]: Full disclosure, enabling open hardware implementations
of this
Post by Warner Losh
kind of thing is something of an agenda of mine.
== Rationale ==
(Again, I'm tired, rushed, and somewhat panicked so my logic
could be
Post by Warner Losh
faulty at any point, so please point it out if it is)
The rationale for why this should work relies on assumptions
about
Post by Warner Losh
Post by Warner Losh
out-of-order pipelines that cannot be guaranteed to hold, but
are
Post by Warner Losh
Post by Warner Losh
extremely likely to be true.
As background, these attacks depend on out-of-order execution
performing
Post by Warner Losh
operations that end up affecting cache and branch-prediction
state,
Post by Warner Losh
ultimately storing information about sensitive data in these
side-channels before the fault conditions are detected and
acted upon.
Post by Warner Losh
I'll borrow terminology from the paper, using "transient
instructions"
Post by Warner Losh
to refer to speculatively executed instructions that will
eventually be
Post by Warner Losh
cancelled by a fault.
These attacks depend entirely on transient instructions being
able to
Post by Warner Losh
get sensitive information into the processor core and then
perform some
Post by Warner Losh
kind of instruction on them before the fault condition cancels
them.
Post by Warner Losh
Therefore, anything that prevents them from doing this
*should* counter
Post by Warner Losh
the attack. If the actual sensitive data never makes it to
the core
Post by Warner Losh
before the fault is detected, the dependent memory
accesses/branches
Post by Warner Losh
never get executed and the data never makes it to the
side-channels.
Post by Warner Losh
Another assumption here is that CPU architects are going to
want to
Post by Warner Losh
squash faulted instructions ASAP and stop issuing along those
speculative branches, so as to reclaim execution units. So
I'm assuming
Post by Warner Losh
once a fault comes back from address translation, then
transient
Post by Warner Losh
Post by Warner Losh
execution stops dead.
Now, break down the cases for whether the address containing
sensitive
Post by Warner Losh
data is in cache and TLB or not. (I'm assuming here that
caches are
Post by Warner Losh
virtually-indexed, which enables cache lookups to bypass
address
Post by Warner Losh
Post by Warner Losh
translation.)
* In cache, in TLB: You end up basically racing between the
cache and
Post by Warner Losh
TLB, which will very likely end up detecting the fault before
the data
Post by Warner Losh
arrives, but at the very worst, you get one or two cycles of
transient
Post by Warner Losh
instruction execution before the fault.
* In cache, not in TLB: Virtually-indexed tagged means you get
a cache
Post by Warner Losh
lookup racing a page-table walk. The cache lookup beats the
page table
Post by Warner Losh
walk by potentially hundreds (maybe thousands) of cycles,
giving you a
Post by Warner Losh
bunch of transient instructions before a fault gets
triggered. This is
Post by Warner Losh
the main attack case.
* Not in cache, in TLB: Memory access requires address
translation,
Post by Warner Losh
which comes back almost immediately as a fault.
* Not in cache, not in TLB: You have to do a page table walk
before you
Post by Warner Losh
can fetch the location, as you have to go out to physical
memory (and
Post by Warner Losh
therefore need a physical address). The page table walk will
come back
Post by Warner Losh
with a fault, stopping the attack.
So, unless I'm missing something here, both non-cached cases
defeat the
Post by Warner Losh
meltdown attack, as you *cannot* get the data unless you do
address
Post by Warner Losh
translation first (and therefore detect faults).
As for why this defeats the spectre attack, the logic is
similar: you've
Post by Warner Losh
jumped into someone else's executable code, hoping to scoop up
enough
Post by Warner Losh
information into your branch predictor before the fault kicks
you out.
Post by Warner Losh
However, to capture anything about sensitive information in
your
Post by Warner Losh
Post by Warner Losh
side-channels, the transient instructions need to actually get
it into
Post by Warner Losh
the core before a fault gets detected. The same case analysis
as above
Post by Warner Losh
applies, so you never actually get the sensitive info into the
core
Post by Warner Losh
before a fault comes back and you get squashed.
[1]: A physically-indexed cache would be largely immune to
this attack,
Post by Warner Losh
as you'd have to do address translation before doing a cache
lookup.
Post by Warner Losh
I have some ideas that can build on this, but I'd like to get
some
Post by Warner Losh
Post by Warner Losh
feedback first.
_______________________________________________
mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>
Post by Warner Losh
To unsubscribe, send any mail to
_______________________________________________
mailing list
Post by Warner Losh
https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>
Post by Warner Losh
To unsubscribe, send any mail to
Eric McCorkle
2018-01-05 23:10:53 UTC
Permalink
I'm not sure what you mean by direct map. Do you mean TLB?
Post by Warner Losh
Wouldn't you have to also unmap it from the direct map for this to be
effective?
Warner
Well, the only way to find out would be to try it out.
However, unless I'm missing something, if you're trying to pull a
meltdown attack, you try and fetch from the kernel.  If that location
isn't cached (or if your cache is physically indexed), you need the
physical address (otherwise you don't know where to look), and thus have
to go through address translation, at which point you detect that the
page isn't accessible and fault.  In the mean time, you can't
speculatively execute any of the operations that load up the
side-channels, because you don't have the sensitive data.
The reason you can pull off a meltdown attack at all is that a
virtually-indexed cache lets you get the data in parallel with address
translation (breaking the dependency between address translation and
fetching data), which takes 1000s of cycles for a TLB miss, during which
you have the data and can launch a whole bunch of transient ops.
Again, these are uncharted waters we're in; so it's entirely possible
I'm missing something here.
Post by Warner Losh
While you might be right, I've seen no indication that a cache miss
would defeat these attacks in the public and non-public data I've looked
at, even though a large number of alternatives to the published
workarounds have been discussed. I'm therefore somewhat skeptical this
would be effective. I'm open, however, to data that changes that
skepticism...
Warner
     Right, but you have to get the value "foo" into the pipeline in order
     for it to affect the side-channels.  This technique attempts to stop
     that from happening.
     Unless I made a mistake, non-cached memory reads force address
     translation to happen first, which detects faults and blocks the
     meltdown attack.
     It also stops spectre with very high probability, as it's very unlikely
     that an uncached load will arrive before the speculative thread gets
     squashed.
     > I think this is fatally flawed.
     >
     > The side channel is the cache. Not the data at risk.
     >
     > Any mapped memory, cached or not, can be used to influence the cache.
     > Storing stuff in uncached memory won't affect the side channel one bit.
     >
     > Basically, all attacks boil down to tricking the processor, at elevated
     > privs, to doing something like
     >
     > a = foo[offset];
     >
     > where foo + offset are designed to communicate information by populating
     > a cache line. offset need not be cached itself and can be the result of
     > simple computations that depend on anything accessible at all in the kernel.
     >
     > Warner
     >
     >
     >     Re-posting to -hackers and -arch.  I'm going to start working on
     >     something like this over the weekend.
     >
     >     -------- Forwarded Message --------
     >     Subject: A more general possible meltdown/spectre countermeasure
     >     Date: Thu, 4 Jan 2018 23:05:40 -0500
     >
     >     I've thought more about how to deal with
meltdown/spectre, and
Post by Warner Losh
     I have an
     >     idea I'd like to put forward.  However, I'm still in
something
Post by Warner Losh
     of a
     >     panic mode, so I'm not certain as to its effectiveness. 
     Needless to
     >     say, I welcome any feedback on this, and I may be completely
     off-base.
     >
     >     I'm calling this a "countermeasure" as opposed to a
     "mitigation", as
     >     it's something that requires modification of code as
opposed to a
Post by Warner Losh
     >     drop-in patch.
     >
     >     == Summary ==
     >
     >     Provide a kernel and userland API by which memory allocation
     can be done
     >     with extended attributes.  In userland, this could be
     accomplished by
     >     extending MMAP flags, and I could imagine a
     malloc-with-attributes flag.
     >      In kernel space, this must already exist, as drivers
need to
Post by Warner Losh
     allocate
     >     memory with various MTRR-type attributes set.
     >
     >     The immediate aim here is to store sensitive information
that must
Post by Warner Losh
     >     remain memory-resident in non-cacheable memory locations
(or,
Post by Warner Losh
     if more
     >     effective attribute combinations exist, using those
instead). 
Post by Warner Losh
     See the
     >     rationale for the argument why this should work.
     >
     >     Assuming the rationale holds, then the attack surface should
     be greatly
     >     reduced.  Attackers would need to grab sensitive data
out of stack
Post by Warner Losh
     >     frames or similar locations if/when it gets copied there for
     faster use.
     >      Moreover, if this is done right, it could dovetail
nicely into a
Post by Warner Losh
     >     framework for storing and processing sensitive assets in
more
Post by Warner Losh
     secure
     >     hardware[0] (like smart cards, the FPGAs I posted
earlier, or
Post by Warner Losh
     other
     >     options).
     >
     >     The obvious downside is that you take a performance hit
     storing things
     >     in non-cacheable locations, especially if you plan on
doing heavy
Post by Warner Losh
     >     computation in that memory (say, encryption/decryption). 
     However, this
     >     is almost certainly going to be less than the projected
30-50%
Post by Warner Losh
     >     performance hit from other mitigations.  Also, this
technique
Post by Warner Losh
     should
     >     work against spectre as well as meltdown (assuming the
     rationale holds).
     >
     >     The second downside is that you have to modify code for this
     to work,
     >     and you have to be careful not to keep copies of sensitive
     information
     >     around too long (this gets tricky in userland, where you
might get
Post by Warner Losh
     >     interrupted and switched out).
     >
     >
     >     [0]: Full disclosure, enabling open hardware implementations
     of this
     >     kind of thing is something of an agenda of mine.
     >
     >     == Rationale ==
     >
     >     (Again, I'm tired, rushed, and somewhat panicked so my logic
     could be
     >     faulty at any point, so please point it out if it is)
     >
     >     The rationale for why this should work relies on
assumptions about
Post by Warner Losh
     >     out-of-order pipelines that cannot be guaranteed to
hold, but are
Post by Warner Losh
     >     extremely likely to be true.
     >
     >     As background, these attacks depend on out-of-order
execution
Post by Warner Losh
     performing
     >     operations that end up affecting cache and branch-prediction
     state,
     >     ultimately storing information about sensitive data in these
     >     side-channels before the fault conditions are detected and
     acted upon.
     >     I'll borrow terminology from the paper, using "transient
     instructions"
     >     to refer to speculatively executed instructions that will
     eventually be
     >     cancelled by a fault.
     >
     >     These attacks depend entirely on transient instructions
being
Post by Warner Losh
     able to
     >     get sensitive information into the processor core and then
     perform some
     >     kind of instruction on them before the fault condition
cancels
Post by Warner Losh
     them.
     >     Therefore, anything that prevents them from doing this
     *should* counter
     >     the attack.  If the actual sensitive data never makes it to
     the core
     >     before the fault is detected, the dependent memory
     accesses/branches
     >     never get executed and the data never makes it to the
     side-channels.
     >
     >     Another assumption here is that CPU architects are going to
     want to
     >     squash faulted instructions ASAP and stop issuing along
those
Post by Warner Losh
     >     speculative branches, so as to reclaim execution units.  So
     I'm assuming
     >     once a fault comes back from address translation, then
transient
Post by Warner Losh
     >     execution stops dead.
     >
     >     Now, break down the cases for whether the address containing
     sensitive
     >     data is in cache and TLB or not.  (I'm assuming here that
     caches are
     >     virtually-indexed, which enables cache lookups to bypass
address
Post by Warner Losh
     >     translation.)
     >
     >     * In cache, in TLB: You end up basically racing between the
     cache and
     >     TLB, which will very likely end up detecting the fault
before
Post by Warner Losh
     the data
     >     arrives, but at the very worst, you get one or two cycles of
     transient
     >     instruction execution before the fault.
     >
     >     * In cache, not in TLB: Virtually-indexed tagged means
you get
Post by Warner Losh
     a cache
     >     lookup racing a page-table walk.  The cache lookup beats the
     page table
     >     walk by potentially hundreds (maybe thousands) of cycles,
     giving you a
     >     bunch of transient instructions before a fault gets
     triggered.  This is
     >     the main attack case.
     >
     >     * Not in cache, in TLB: Memory access requires address
     translation,
     >     which comes back almost immediately as a fault.
     >
     >     * Not in cache, not in TLB: You have to do a page table walk
     before you
     >     can fetch the location, as you have to go out to physical
     memory (and
     >     therefore need a physical address).  The page table walk
will
Post by Warner Losh
     come back
     >     with a fault, stopping the attack.
     >
     >     So, unless I'm missing something here, both non-cached cases
     defeat the
     >     meltdown attack, as you *cannot* get the data unless you do
     address
     >     translation first (and therefore detect faults).
     >
     >     As for why this defeats the spectre attack, the logic is
     similar: you've
     >     jumped into someone else's executable code, hoping to
scoop up
Post by Warner Losh
     enough
     >     information into your branch predictor before the fault
kicks
Post by Warner Losh
     you out.
     >     However, to capture anything about sensitive information
in your
Post by Warner Losh
     >     side-channels, the transient instructions need to
actually get
Post by Warner Losh
     it into
     >     the core before a fault gets detected.  The same case
analysis
Post by Warner Losh
     as above
     >     applies, so you never actually get the sensitive info
into the
Post by Warner Losh
     core
     >     before a fault comes back and you get squashed.
     >
     >
     >     [1]: A physically-indexed cache would be largely immune to
     this attack,
     >     as you'd have to do address translation before doing a cache
     lookup.
     >
     >
     >     I have some ideas that can build on this, but I'd like
to get some
Post by Warner Losh
     >     feedback first.
     >     _______________________________________________
     >     mailing list
     >     https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
Post by Warner Losh
     <https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>
Post by Warner Losh
     >     <https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
Post by Warner Losh
     <https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>>
Post by Warner Losh
     >     To unsubscribe, send any mail to
     >     _______________________________________________
     mailing list
     >     https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
     <https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>
Post by Warner Losh
     >     <https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
     <https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>>
Post by Warner Losh
     >     To unsubscribe, send any mail to
     >
     >
Warner Losh
2018-01-05 23:24:14 UTC
Permalink
I mean the mappings we have in the kernel that map all of memory to a
specific page using 512GB pages in
sys/amd64/amd64/pmap.c:create_pagetables. This allows us to map any PA to a
VA with simple math rather than a page table walk.

Warner
Post by Eric McCorkle
I'm not sure what you mean by direct map. Do you mean TLB?
Post by Warner Losh
Wouldn't you have to also unmap it from the direct map for this to be
effective?
Warner
Well, the only way to find out would be to try it out.
However, unless I'm missing something, if you're trying to pull a
meltdown attack, you try and fetch from the kernel. If that location
isn't cached (or if your cache is physically indexed), you need the
physical address (otherwise you don't know where to look), and thus
have
Post by Warner Losh
to go through address translation, at which point you detect that the
page isn't accessible and fault. In the mean time, you can't
speculatively execute any of the operations that load up the
side-channels, because you don't have the sensitive data.
The reason you can pull off a meltdown attack at all is that a
virtually-indexed cache lets you get the data in parallel with
address
Post by Warner Losh
translation (breaking the dependency between address translation and
fetching data), which takes 1000s of cycles for a TLB miss, during
which
Post by Warner Losh
you have the data and can launch a whole bunch of transient ops.
Again, these are uncharted waters we're in; so it's entirely possible
I'm missing something here.
Post by Warner Losh
While you might be right, I've seen no indication that a cache miss
would defeat these attacks in the public and non-public data I've
looked
Post by Warner Losh
Post by Warner Losh
at, even though a large number of alternatives to the published
workarounds have been discussed. I'm therefore somewhat skeptical
this
Post by Warner Losh
Post by Warner Losh
would be effective. I'm open, however, to data that changes that
skepticism...
Warner
On Fri, Jan 5, 2018 at 3:15 PM, Eric McCorkle <
Right, but you have to get the value "foo" into the pipeline
in order
Post by Warner Losh
Post by Warner Losh
for it to affect the side-channels. This technique attempts
to stop
Post by Warner Losh
Post by Warner Losh
that from happening.
Unless I made a mistake, non-cached memory reads force address
translation to happen first, which detects faults and blocks
the
Post by Warner Losh
Post by Warner Losh
meltdown attack.
It also stops spectre with very high probability, as it's very
unlikely
Post by Warner Losh
Post by Warner Losh
that an uncached load will arrive before the speculative
thread gets
Post by Warner Losh
Post by Warner Losh
squashed.
Post by Warner Losh
I think this is fatally flawed.
The side channel is the cache. Not the data at risk.
Any mapped memory, cached or not, can be used to influence
the cache.
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Storing stuff in uncached memory won't affect the side
channel one bit.
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Basically, all attacks boil down to tricking the processor,
at elevated
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
privs, to doing something like
a = foo[offset];
where foo + offset are designed to communicate information
by populating
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
a cache line. offset need not be cached itself and can be
the result of
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
simple computations that depend on anything accessible at
all in the kernel.
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Warner
On Fri, Jan 5, 2018 at 3:02 PM, Eric McCorkle <
Re-posting to -hackers and -arch. I'm going to start
working on
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
something like this over the weekend.
-------- Forwarded Message --------
Subject: A more general possible meltdown/spectre
countermeasure
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Date: Thu, 4 Jan 2018 23:05:40 -0500
freebsd.org>>
freebsd.org>>>
freebsd.org>>
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
I've thought more about how to deal with
meltdown/spectre, and
Post by Warner Losh
I have an
Post by Warner Losh
idea I'd like to put forward. However, I'm still in
something
Post by Warner Losh
of a
Post by Warner Losh
panic mode, so I'm not certain as to its effectiveness.
Needless to
Post by Warner Losh
say, I welcome any feedback on this, and I may be
completely
Post by Warner Losh
Post by Warner Losh
off-base.
Post by Warner Losh
I'm calling this a "countermeasure" as opposed to a
"mitigation", as
Post by Warner Losh
it's something that requires modification of code as
opposed to a
Post by Warner Losh
Post by Warner Losh
drop-in patch.
== Summary ==
Provide a kernel and userland API by which memory
allocation
Post by Warner Losh
Post by Warner Losh
can be done
Post by Warner Losh
with extended attributes. In userland, this could be
accomplished by
Post by Warner Losh
extending MMAP flags, and I could imagine a
malloc-with-attributes flag.
Post by Warner Losh
In kernel space, this must already exist, as drivers
need to
Post by Warner Losh
allocate
Post by Warner Losh
memory with various MTRR-type attributes set.
The immediate aim here is to store sensitive information
that must
Post by Warner Losh
Post by Warner Losh
remain memory-resident in non-cacheable memory locations
(or,
Post by Warner Losh
if more
Post by Warner Losh
effective attribute combinations exist, using those
instead).
Post by Warner Losh
See the
Post by Warner Losh
rationale for the argument why this should work.
Assuming the rationale holds, then the attack surface
should
Post by Warner Losh
Post by Warner Losh
be greatly
Post by Warner Losh
reduced. Attackers would need to grab sensitive data
out of stack
Post by Warner Losh
Post by Warner Losh
frames or similar locations if/when it gets copied there
for
Post by Warner Losh
Post by Warner Losh
faster use.
Post by Warner Losh
Moreover, if this is done right, it could dovetail
nicely into a
Post by Warner Losh
Post by Warner Losh
framework for storing and processing sensitive assets in
more
Post by Warner Losh
secure
Post by Warner Losh
hardware[0] (like smart cards, the FPGAs I posted
earlier, or
Post by Warner Losh
other
Post by Warner Losh
options).
The obvious downside is that you take a performance hit
storing things
Post by Warner Losh
in non-cacheable locations, especially if you plan on
doing heavy
Post by Warner Losh
Post by Warner Losh
computation in that memory (say, encryption/decryption).
However, this
Post by Warner Losh
is almost certainly going to be less than the projected
30-50%
Post by Warner Losh
Post by Warner Losh
performance hit from other mitigations. Also, this
technique
Post by Warner Losh
should
Post by Warner Losh
work against spectre as well as meltdown (assuming the
rationale holds).
Post by Warner Losh
The second downside is that you have to modify code for
this
Post by Warner Losh
Post by Warner Losh
to work,
Post by Warner Losh
and you have to be careful not to keep copies of
sensitive
Post by Warner Losh
Post by Warner Losh
information
Post by Warner Losh
around too long (this gets tricky in userland, where you
might get
Post by Warner Losh
Post by Warner Losh
interrupted and switched out).
[0]: Full disclosure, enabling open hardware
implementations
Post by Warner Losh
Post by Warner Losh
of this
Post by Warner Losh
kind of thing is something of an agenda of mine.
== Rationale ==
(Again, I'm tired, rushed, and somewhat panicked so my
logic
Post by Warner Losh
Post by Warner Losh
could be
Post by Warner Losh
faulty at any point, so please point it out if it is)
The rationale for why this should work relies on
assumptions about
Post by Warner Losh
Post by Warner Losh
out-of-order pipelines that cannot be guaranteed to
hold, but are
Post by Warner Losh
Post by Warner Losh
extremely likely to be true.
As background, these attacks depend on out-of-order
execution
Post by Warner Losh
performing
Post by Warner Losh
operations that end up affecting cache and
branch-prediction
Post by Warner Losh
Post by Warner Losh
state,
Post by Warner Losh
ultimately storing information about sensitive data in
these
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
side-channels before the fault conditions are detected
and
Post by Warner Losh
Post by Warner Losh
acted upon.
Post by Warner Losh
I'll borrow terminology from the paper, using "transient
instructions"
Post by Warner Losh
to refer to speculatively executed instructions that will
eventually be
Post by Warner Losh
cancelled by a fault.
These attacks depend entirely on transient instructions
being
Post by Warner Losh
able to
Post by Warner Losh
get sensitive information into the processor core and
then
Post by Warner Losh
Post by Warner Losh
perform some
Post by Warner Losh
kind of instruction on them before the fault condition
cancels
Post by Warner Losh
them.
Post by Warner Losh
Therefore, anything that prevents them from doing this
*should* counter
Post by Warner Losh
the attack. If the actual sensitive data never makes it
to
Post by Warner Losh
Post by Warner Losh
the core
Post by Warner Losh
before the fault is detected, the dependent memory
accesses/branches
Post by Warner Losh
never get executed and the data never makes it to the
side-channels.
Post by Warner Losh
Another assumption here is that CPU architects are going
to
Post by Warner Losh
Post by Warner Losh
want to
Post by Warner Losh
squash faulted instructions ASAP and stop issuing along
those
Post by Warner Losh
Post by Warner Losh
speculative branches, so as to reclaim execution units.
So
Post by Warner Losh
Post by Warner Losh
I'm assuming
Post by Warner Losh
once a fault comes back from address translation, then
transient
Post by Warner Losh
Post by Warner Losh
execution stops dead.
Now, break down the cases for whether the address
containing
Post by Warner Losh
Post by Warner Losh
sensitive
Post by Warner Losh
data is in cache and TLB or not. (I'm assuming here that
caches are
Post by Warner Losh
virtually-indexed, which enables cache lookups to bypass
address
Post by Warner Losh
Post by Warner Losh
translation.)
* In cache, in TLB: You end up basically racing between
the
Post by Warner Losh
Post by Warner Losh
cache and
Post by Warner Losh
TLB, which will very likely end up detecting the fault
before
Post by Warner Losh
the data
Post by Warner Losh
arrives, but at the very worst, you get one or two
cycles of
Post by Warner Losh
Post by Warner Losh
transient
Post by Warner Losh
instruction execution before the fault.
* In cache, not in TLB: Virtually-indexed tagged means
you get
Post by Warner Losh
a cache
Post by Warner Losh
lookup racing a page-table walk. The cache lookup beats
the
Post by Warner Losh
Post by Warner Losh
page table
Post by Warner Losh
walk by potentially hundreds (maybe thousands) of cycles,
giving you a
Post by Warner Losh
bunch of transient instructions before a fault gets
triggered. This is
Post by Warner Losh
the main attack case.
* Not in cache, in TLB: Memory access requires address
translation,
Post by Warner Losh
which comes back almost immediately as a fault.
* Not in cache, not in TLB: You have to do a page table
walk
Post by Warner Losh
Post by Warner Losh
before you
Post by Warner Losh
can fetch the location, as you have to go out to physical
memory (and
Post by Warner Losh
therefore need a physical address). The page table walk
will
Post by Warner Losh
come back
Post by Warner Losh
with a fault, stopping the attack.
So, unless I'm missing something here, both non-cached
cases
Post by Warner Losh
Post by Warner Losh
defeat the
Post by Warner Losh
meltdown attack, as you *cannot* get the data unless you
do
Post by Warner Losh
Post by Warner Losh
address
Post by Warner Losh
translation first (and therefore detect faults).
As for why this defeats the spectre attack, the logic is
similar: you've
Post by Warner Losh
jumped into someone else's executable code, hoping to
scoop up
Post by Warner Losh
enough
Post by Warner Losh
information into your branch predictor before the fault
kicks
Post by Warner Losh
you out.
Post by Warner Losh
However, to capture anything about sensitive information
in your
Post by Warner Losh
Post by Warner Losh
side-channels, the transient instructions need to
actually get
Post by Warner Losh
it into
Post by Warner Losh
the core before a fault gets detected. The same case
analysis
Post by Warner Losh
as above
Post by Warner Losh
applies, so you never actually get the sensitive info
into the
Post by Warner Losh
core
Post by Warner Losh
before a fault comes back and you get squashed.
[1]: A physically-indexed cache would be largely immune
to
Post by Warner Losh
Post by Warner Losh
this attack,
Post by Warner Losh
as you'd have to do address translation before doing a
cache
Post by Warner Losh
Post by Warner Losh
lookup.
Post by Warner Losh
I have some ideas that can build on this, but I'd like
to get some
Post by Warner Losh
Post by Warner Losh
feedback first.
_______________________________________________
freebsd.org>>>
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-
security
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>
Post by Warner Losh
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-
security
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>>
Post by Warner Losh
Post by Warner Losh
To unsubscribe, send any mail to
_______________________________________________
org>
Post by Warner Losh
Post by Warner Losh
mailing list
Post by Warner Losh
https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>
Post by Warner Losh
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>>
Post by Warner Losh
Post by Warner Losh
To unsubscribe, send any mail to
Eric McCorkle
2018-01-05 23:30:14 UTC
Permalink
Ah, superpages. I wouldn't think so. The cpu still has to do a page table walk (just stopping at the top level page table), and would discover that it's not accessible.
Post by Warner Losh
I mean the mappings we have in the kernel that map all of memory to a
specific page using 512GB pages in
sys/amd64/amd64/pmap.c:create_pagetables. This allows us to map any PA to a
VA with simple math rather than a page table walk.
Warner
Post by Eric McCorkle
I'm not sure what you mean by direct map. Do you mean TLB?
Post by Warner Losh
Wouldn't you have to also unmap it from the direct map for this to
be
Post by Eric McCorkle
Post by Warner Losh
effective?
Warner
Well, the only way to find out would be to try it out.
However, unless I'm missing something, if you're trying to pull
a
Post by Eric McCorkle
Post by Warner Losh
meltdown attack, you try and fetch from the kernel. If that
location
Post by Eric McCorkle
Post by Warner Losh
isn't cached (or if your cache is physically indexed), you need
the
Post by Eric McCorkle
Post by Warner Losh
physical address (otherwise you don't know where to look), and
thus
Post by Eric McCorkle
have
Post by Warner Losh
to go through address translation, at which point you detect
that the
Post by Eric McCorkle
Post by Warner Losh
page isn't accessible and fault. In the mean time, you can't
speculatively execute any of the operations that load up the
side-channels, because you don't have the sensitive data.
The reason you can pull off a meltdown attack at all is that a
virtually-indexed cache lets you get the data in parallel with
address
Post by Warner Losh
translation (breaking the dependency between address
translation and
Post by Eric McCorkle
Post by Warner Losh
fetching data), which takes 1000s of cycles for a TLB miss,
during
Post by Eric McCorkle
which
Post by Warner Losh
you have the data and can launch a whole bunch of transient
ops.
Post by Eric McCorkle
Post by Warner Losh
Again, these are uncharted waters we're in; so it's entirely
possible
Post by Eric McCorkle
Post by Warner Losh
I'm missing something here.
Post by Warner Losh
While you might be right, I've seen no indication that a
cache miss
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
would defeat these attacks in the public and non-public data
I've
Post by Eric McCorkle
looked
Post by Warner Losh
Post by Warner Losh
at, even though a large number of alternatives to the
published
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
workarounds have been discussed. I'm therefore somewhat
skeptical
Post by Eric McCorkle
this
Post by Warner Losh
Post by Warner Losh
would be effective. I'm open, however, to data that changes
that
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
skepticism...
Warner
On Fri, Jan 5, 2018 at 3:15 PM, Eric McCorkle <
Right, but you have to get the value "foo" into the
pipeline
Post by Eric McCorkle
in order
Post by Warner Losh
Post by Warner Losh
for it to affect the side-channels. This technique
attempts
Post by Eric McCorkle
to stop
Post by Warner Losh
Post by Warner Losh
that from happening.
Unless I made a mistake, non-cached memory reads force
address
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
translation to happen first, which detects faults and
blocks
Post by Eric McCorkle
the
Post by Warner Losh
Post by Warner Losh
meltdown attack.
It also stops spectre with very high probability, as it's
very
Post by Eric McCorkle
unlikely
Post by Warner Losh
Post by Warner Losh
that an uncached load will arrive before the speculative
thread gets
Post by Warner Losh
Post by Warner Losh
squashed.
Post by Warner Losh
I think this is fatally flawed.
The side channel is the cache. Not the data at risk.
Any mapped memory, cached or not, can be used to
influence
Post by Eric McCorkle
the cache.
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Storing stuff in uncached memory won't affect the side
channel one bit.
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Basically, all attacks boil down to tricking the
processor,
Post by Eric McCorkle
at elevated
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
privs, to doing something like
a = foo[offset];
where foo + offset are designed to communicate
information
Post by Eric McCorkle
by populating
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
a cache line. offset need not be cached itself and can
be
Post by Eric McCorkle
the result of
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
simple computations that depend on anything accessible
at
Post by Eric McCorkle
all in the kernel.
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Warner
On Fri, Jan 5, 2018 at 3:02 PM, Eric McCorkle <
Re-posting to -hackers and -arch. I'm going to
start
Post by Eric McCorkle
working on
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
something like this over the weekend.
-------- Forwarded Message --------
Subject: A more general possible meltdown/spectre
countermeasure
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Date: Thu, 4 Jan 2018 23:05:40 -0500
freebsd.org>>
freebsd.org>>>
freebsd.org>>
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
I've thought more about how to deal with
meltdown/spectre, and
Post by Warner Losh
I have an
Post by Warner Losh
idea I'd like to put forward. However, I'm still
in
Post by Eric McCorkle
Post by Warner Losh
something
Post by Warner Losh
of a
Post by Warner Losh
panic mode, so I'm not certain as to its
effectiveness.
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
Needless to
Post by Warner Losh
say, I welcome any feedback on this, and I may be
completely
Post by Warner Losh
Post by Warner Losh
off-base.
Post by Warner Losh
I'm calling this a "countermeasure" as opposed to a
"mitigation", as
Post by Warner Losh
it's something that requires modification of code
as
Post by Eric McCorkle
Post by Warner Losh
opposed to a
Post by Warner Losh
Post by Warner Losh
drop-in patch.
== Summary ==
Provide a kernel and userland API by which memory
allocation
Post by Warner Losh
Post by Warner Losh
can be done
Post by Warner Losh
with extended attributes. In userland, this could
be
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
accomplished by
Post by Warner Losh
extending MMAP flags, and I could imagine a
malloc-with-attributes flag.
Post by Warner Losh
In kernel space, this must already exist, as
drivers
Post by Eric McCorkle
Post by Warner Losh
need to
Post by Warner Losh
allocate
Post by Warner Losh
memory with various MTRR-type attributes set.
The immediate aim here is to store sensitive
information
Post by Eric McCorkle
Post by Warner Losh
that must
Post by Warner Losh
Post by Warner Losh
remain memory-resident in non-cacheable memory
locations
Post by Eric McCorkle
Post by Warner Losh
(or,
Post by Warner Losh
if more
Post by Warner Losh
effective attribute combinations exist, using those
instead).
Post by Warner Losh
See the
Post by Warner Losh
rationale for the argument why this should work.
Assuming the rationale holds, then the attack
surface
Post by Eric McCorkle
should
Post by Warner Losh
Post by Warner Losh
be greatly
Post by Warner Losh
reduced. Attackers would need to grab sensitive
data
Post by Eric McCorkle
Post by Warner Losh
out of stack
Post by Warner Losh
Post by Warner Losh
frames or similar locations if/when it gets copied
there
Post by Eric McCorkle
for
Post by Warner Losh
Post by Warner Losh
faster use.
Post by Warner Losh
Moreover, if this is done right, it could dovetail
nicely into a
Post by Warner Losh
Post by Warner Losh
framework for storing and processing sensitive
assets in
Post by Eric McCorkle
Post by Warner Losh
more
Post by Warner Losh
secure
Post by Warner Losh
hardware[0] (like smart cards, the FPGAs I posted
earlier, or
Post by Warner Losh
other
Post by Warner Losh
options).
The obvious downside is that you take a performance
hit
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
storing things
Post by Warner Losh
in non-cacheable locations, especially if you plan
on
Post by Eric McCorkle
Post by Warner Losh
doing heavy
Post by Warner Losh
Post by Warner Losh
computation in that memory (say,
encryption/decryption).
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
However, this
Post by Warner Losh
is almost certainly going to be less than the
projected
Post by Eric McCorkle
Post by Warner Losh
30-50%
Post by Warner Losh
Post by Warner Losh
performance hit from other mitigations. Also, this
technique
Post by Warner Losh
should
Post by Warner Losh
work against spectre as well as meltdown (assuming
the
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
rationale holds).
Post by Warner Losh
The second downside is that you have to modify code
for
Post by Eric McCorkle
this
Post by Warner Losh
Post by Warner Losh
to work,
Post by Warner Losh
and you have to be careful not to keep copies of
sensitive
Post by Warner Losh
Post by Warner Losh
information
Post by Warner Losh
around too long (this gets tricky in userland,
where you
Post by Eric McCorkle
Post by Warner Losh
might get
Post by Warner Losh
Post by Warner Losh
interrupted and switched out).
[0]: Full disclosure, enabling open hardware
implementations
Post by Warner Losh
Post by Warner Losh
of this
Post by Warner Losh
kind of thing is something of an agenda of mine.
== Rationale ==
(Again, I'm tired, rushed, and somewhat panicked so
my
Post by Eric McCorkle
logic
Post by Warner Losh
Post by Warner Losh
could be
Post by Warner Losh
faulty at any point, so please point it out if it
is)
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
The rationale for why this should work relies on
assumptions about
Post by Warner Losh
Post by Warner Losh
out-of-order pipelines that cannot be guaranteed to
hold, but are
Post by Warner Losh
Post by Warner Losh
extremely likely to be true.
As background, these attacks depend on out-of-order
execution
Post by Warner Losh
performing
Post by Warner Losh
operations that end up affecting cache and
branch-prediction
Post by Warner Losh
Post by Warner Losh
state,
Post by Warner Losh
ultimately storing information about sensitive data
in
Post by Eric McCorkle
these
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
side-channels before the fault conditions are
detected
Post by Eric McCorkle
and
Post by Warner Losh
Post by Warner Losh
acted upon.
Post by Warner Losh
I'll borrow terminology from the paper, using
"transient
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
instructions"
Post by Warner Losh
to refer to speculatively executed instructions
that will
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
eventually be
Post by Warner Losh
cancelled by a fault.
These attacks depend entirely on transient
instructions
Post by Eric McCorkle
Post by Warner Losh
being
Post by Warner Losh
able to
Post by Warner Losh
get sensitive information into the processor core
and
Post by Eric McCorkle
then
Post by Warner Losh
Post by Warner Losh
perform some
Post by Warner Losh
kind of instruction on them before the fault
condition
Post by Eric McCorkle
Post by Warner Losh
cancels
Post by Warner Losh
them.
Post by Warner Losh
Therefore, anything that prevents them from doing
this
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
*should* counter
Post by Warner Losh
the attack. If the actual sensitive data never
makes it
Post by Eric McCorkle
to
Post by Warner Losh
Post by Warner Losh
the core
Post by Warner Losh
before the fault is detected, the dependent memory
accesses/branches
Post by Warner Losh
never get executed and the data never makes it to
the
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
side-channels.
Post by Warner Losh
Another assumption here is that CPU architects are
going
Post by Eric McCorkle
to
Post by Warner Losh
Post by Warner Losh
want to
Post by Warner Losh
squash faulted instructions ASAP and stop issuing
along
Post by Eric McCorkle
Post by Warner Losh
those
Post by Warner Losh
Post by Warner Losh
speculative branches, so as to reclaim execution
units.
Post by Eric McCorkle
So
Post by Warner Losh
Post by Warner Losh
I'm assuming
Post by Warner Losh
once a fault comes back from address translation,
then
Post by Eric McCorkle
Post by Warner Losh
transient
Post by Warner Losh
Post by Warner Losh
execution stops dead.
Now, break down the cases for whether the address
containing
Post by Warner Losh
Post by Warner Losh
sensitive
Post by Warner Losh
data is in cache and TLB or not. (I'm assuming
here that
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
caches are
Post by Warner Losh
virtually-indexed, which enables cache lookups to
bypass
Post by Eric McCorkle
Post by Warner Losh
address
Post by Warner Losh
Post by Warner Losh
translation.)
* In cache, in TLB: You end up basically racing
between
Post by Eric McCorkle
the
Post by Warner Losh
Post by Warner Losh
cache and
Post by Warner Losh
TLB, which will very likely end up detecting the
fault
Post by Eric McCorkle
Post by Warner Losh
before
Post by Warner Losh
the data
Post by Warner Losh
arrives, but at the very worst, you get one or two
cycles of
Post by Warner Losh
Post by Warner Losh
transient
Post by Warner Losh
instruction execution before the fault.
* In cache, not in TLB: Virtually-indexed tagged
means
Post by Eric McCorkle
Post by Warner Losh
you get
Post by Warner Losh
a cache
Post by Warner Losh
lookup racing a page-table walk. The cache lookup
beats
Post by Eric McCorkle
the
Post by Warner Losh
Post by Warner Losh
page table
Post by Warner Losh
walk by potentially hundreds (maybe thousands) of
cycles,
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
giving you a
Post by Warner Losh
bunch of transient instructions before a fault gets
triggered. This is
Post by Warner Losh
the main attack case.
* Not in cache, in TLB: Memory access requires
address
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
translation,
Post by Warner Losh
which comes back almost immediately as a fault.
* Not in cache, not in TLB: You have to do a page
table
Post by Eric McCorkle
walk
Post by Warner Losh
Post by Warner Losh
before you
Post by Warner Losh
can fetch the location, as you have to go out to
physical
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
memory (and
Post by Warner Losh
therefore need a physical address). The page table
walk
Post by Eric McCorkle
Post by Warner Losh
will
Post by Warner Losh
come back
Post by Warner Losh
with a fault, stopping the attack.
So, unless I'm missing something here, both
non-cached
Post by Eric McCorkle
cases
Post by Warner Losh
Post by Warner Losh
defeat the
Post by Warner Losh
meltdown attack, as you *cannot* get the data
unless you
Post by Eric McCorkle
do
Post by Warner Losh
Post by Warner Losh
address
Post by Warner Losh
translation first (and therefore detect faults).
As for why this defeats the spectre attack, the
logic is
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
similar: you've
Post by Warner Losh
jumped into someone else's executable code, hoping
to
Post by Eric McCorkle
Post by Warner Losh
scoop up
Post by Warner Losh
enough
Post by Warner Losh
information into your branch predictor before the
fault
Post by Eric McCorkle
Post by Warner Losh
kicks
Post by Warner Losh
you out.
Post by Warner Losh
However, to capture anything about sensitive
information
Post by Eric McCorkle
Post by Warner Losh
in your
Post by Warner Losh
Post by Warner Losh
side-channels, the transient instructions need to
actually get
Post by Warner Losh
it into
Post by Warner Losh
the core before a fault gets detected. The same
case
Post by Eric McCorkle
Post by Warner Losh
analysis
Post by Warner Losh
as above
Post by Warner Losh
applies, so you never actually get the sensitive
info
Post by Eric McCorkle
Post by Warner Losh
into the
Post by Warner Losh
core
Post by Warner Losh
before a fault comes back and you get squashed.
[1]: A physically-indexed cache would be largely
immune
Post by Eric McCorkle
to
Post by Warner Losh
Post by Warner Losh
this attack,
Post by Warner Losh
as you'd have to do address translation before
doing a
Post by Eric McCorkle
cache
Post by Warner Losh
Post by Warner Losh
lookup.
Post by Warner Losh
I have some ideas that can build on this, but I'd
like
Post by Eric McCorkle
Post by Warner Losh
to get some
Post by Warner Losh
Post by Warner Losh
feedback first.
_______________________________________________
freebsd.org>>>
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-
security
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
<https://lists.freebsd.org/mailman/listinfo/freebsd-security
Post by Eric McCorkle
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>
<https://lists.freebsd.org/mailman/listinfo/freebsd-
Post by Eric McCorkle
security
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
<https://lists.freebsd.org/mailman/listinfo/freebsd-security
Post by Eric McCorkle
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>>
Post by Warner Losh
Post by Warner Losh
To unsubscribe, send any mail to
_______________________________________________
org>
Post by Warner Losh
Post by Warner Losh
mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-arch
Post by Eric McCorkle
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
Post by Eric McCorkle
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>>
Post by Warner Losh
Post by Warner Losh
To unsubscribe, send any mail to
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Nathan Dautenhahn
2018-01-06 04:32:59 UTC
Permalink
No this isn't quite superpages. There is a data structure that is a
direct map (DMAP) that deterministically maps all physical pages in
the system so that all physical pages are accessible through virtual
memory. The DMAP has some simple offset calculations allowing it to
find the right virtual address mapping (in the DMAP) for the physical
address.

The more important observation that Warner makes is that to mitigate
the problem you have to make sure you get all aliases to each secret.
How many exist for each one? How do you know you get them all? Can a
attacker create bogus mappings (like ret2dir attack) and then use the
new attacks?

Another solution, which would handle the more complex attack above, (I
know I'm piggybacking, not sure if that's bad) could be to partition a
subset of the kernel address space for secrets, and then map those in
only when needed, and flush out when done. I did some work a while
back on page table isolation and protection from potentially malicious
OSs called the nested kernel. I haven't reviewed these new
side-channel attacks in great detail yet, but I'm currently working on
pushing fine grained intra-address space isolation that might be a
nice solution for easily managing and subsets of kernel data.

The paper and associated code etc. is all linked on nestedkernel.org.
I think these attacks really motivate the nested kernel approach,
although we didn't consider secret protection from side-channels.

Cheers,
-- :: Nathan Dautenhahn :: --
Post by Eric McCorkle
Ah, superpages. I wouldn't think so. The cpu still has to do a page table walk (just stopping at the top level page table), and would discover that it's not accessible.
Post by Warner Losh
I mean the mappings we have in the kernel that map all of memory to a
specific page using 512GB pages in
sys/amd64/amd64/pmap.c:create_pagetables. This allows us to map any PA to a
VA with simple math rather than a page table walk.
Warner
Post by Eric McCorkle
I'm not sure what you mean by direct map. Do you mean TLB?
Post by Warner Losh
Wouldn't you have to also unmap it from the direct map for this to
be
Post by Eric McCorkle
Post by Warner Losh
effective?
Warner
Well, the only way to find out would be to try it out.
However, unless I'm missing something, if you're trying to pull
a
Post by Eric McCorkle
Post by Warner Losh
meltdown attack, you try and fetch from the kernel. If that
location
Post by Eric McCorkle
Post by Warner Losh
isn't cached (or if your cache is physically indexed), you need
the
Post by Eric McCorkle
Post by Warner Losh
physical address (otherwise you don't know where to look), and
thus
Post by Eric McCorkle
have
Post by Warner Losh
to go through address translation, at which point you detect
that the
Post by Eric McCorkle
Post by Warner Losh
page isn't accessible and fault. In the mean time, you can't
speculatively execute any of the operations that load up the
side-channels, because you don't have the sensitive data.
The reason you can pull off a meltdown attack at all is that a
virtually-indexed cache lets you get the data in parallel with
address
Post by Warner Losh
translation (breaking the dependency between address
translation and
Post by Eric McCorkle
Post by Warner Losh
fetching data), which takes 1000s of cycles for a TLB miss,
during
Post by Eric McCorkle
which
Post by Warner Losh
you have the data and can launch a whole bunch of transient
ops.
Post by Eric McCorkle
Post by Warner Losh
Again, these are uncharted waters we're in; so it's entirely
possible
Post by Eric McCorkle
Post by Warner Losh
I'm missing something here.
Post by Warner Losh
While you might be right, I've seen no indication that a
cache miss
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
would defeat these attacks in the public and non-public data
I've
Post by Eric McCorkle
looked
Post by Warner Losh
Post by Warner Losh
at, even though a large number of alternatives to the
published
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
workarounds have been discussed. I'm therefore somewhat
skeptical
Post by Eric McCorkle
this
Post by Warner Losh
Post by Warner Losh
would be effective. I'm open, however, to data that changes
that
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
skepticism...
Warner
On Fri, Jan 5, 2018 at 3:15 PM, Eric McCorkle <
Right, but you have to get the value "foo" into the
pipeline
Post by Eric McCorkle
in order
Post by Warner Losh
Post by Warner Losh
for it to affect the side-channels. This technique
attempts
Post by Eric McCorkle
to stop
Post by Warner Losh
Post by Warner Losh
that from happening.
Unless I made a mistake, non-cached memory reads force
address
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
translation to happen first, which detects faults and
blocks
Post by Eric McCorkle
the
Post by Warner Losh
Post by Warner Losh
meltdown attack.
It also stops spectre with very high probability, as it's
very
Post by Eric McCorkle
unlikely
Post by Warner Losh
Post by Warner Losh
that an uncached load will arrive before the speculative
thread gets
Post by Warner Losh
Post by Warner Losh
squashed.
Post by Warner Losh
I think this is fatally flawed.
The side channel is the cache. Not the data at risk.
Any mapped memory, cached or not, can be used to
influence
Post by Eric McCorkle
the cache.
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Storing stuff in uncached memory won't affect the side
channel one bit.
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Basically, all attacks boil down to tricking the
processor,
Post by Eric McCorkle
at elevated
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
privs, to doing something like
a = foo[offset];
where foo + offset are designed to communicate
information
Post by Eric McCorkle
by populating
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
a cache line. offset need not be cached itself and can
be
Post by Eric McCorkle
the result of
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
simple computations that depend on anything accessible
at
Post by Eric McCorkle
all in the kernel.
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Warner
On Fri, Jan 5, 2018 at 3:02 PM, Eric McCorkle <
Re-posting to -hackers and -arch. I'm going to
start
Post by Eric McCorkle
working on
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
something like this over the weekend.
-------- Forwarded Message --------
Subject: A more general possible meltdown/spectre
countermeasure
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
Date: Thu, 4 Jan 2018 23:05:40 -0500
freebsd.org>>
freebsd.org>>>
freebsd.org>>
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
I've thought more about how to deal with
meltdown/spectre, and
Post by Warner Losh
I have an
Post by Warner Losh
idea I'd like to put forward. However, I'm still
in
Post by Eric McCorkle
Post by Warner Losh
something
Post by Warner Losh
of a
Post by Warner Losh
panic mode, so I'm not certain as to its
effectiveness.
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
Needless to
Post by Warner Losh
say, I welcome any feedback on this, and I may be
completely
Post by Warner Losh
Post by Warner Losh
off-base.
Post by Warner Losh
I'm calling this a "countermeasure" as opposed to a
"mitigation", as
Post by Warner Losh
it's something that requires modification of code
as
Post by Eric McCorkle
Post by Warner Losh
opposed to a
Post by Warner Losh
Post by Warner Losh
drop-in patch.
== Summary ==
Provide a kernel and userland API by which memory
allocation
Post by Warner Losh
Post by Warner Losh
can be done
Post by Warner Losh
with extended attributes. In userland, this could
be
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
accomplished by
Post by Warner Losh
extending MMAP flags, and I could imagine a
malloc-with-attributes flag.
Post by Warner Losh
In kernel space, this must already exist, as
drivers
Post by Eric McCorkle
Post by Warner Losh
need to
Post by Warner Losh
allocate
Post by Warner Losh
memory with various MTRR-type attributes set.
The immediate aim here is to store sensitive
information
Post by Eric McCorkle
Post by Warner Losh
that must
Post by Warner Losh
Post by Warner Losh
remain memory-resident in non-cacheable memory
locations
Post by Eric McCorkle
Post by Warner Losh
(or,
Post by Warner Losh
if more
Post by Warner Losh
effective attribute combinations exist, using those
instead).
Post by Warner Losh
See the
Post by Warner Losh
rationale for the argument why this should work.
Assuming the rationale holds, then the attack
surface
Post by Eric McCorkle
should
Post by Warner Losh
Post by Warner Losh
be greatly
Post by Warner Losh
reduced. Attackers would need to grab sensitive
data
Post by Eric McCorkle
Post by Warner Losh
out of stack
Post by Warner Losh
Post by Warner Losh
frames or similar locations if/when it gets copied
there
Post by Eric McCorkle
for
Post by Warner Losh
Post by Warner Losh
faster use.
Post by Warner Losh
Moreover, if this is done right, it could dovetail
nicely into a
Post by Warner Losh
Post by Warner Losh
framework for storing and processing sensitive
assets in
Post by Eric McCorkle
Post by Warner Losh
more
Post by Warner Losh
secure
Post by Warner Losh
hardware[0] (like smart cards, the FPGAs I posted
earlier, or
Post by Warner Losh
other
Post by Warner Losh
options).
The obvious downside is that you take a performance
hit
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
storing things
Post by Warner Losh
in non-cacheable locations, especially if you plan
on
Post by Eric McCorkle
Post by Warner Losh
doing heavy
Post by Warner Losh
Post by Warner Losh
computation in that memory (say,
encryption/decryption).
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
However, this
Post by Warner Losh
is almost certainly going to be less than the
projected
Post by Eric McCorkle
Post by Warner Losh
30-50%
Post by Warner Losh
Post by Warner Losh
performance hit from other mitigations. Also, this
technique
Post by Warner Losh
should
Post by Warner Losh
work against spectre as well as meltdown (assuming
the
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
rationale holds).
Post by Warner Losh
The second downside is that you have to modify code
for
Post by Eric McCorkle
this
Post by Warner Losh
Post by Warner Losh
to work,
Post by Warner Losh
and you have to be careful not to keep copies of
sensitive
Post by Warner Losh
Post by Warner Losh
information
Post by Warner Losh
around too long (this gets tricky in userland,
where you
Post by Eric McCorkle
Post by Warner Losh
might get
Post by Warner Losh
Post by Warner Losh
interrupted and switched out).
[0]: Full disclosure, enabling open hardware
implementations
Post by Warner Losh
Post by Warner Losh
of this
Post by Warner Losh
kind of thing is something of an agenda of mine.
== Rationale ==
(Again, I'm tired, rushed, and somewhat panicked so
my
Post by Eric McCorkle
logic
Post by Warner Losh
Post by Warner Losh
could be
Post by Warner Losh
faulty at any point, so please point it out if it
is)
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
The rationale for why this should work relies on
assumptions about
Post by Warner Losh
Post by Warner Losh
out-of-order pipelines that cannot be guaranteed to
hold, but are
Post by Warner Losh
Post by Warner Losh
extremely likely to be true.
As background, these attacks depend on out-of-order
execution
Post by Warner Losh
performing
Post by Warner Losh
operations that end up affecting cache and
branch-prediction
Post by Warner Losh
Post by Warner Losh
state,
Post by Warner Losh
ultimately storing information about sensitive data
in
Post by Eric McCorkle
these
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
side-channels before the fault conditions are
detected
Post by Eric McCorkle
and
Post by Warner Losh
Post by Warner Losh
acted upon.
Post by Warner Losh
I'll borrow terminology from the paper, using
"transient
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
instructions"
Post by Warner Losh
to refer to speculatively executed instructions
that will
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
eventually be
Post by Warner Losh
cancelled by a fault.
These attacks depend entirely on transient
instructions
Post by Eric McCorkle
Post by Warner Losh
being
Post by Warner Losh
able to
Post by Warner Losh
get sensitive information into the processor core
and
Post by Eric McCorkle
then
Post by Warner Losh
Post by Warner Losh
perform some
Post by Warner Losh
kind of instruction on them before the fault
condition
Post by Eric McCorkle
Post by Warner Losh
cancels
Post by Warner Losh
them.
Post by Warner Losh
Therefore, anything that prevents them from doing
this
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
*should* counter
Post by Warner Losh
the attack. If the actual sensitive data never
makes it
Post by Eric McCorkle
to
Post by Warner Losh
Post by Warner Losh
the core
Post by Warner Losh
before the fault is detected, the dependent memory
accesses/branches
Post by Warner Losh
never get executed and the data never makes it to
the
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
side-channels.
Post by Warner Losh
Another assumption here is that CPU architects are
going
Post by Eric McCorkle
to
Post by Warner Losh
Post by Warner Losh
want to
Post by Warner Losh
squash faulted instructions ASAP and stop issuing
along
Post by Eric McCorkle
Post by Warner Losh
those
Post by Warner Losh
Post by Warner Losh
speculative branches, so as to reclaim execution
units.
Post by Eric McCorkle
So
Post by Warner Losh
Post by Warner Losh
I'm assuming
Post by Warner Losh
once a fault comes back from address translation,
then
Post by Eric McCorkle
Post by Warner Losh
transient
Post by Warner Losh
Post by Warner Losh
execution stops dead.
Now, break down the cases for whether the address
containing
Post by Warner Losh
Post by Warner Losh
sensitive
Post by Warner Losh
data is in cache and TLB or not. (I'm assuming
here that
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
caches are
Post by Warner Losh
virtually-indexed, which enables cache lookups to
bypass
Post by Eric McCorkle
Post by Warner Losh
address
Post by Warner Losh
Post by Warner Losh
translation.)
* In cache, in TLB: You end up basically racing
between
Post by Eric McCorkle
the
Post by Warner Losh
Post by Warner Losh
cache and
Post by Warner Losh
TLB, which will very likely end up detecting the
fault
Post by Eric McCorkle
Post by Warner Losh
before
Post by Warner Losh
the data
Post by Warner Losh
arrives, but at the very worst, you get one or two
cycles of
Post by Warner Losh
Post by Warner Losh
transient
Post by Warner Losh
instruction execution before the fault.
* In cache, not in TLB: Virtually-indexed tagged
means
Post by Eric McCorkle
Post by Warner Losh
you get
Post by Warner Losh
a cache
Post by Warner Losh
lookup racing a page-table walk. The cache lookup
beats
Post by Eric McCorkle
the
Post by Warner Losh
Post by Warner Losh
page table
Post by Warner Losh
walk by potentially hundreds (maybe thousands) of
cycles,
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
giving you a
Post by Warner Losh
bunch of transient instructions before a fault gets
triggered. This is
Post by Warner Losh
the main attack case.
* Not in cache, in TLB: Memory access requires
address
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
translation,
Post by Warner Losh
which comes back almost immediately as a fault.
* Not in cache, not in TLB: You have to do a page
table
Post by Eric McCorkle
walk
Post by Warner Losh
Post by Warner Losh
before you
Post by Warner Losh
can fetch the location, as you have to go out to
physical
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
memory (and
Post by Warner Losh
therefore need a physical address). The page table
walk
Post by Eric McCorkle
Post by Warner Losh
will
Post by Warner Losh
come back
Post by Warner Losh
with a fault, stopping the attack.
So, unless I'm missing something here, both
non-cached
Post by Eric McCorkle
cases
Post by Warner Losh
Post by Warner Losh
defeat the
Post by Warner Losh
meltdown attack, as you *cannot* get the data
unless you
Post by Eric McCorkle
do
Post by Warner Losh
Post by Warner Losh
address
Post by Warner Losh
translation first (and therefore detect faults).
As for why this defeats the spectre attack, the
logic is
Post by Eric McCorkle
Post by Warner Losh
Post by Warner Losh
similar: you've
Post by Warner Losh
jumped into someone else's executable code, hoping
to
Post by Eric McCorkle
Post by Warner Losh
scoop up
Post by Warner Losh
enough
Post by Warner Losh
information into your branch predictor before the
fault
Post by Eric McCorkle
Post by Warner Losh
kicks
Post by Warner Losh
you out.
Post by Warner Losh
However, to capture anything about sensitive
information
Post by Eric McCorkle
Post by Warner Losh
in your
Post by Warner Losh
Post by Warner Losh
side-channels, the transient instructions need to
actually get
Post by Warner Losh
it into
Post by Warner Losh
the core before a fault gets detected. The same
case
Post by Eric McCorkle
Post by Warner Losh
analysis
Post by Warner Losh
as above
Post by Warner Losh
applies, so you never actually get the sensitive
info
Post by Eric McCorkle
Post by Warner Losh
into the
Post by Warner Losh
core
Post by Warner Losh
before a fault comes back and you get squashed.
[1]: A physically-indexed cache would be largely
immune
Post by Eric McCorkle
to
Post by Warner Losh
Post by Warner Losh
this attack,
Post by Warner Losh
as you'd have to do address translation before
doing a
Post by Eric McCorkle
cache
Post by Warner Losh
Post by Warner Losh
lookup.
Post by Warner Losh
I have some ideas that can build on this, but I'd
like
Post by Eric McCorkle
Post by Warner Losh
to get some
Post by Warner Losh
Post by Warner Losh
feedback first.
_______________________________________________
freebsd.org>>>
Post by Warner Losh
Post by Warner Losh
Post by Warner Losh
mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-
security
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
<https://lists.freebsd.org/mailman/listinfo/freebsd-security
Post by Eric McCorkle
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>
<https://lists.freebsd.org/mailman/listinfo/freebsd-
Post by Eric McCorkle
security
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>
<https://lists.freebsd.org/mailman/listinfo/freebsd-security
Post by Eric McCorkle
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-security>>>
Post by Warner Losh
Post by Warner Losh
To unsubscribe, send any mail to
_______________________________________________
org>
Post by Warner Losh
Post by Warner Losh
mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-arch
Post by Eric McCorkle
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
Post by Eric McCorkle
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>
Post by Warner Losh
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch
<https://lists.freebsd.org/mailman/listinfo/freebsd-arch>>>
Post by Warner Losh
Post by Warner Losh
To unsubscribe, send any mail to
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
Eric McCorkle
2018-01-06 05:28:08 UTC
Permalink
Post by Nathan Dautenhahn
Another solution, which would handle the more complex attack above, (I
know I'm piggybacking, not sure if that's bad) could be to partition a
subset of the kernel address space for secrets, and then map those in
only when needed, and flush out when done. I did some work a while
back on page table isolation and protection from potentially malicious
OSs called the nested kernel. I haven't reviewed these new
side-channel attacks in great detail yet, but I'm currently working on
pushing fine grained intra-address space isolation that might be a
nice solution for easily managing and subsets of kernel data.
The paper and associated code etc. is all linked on nestedkernel.org.
I think these attacks really motivate the nested kernel approach,
although we didn't consider secret protection from side-channels.
This sounds more or less like what I had in mind: carve out some special
region of kernel space for sensitive information. Ideally, this could
be swapped out with an API for storing sensitive data in a secure device
(TPM, smart card, etc).

However, discussions of this approach over on the RISC-V lists suggest
that Intel apparently does some rather crazy things that end up
thwarting my proposed countermeasure. (Apparently, they don't
acknowledge faults until the faulting instruction *commits*, which means
any number of transients could have followed) I'll probably still put a
PoC together, but I fear it may not work on Intel.
Eric McCorkle
2018-01-06 16:12:10 UTC
Permalink
sorry for stupid question but for my understanding these attacks works
1) perform access to byte not allowed virtual address and use next
instruction to store relative to private space so cache is filled
depending on value that one shouldn't be able to access.
2) as kernel get trap on access violation it will generate SIGSEGV or
SIGBUS which is directed by application using signal(2) so it can be
ignored.
3) other part of code perform some timing magic and detects this way
where cache is filled - so byte  value can be guessed properly.
My question is - why simply any access attempts to kernel space cannot
generate SIGKILL? Of course it would harm program development, but as
today developers doesn't usually use timesharing machine but have
private computers, simple sysctl variable would suffice.
I'd thought of this myself. The problem is that the cache effects could
still be observed by another process.

While is doesn't defeat the attack, tt does still complicate attacks, so
I think it's worth considering.
Warner Losh
2018-01-06 16:31:42 UTC
Permalink
Post by Eric McCorkle
sorry for stupid question but for my understanding these attacks works
1) perform access to byte not allowed virtual address and use next
instruction to store relative to private space so cache is filled
depending on value that one shouldn't be able to access.
2) as kernel get trap on access violation it will generate SIGSEGV or
SIGBUS which is directed by application using signal(2) so it can be
ignored.
3) other part of code perform some timing magic and detects this way
where cache is filled - so byte value can be guessed properly.
My question is - why simply any access attempts to kernel space cannot
generate SIGKILL? Of course it would harm program development, but as
today developers doesn't usually use timesharing machine but have
private computers, simple sysctl variable would suffice.
I'd thought of this myself. The problem is that the cache effects could
still be observed by another process.
While is doesn't defeat the attack, tt does still complicate attacks, so
I think it's worth considering.
The problem is that the attempts to access kernel space are speculative.
There's no way to get the 'speculative trap' that would have been generated
had the code actually executed. There literally is no signal to the kernel
this just happened.

Warner
Wojciech Puchar
2018-01-06 16:53:37 UTC
Permalink
Post by Eric McCorkle
While is doesn't defeat the attack, tt does still complicate attacks, so
I think it's worth considering.
The problem is that the attempts to access kernel space are speculative. There's no way to get the 'speculative trap' that would
have been generated had the code actually executed. There literally is no signal to the kernel this just happened.
Warner 
f..k. so there are no real workarounds. Anyway - if CPU companies would be
honest they would replace at least all server CPUs that are on warranty
Warner Losh
2018-01-06 17:04:54 UTC
Permalink
Post by Eric McCorkle
While is doesn't defeat the attack, tt does still complicate
Post by Eric McCorkle
attacks, so
I think it's worth considering.
The problem is that the attempts to access kernel space are speculative.
There's no way to get the 'speculative trap' that would
have been generated had the code actually executed. There literally is no
signal to the kernel this just happened.
Warner
f..k. so there are no real workarounds. Anyway - if CPU companies would
be honest they would replace at least all server CPUs that are on warranty
The only workaround that's completely effective is to unmap all of kernel
memory when running in userland. It's a bit tricky because there's small
parts that have to stay mapped for various architectural reasons. This
means KASLR on these CPUs likely can never be effective since meltdown will
let you find what the trap address is and from that find the kernel (though
there's some rumblings that the indirection Linux is doing will suffice).

Warner
Gary Jennejohn
2018-01-06 19:00:20 UTC
Permalink
On Sat, 6 Jan 2018 10:04:54 -0700
Post by Warner Losh
Post by Eric McCorkle
While is doesn't defeat the attack, tt does still complicate
Post by Eric McCorkle
attacks, so
I think it's worth considering.
The problem is that the attempts to access kernel space are speculative.
There's no way to get the 'speculative trap' that would
have been generated had the code actually executed. There literally is no
signal to the kernel this just happened.
Warner
f..k. so there are no real workarounds. Anyway - if CPU companies would
be honest they would replace at least all server CPUs that are on warranty
The only workaround that's completely effective is to unmap all of kernel
memory when running in userland. It's a bit tricky because there's small
parts that have to stay mapped for various architectural reasons. This
means KASLR on these CPUs likely can never be effective since meltdown will
let you find what the trap address is and from that find the kernel (though
there's some rumblings that the indirection Linux is doing will suffice).
This point is addressed in one of the papers. KAISER only maps
small parts of the address space, which are apparently required
for special use, in both the kernel and user space. Otherwise,
the kernel and user space do not share any part of the memory map.

The conclusion in the paper is that, yes, a small part of memory
is still common to both the kernel and user space, but if KASLR
is used, then it will be very difficult to identify these ranges.
--
Gary Jennejohn
Wojciech Puchar
2018-01-06 20:41:52 UTC
Permalink
The only workaround that's completely effective is to unmap all of kernel memory when running in userland. It's a bit tricky because
this means on every syscall on interrupt:

- memcopy part of top level PTE on enter, bzero on exit
- TLB flush both on enter and exit.

IMHO it would make much more than 30% overhead in many cases. am i wrong?
there's small parts that have to stay mapped for various architectural reasons. This means KASLR on these CPUs likely can never be
effective since meltdown will let you find what the trap address is and from that find the kernel (though there's some rumblings
that the indirection Linux is doing will suffice).
Warner
Rang, Anton
2018-01-08 17:28:20 UTC
Permalink
The tables aren’t changed on each transition; rather, two page tables are maintained, one which has an entry for the kernel mappings at the top level and one which does not.

Then it’s simply a matter of changing which page table is examined (by writing to CR3) on transition.

If PCID is available, previously-used mappings can stay cached in the TLB through this, though they won’t be shared between user/kernel (so in general syscalls will incur an additional translation per buffer page).

Anton
Post by Wojciech Puchar
The only workaround that's completely effective is to unmap all of kernel memory when running in userland. It's a bit tricky because
- memcopy part of top level PTE on enter, bzero on exit
- TLB flush both on enter and exit.
IMHO it would make much more than 30% overhead in many cases. am i wrong?
there's small parts that have to stay mapped for various architectural reasons. This means KASLR on these CPUs likely can never be
effective since meltdown will let you find what the trap address is and from that find the kernel (though there's some rumblings
that the indirection Linux is doing will suffice).
Warner
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-arch
Loading...