All of lore.kernel.org
 help / color / mirror / Atom feed
From: valdis.kletnieks@vt.edu (valdis.kletnieks at vt.edu)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Fwd: How to change page permission from inside the kernel?
Date: Fri, 06 Jul 2018 22:06:39 -0400	[thread overview]
Message-ID: <148921.1530929199@turing-police.cc.vt.edu> (raw)
In-Reply-To: <CAAGnT3axsO59jTRc-3UDdeyPQ6b+OVS=G2x9Hm12J6Vg8E1W8g@mail.gmail.com>

On Sat, 07 Jul 2018 01:31:45 +0200, Ahmed Soliman said:

> > You missed the point - your protection can be bypassed without manipulating
> > a ROE page.
> Changing the virtual memory pointer table is ok but again these memory
> mappings will never
> make it to the TLB and will be caught during by KVM MMU because it
> will explicitly check both gva and gpa when resolving a gva so perhaps

Did you actually *check* that this will happen, or will KVM just say "Oh,
the VM changed their mapping" and go with the new mapping?

In other words, *prove* that they won't make it to the TLB - and while
you're at it, deal with the case where the TLB isn't the source of the
mapping (which is the case on every single TLB miss, where it has to
go consult the page tables for the mapping.  And given Intel chipset's
over-exuberant approach to speculative execution and pipelining, there's
a good chance that the instant the proper mapping is found from the page
tables, it's used to make the actual memory reference, while the TLB gets
updated after the fact.  Plus, a lot of that happens in hardware, without
KVM getting a chance to inspect things.

(I don't actually know how the TLB works - but the point is you'll have to go
reading the Intel and AMD processor manuals to get that part right...)

While you're reading it, look for the implications of the "load/store bypassing
cache" instructions - can you force a surprise by storing directly to main memory
for a page table entry that is in L3 cache on the other socket?  (Note that the
kernel has memory barriers all over the place to avoid such surprises - but
examine the converse, where malware intentionally doesn't use a barrier so
there's inconsistency between cache, memory, and registers)

I take it you assuming more special-case checking which will require patches
to the KVM side (at a minimum, the KVM needs to keep a list of pages that
should not be changed, and check that at every required point?

Bonus points for properly handling the case where KVM pages an ROE page
out of real memory, and then pages it back into a different page frame (unless
you want to claim it works like mlock() - at which point you need to consider
the implications of a guest permanently mlock()ing up to 16M or 32M or even more).

You might want to stop and ask yourself why the people who did all the W^X
code for the kernel didn't extend it another step and add your ROE scheme.. ;)




-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 486 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20180706/79016ee9/attachment.sig>

  reply	other threads:[~2018-07-07  2:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-06 18:06 How to change page permission from inside the kernel? Ahmed Soliman
2018-07-06 18:42 ` valdis.kletnieks at vt.edu
2018-07-06 19:29   ` Ahmed Soliman
2018-07-06 21:10     ` valdis.kletnieks at vt.edu
     [not found]       ` <CAAGnT3Ymh6EcdaLo=rGR4-oH0nYub8v9VCZaCtppyxxJAmh5Ag@mail.gmail.com>
2018-07-06 21:59         ` Fwd: " Ahmed Soliman
2018-07-06 22:32           ` valdis.kletnieks at vt.edu
2018-07-06 23:31             ` Ahmed Soliman
2018-07-07  2:06               ` valdis.kletnieks at vt.edu [this message]
2018-07-07  2:13     ` Rik van Riel
2018-07-07 11:05       ` Ahmed Soliman
2018-07-06 18:49 ` Ruben Safir

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=148921.1530929199@turing-police.cc.vt.edu \
    --to=valdis.kletnieks@vt.edu \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.