Multi-Key Total Memory Encryption API (MKTME)
Subsystems (14)
v2 cover Multi-Key Total Memory Encryption API (MKTME)
Hi Thomas, David,
Here is an updated RFC on the API's to support MKTME. (Multi-Key Total Memory Encryption)
This RFC presents the 2 API additions to support the creation and usage of memory encryption keys:
1) Kernel Key Service type "mktme"
2) System call encrypt_mprotect()
This patchset is built upon Kirill Shutemov's work for the core MKTME support.
David: Please let me know if the changes made, based on your review, are reasonable. I don't think that the new changes touch key service specific areas (much).
Thomas: Please provide feedback on encrypt_mprotect(). If not a review, then a direction check would be helpful.
I picked up a few more 'CCs this time in get_maintainer!
Thanks!
Alison
Changes in RFC2
Add a preparser to mktme key service. (dhowells)
Replace key serial no. with key struct point in mktme_map. (dhowells) Remove patch that inserts a special MKTME case in keyctl revoke. (dhowells) Updated key usage syntax in the documentation (Kai)
Replaced NO_PKEY, NO_KEYID with a single constant NO_KEY. (Jarkko) Clarified comments in changelog and code. (Jarkko)
Add clear, no-encrypt, and update key support.
Add mktme_savekeys (Patch 12 ) to give kernel permission to save key data. Add cpu hotplug support. (Patch 13)
Alison Schofield (13):
x86/mktme: Document the MKTME APIs
mm: Generalize the mprotect implementation to support extensions syscall/x86: Wire up a new system call for memory encryption keys x86/mm: Add helper functions for MKTME memory encryption keys x86/mm: Set KeyIDs in encrypted VMAs
mm: Add the encrypt_mprotect() system call
x86/mm: Add helpers for reference counting encrypted VMAs
mm: Use reference counting for encrypted VMAs
mm: Restrict memory encryption to anonymous VMA's keys/mktme: Add the MKTME Key Service type for memory encryption keys/mktme: Program memory encryption keys on a system wide basis keys/mktme: Save MKTME data if kernel cmdline parameter allows keys/mktme: Support CPU Hotplug for MKTME keys
Documentation/admin-guide/kernel-parameters.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 11 + Documentation/x86/mktme/index.rst | 11 + Documentation/x86/mktme/mktme_demo.rst | 53 +++ Documentation/x86/mktme/mktme_encrypt.rst | 58 +++ Documentation/x86/mktme/mktme_keys.rst | 109 +++++ Documentation/x86/mktme/mktme_overview.rst | 60 +++ arch/x86/Kconfig | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/x86/include/asm/mktme.h | 25 + arch/x86/mm/mktme.c | 179 ++++++++ fs/exec.c | 4 +- include/keys/mktme-type.h | 41 ++ include/linux/key.h | 2 + include/linux/mm.h | 11 +- include/linux/syscalls.h | 2 + include/uapi/asm-generic/unistd.h | 4 +- kernel/fork.c | 2 + kernel/sys_ni.c | 2 + mm/mprotect.c | 91 +++- security/keys/Kconfig | 11 + security/keys/Makefile | 1 + security/keys/mktme_keys.c | 580 ++++++++++++++++++++++++ 24 files changed, 1249 insertions(+), 12 deletions(-) create mode 100644 Documentation/x86/mktme/index.rst create mode 100644 Documentation/x86/mktme/mktme_demo.rst create mode 100644 Documentation/x86/mktme/mktme_encrypt.rst create mode 100644 Documentation/x86/mktme/mktme_keys.rst create mode 100644 Documentation/x86/mktme/mktme_overview.rst create mode 100644 include/keys/mktme-type.h create mode 100644 security/keys/mktme_keys.c
Signature · 1 line
2.14.1
RFC v2 1/13 x86/mktme: Document the MKTME APIs
This includes an overview, a section on each API: MTKME Keys and system call encrypt_mprotect(), and a demonstration program.
(Some of this info is destined for man pages.)
--- Documentation/x86/mktme/index.rst | 11 +++ Documentation/x86/mktme/mktme_demo.rst | 53 ++++++++++++++ Documentation/x86/mktme/mktme_encrypt.rst | 58 +++++++++++++++ Documentation/x86/mktme/mktme_keys.rst | 109 +++++++++++++++++++++++++++++ Documentation/x86/mktme/mktme_overview.rst | 60 ++++++++++++++++ 5 files changed, 291 insertions(+) create mode 100644 Documentation/x86/mktme/index.rst create mode 100644 Documentation/x86/mktme/mktme_demo.rst create mode 100644 Documentation/x86/mktme/mktme_encrypt.rst create mode 100644 Documentation/x86/mktme/mktme_keys.rst create mode 100644 Documentation/x86/mktme/mktme_overview.rst
Documentation/x86/mktme/index.rst new file +11 -0
@@ -0,0 +1,11 @@ + +============================================= +Multi-Key Total Memory Encryption (MKTME) API +============================================= + +.. toctree:: + + mktme_overview + mktme_keys + mktme_encrypt + mktme_demo
Documentation/x86/mktme/mktme_demo.rst new file +53 -0
53 lines not on this page · raw message
Documentation/x86/mktme/mktme_encrypt.rst new file +58 -0
58 lines not on this page · raw message
Documentation/x86/mktme/mktme_keys.rst new file +109 -0
109 lines not on this page · raw message
Documentation/x86/mktme/mktme_overview.rst new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.14.1
Re: [RFC v2 01/13] x86/mktme: Document the MKTME APIs
Quoted 3 lines · Alison Schofield
I realize you’re writing code to expose hardware behavior, but I’m not sure this really makes sense in this context.
Documentation/x86/mktme/mktme_keys.rst line 20
Quoted 11 lines
.
Documentation/x86/mktme/mktme_keys.rst new file +10
-0+ +Usage +----- + When using the Kernel Key Service to request an *mktme* key, + specify the *payload* as follows: + + type= + *user* User will supply the encryption key data. Use this + type to directly program a hardware encryption key. +
I think that “user” probably sense as a “key service” key, but I don’t think it is at all useful for non-persistent memory. Even if we take for granted that MKTME for anonymous memory is useful at all, “cpu” seems to be better in all respects.
Perhaps support for “user” should be tabled until there’s a design for how to use this for pmem? I imagine it would look quite a bit like dm-crypt. Advanced pmem filesystems could plausibly use different keys for different files, I suppose.
If “user” is dropped, I think a lot of the complexity goes away. Hotplug becomes automatic, right?
Quoted 1 line
+ *cpu* User requests a CPU generated encryption key.
Okay, maybe, but it’s still unclear to me exactly what the intended benefit is, though.
Documentation/x86/mktme/mktme_keys.rst line 28
Quoted 7 lines
Documentation/x86/mktme/mktme_keys.rst new file +7
-0+ The CPU generates and assigns an ephemeral key. + + *clear* User requests that a hardware encryption key be + cleared. This will clear the encryption key from + the hardware. On execution this hardware key gets + TME behavior. +
Why is this a key type? Shouldn’t the API to select a key just have an option to ask for no key to be used?
Documentation/x86/mktme/mktme_keys.rst line 31
Quoted 3 lines
Documentation/x86/mktme/mktme_keys.rst new file +3
-0+ *no-encrypt* + User requests that hardware does not encrypt + memory when this key is in use.
Same as above. If there’s a performance benefit, then there could be a way to ask for cleartext memory. Similarly, some pmem users may want a way to keep their pmem unencrypted.
—Andy
Re: [RFC v2 01/13] x86/mktme: Document the MKTME APIs
Quoted 6 lines · Andy Lutomirski
Quoted 3 lines · Alison Schofield
I realize you’re writing code to expose hardware behavior, but I’m not sure this really makes sense in this context.
Your observation is accurate. The Usage defined here is very closely aligned to the Intel MKTME Architecture spec. That's a starting point, but not the ending point. We need to implement the feature set that makes sense. More below...
Quoted 9 lines
Documentation/x86/mktme/mktme_keys.rst line 20
Quoted 5 lines
Documentation/x86/mktme/mktme_keys.rst new file +5
-0+ + type= + *user* User will supply the encryption key data. Use this + type to directly program a hardware encryption key. +I think that “user” probably sense as a “key service” key, but I don’t think it is at all useful for non-persistent memory. Even if we take for granted that MKTME for anonymous memory is useful at all, “cpu” seems to be better in all respects.
Quoted 3 lines
Perhaps support for “user” should be tabled until there’s a design for how to use this for pmem? I imagine it would look quite a bit like dm-crypt. Advanced pmem filesystems could plausibly use different keys for different files, I suppose.
If “user” is dropped, I think a lot of the complexity goes away. Hotplug becomes automatic, right?
Dropping 'user' type removes a great deal of complexity.
Let me follow up in 2 ways:
1) Find out when MKTME support for pmem is required.
2) Go back to the the requirements and get the justification for user type.
Quoted 4 lines
Quoted 2 lines
+ *cpu* User requests a CPU generated encryption key.
Okay, maybe, but it’s still unclear to me exactly what the intended benefit is, though.
*cpu* is the RANDOM key generated by the cpu. If there were no other options, then this would be default, and go away.
Quoted 7 lines
Documentation/x86/mktme/mktme_keys.rst line 28
Quoted 5 lines
Documentation/x86/mktme/mktme_keys.rst new file +5
-0+ *clear* User requests that a hardware encryption key be + cleared. This will clear the encryption key from + the hardware. On execution this hardware key gets + TME behavior. +Why is this a key type? Shouldn’t the API to select a key just have an option to ask for no key to be used?
The *clear* key has been requested in order to clear/erase the users key data that has been programmed into a hardware slot. User does not want to leave a slot programmed with their encryption data when they are done with it.
Quoted 5 lines
Documentation/x86/mktme/mktme_keys.rst line 31
Quoted 3 lines
Documentation/x86/mktme/mktme_keys.rst new file +3
-0+ *no-encrypt* + User requests that hardware does not encrypt + memory when this key is in use.Same as above. If there’s a performance benefit, then there could be a way to ask for cleartext memory. Similarly, some pmem users may want a way to keep their pmem unencrypted.
So, this is the way to ask for cleartext memory.
The entire system will be encrypted with the system wide TME Key. A subset of that will be protected with MKTME Keys.
If user wants, no encrypt, this *no-encrypt* is the way to do it.
Alison
Quoted 2 lines
—Andy
Andy Lutomirski
maintainerRe: [RFC v2 01/13] x86/mktme: Document the MKTME APIs
Quoted 48 lines
Quoted 9 lines · Alison Schofield
Quoted 1 line · Andy Lutomirski
On Dec 3, 2018, at 11:39 PM, Alison Schofield <[email protected]> wrote:
I realize you’re writing code to expose hardware behavior, but I’m not sure this really makes sense in this context.
Your observation is accurate. The Usage defined here is very closely aligned to the Intel MKTME Architecture spec. That's a starting point, but not the ending point. We need to implement the feature set that makes sense. More below...
Quoted 9 lines
Documentation/x86/mktme/mktme_keys.rst line 20
Quoted 5 lines
Documentation/x86/mktme/mktme_keys.rst new file +5
-0+ + type= + *user* User will supply the encryption key data. Use this + type to directly program a hardware encryption key. +I think that “user” probably sense as a “key service” key, but I don’t think it is at all useful for non-persistent memory. Even if we take for granted that MKTME for anonymous memory is useful at all, “cpu” seems to be better in all respects.
Quoted 3 lines
Perhaps support for “user” should be tabled until there’s a design for how to use this for pmem? I imagine it would look quite a bit like dm-crypt. Advanced pmem filesystems could plausibly use different keys for different files, I suppose.
If “user” is dropped, I think a lot of the complexity goes away. Hotplug becomes automatic, right?
Dropping 'user' type removes a great deal of complexity.
Let me follow up in 2 ways:
1) Find out when MKTME support for pmem is required.
2) Go back to the the requirements and get the justification for user type.Quoted 4 lines
Quoted 2 lines
+ *cpu* User requests a CPU generated encryption key.
Okay, maybe, but it’s still unclear to me exactly what the intended benefit is, though.
*cpu* is the RANDOM key generated by the cpu. If there were no other options, then this would be default, and go away.
Quoted 6 lines
Quoted 5 lines
Documentation/x86/mktme/mktme_keys.rst new file +5
-0+ *clear* User requests that a hardware encryption key be + cleared. This will clear the encryption key from + the hardware. On execution this hardware key gets + TME behavior. +
Quoted 6 lines
Quoted 1 line
Why is this a key type? Shouldn’t the API to select a key just have an option to ask for no key to be used?
The *clear* key has been requested in order to clear/erase the users key data that has been programmed into a hardware slot. User does not want to leave a slot programmed with their encryption data when they are done with it.
Can’t you just clear the key when the key is deleted by the user? Asking the user to allocate a *new* key and hope that it somehow ends up in the same spot seems like a poor design, especially if future hardware gains support for key slot virtualization in some way that makes the slot allocation more dynamic.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Documentation/x86/mktme/mktme_keys.rst new file +3
-0+ *no-encrypt* + User requests that hardware does not encrypt + memory when this key is in use.
Quoted 7 lines
Quoted 1 line
Same as above. If there’s a performance benefit, then there could be a way to ask for cleartext memory. Similarly, some pmem users may want a way to keep their pmem unencrypted.
So, this is the way to ask for cleartext memory.
The entire system will be encrypted with the system wide TME Key. A subset of that will be protected with MKTME Keys.
If user wants, no encrypt, this *no-encrypt* is the way to do it.
Understood. I’m saying that having a *key* (in the add_key sense) for it seems unnecessary. Whatever the final API for controlling the use of keys, adding an option to ask for clear text seems reasonable. This actually seems more useful for anonymous memory than the cpu-generates keys are IMO.
I do think that, before you invest too much time in perfecting the series with the current design, you should identify the use cases, make sure the use cases are valid, and figure out whether your API design is appropriate. After considerable head-scratching, I haven’t thought of a reason that explicit CPU generated keys are any better than the default TME key, at least in the absence of additional hardware support for locking down what code can use what key. The sole exception is that a key can be removed, which is probably faster than directly zeroing large amounts of data.
I understand that it would be very nice to say "hey, cloud customer, your VM has all its memory encrypted with a key that is unique to your VM", but that seems to be more or less just a platitude with no actual effect. Anyone who snoops the memory bus or steals a DIMM learns nothing unless they also take control of the CPU and can replay all the data into the CPU. On the other hand, anyone who can get the CPU to read from a given physical address (which seems like the most likely threat) can just get the CPU to decrypt any tenant's data. So, for example, if someone manages to write a couple of words to the EPT for one VM, then they can easily read another VM's data, MKTME or no MKTME, because the memory controller has no clue which VM initiated the access.
I suppose there's some smallish value in rotating the key every now and then to make old data non-replayable, but an attack that compromises the memory bus and only later compromises the CPU is a strange threat model.
Re: [RFC v2 01/13] x86/mktme: Document the MKTME APIs
In reply to Alison SchofieldSSdsbCBmb2N1cyBteSByZW1hcmtzIG5vdyB0b3dhcmRzIGRvY3VtZW50YXRpb24gYXMgSSBoYXZl IGxvdHMgb2YNCmNhdGNoaW5nIHVwIHRvIGRvIHdpdGggVE1FIDotKSBJJ2xsIGdpdmUgbW9yZSBm ZWVkYmFjayBvZiBhY3R1YWwgY29kZQ0KY2hhbmdlcyBvbmNlIHYxOCBvZiB0aGUgU0dYIHBhdGNo IHNldCBpcyBvdXQsIHB1bGwgcmVxdWVzdCBmb3IgVFBNIDQuMjENCmNoYW5nZXMgaXMgb3V0IGFu ZCBtYXliZSBhIG5ldyB2ZXJzaW9uIG9mIHRoaXMgcGF0Y2ggc2V0IGhhcyBiZWVuDQpyZWxlYXNl ZC4NCg0KUmlnaHQgbm93IHRvbyBtdWNoIG9uIG15IHNob3VsZGVycyB0byBnbyB0b28gZGVlcCB3 aXRoIHRoaXMgcGF0Y2ggc2V0Lg0KDQpPbiBNb24sIDIwMTgtMTItMDMgYXQgMjM6MzkgLTA4MDAs IEFsaXNvbiBTY2hvZmllbGQgd3JvdGU6DQo+IFRoaXMgaW5jbHVkZXMgYW4gb3ZlcnZpZXcsIGEg c2VjdGlvbiBvbiBlYWNoIEFQSTogTVRLTUUgS2V5cyBhbmQNCj4gc3lzdGVtIGNhbGwgZW5jcnlw dF9tcHJvdGVjdCgpLCBhbmQgYSBkZW1vbnN0cmF0aW9uIHByb2dyYW0uDQo+IA0KPiAoU29tZSBv ZiB0aGlzIGluZm8gaXMgZGVzdGluZWQgZm9yIG1hbiBwYWdlcy4pDQo+IA0KPiBDaGFuZ2UtSWQ6 IEkzNGRjOWZmMWExMzA4YzA1N2VjNGJiM2U2NTJjNGQ3Y2U2OTk1NjA2DQo+IFNpZ25lZC1vZm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S5lLiBjb21wbGV4aXR5IHdpdGhvdXQgZ2Fp bi4NCg0KPiArCVRoaXMgZG9jdW1lbnQgZG9lcyBub3QgaW50ZW5kIHRvIGRvY3VtZW50IEtLUywg YnV0IG9ubHkgdGhlDQo+ICsJTUtUTUUgdHlwZSBvZiB0aGUgS0tTLiBUaGUgb3B0aW9ucyBvZiB0 aGUgS0tTIGNhbiBiZSBncm91cGVkDQo+ICsJaW50byAyIGNsYXNzZXMgZm9yIHB1cnBvc2VzIG9m IHVuZGVyc3RhbmRpbmcgaG93IE1LVE1FIG9wZXJhdGVzDQo+ICsJd2l0aGluIHRoZSBicm9hZGVy IEtLUy4NCg0KTWF5YmUganVzdCBkZWxldGUgdGhpcyBwYXJhZ3JhcGg/IEkgdGhpbmsgaXQgaXMg anVzdCBzdGF0aW5nIHRoZQ0Kb2J2aW91cy4NCg0KSSB0aGluayB5b3UgbmVlZCB0aGlzIHBhcmFn cmFwaCBvbmx5IGJlY2F1c2UgeW91IGhhdmUgZGVwbG95ZWQgdGhpcw0KZG9jdW1lbnQgdG8gd3Jv bmcgcGxhY2UuIEJldHRlciBwYXRoIHdvdWxkIGJlDQoNCkRvY3VtZW50YXRpb24vc2VjdXJpdHkv a2V5cy9ta3RtZS5yc3QuDQoNCi9KYXJra28NCg=
RFC v2 2/13 mm: Generalize the mprotect implementation to support extensions
In reply to Alison SchofieldToday mprotect is implemented to support legacy mprotect behavior plus an extension for memory protection keys. Make it more generic so that it can support additional extensions in the future.
This is done is preparation for adding a new system call for memory encyption keys. The intent is that the new encrypted mprotect will be another extension to legacy mprotect.
--- mm/mprotect.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
mm/mprotect.c +6 -4
@@ -35,6 +35,8 @@#include "internal.h" +#define NO_KEY -1 +static unsigned long change_pte_range (struct vm_area_struct *vma,pmd_t *pmd,unsigned long addr,unsigned long end,pgprot_t newprot,int dirty_accountable,int prot_numa)
@@ -451,9 +453,9 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev, }/* -* pkey==-1 when doing a legacy mprotect() +* When pkey==NO_KEY we get legacy mprotect behavior here. */ -static int do_mprotect_pkey (unsigned long start,size_t len, +static int do_mprotect_ext (unsigned long start,size_t len,unsigned long prot,int pkey) {unsigned long nstart, end, tmp, reqprot;
@@ -577,7 +579,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, unsigned long, prot) { -return do_mprotect_pkey (start, len, prot,-1 ); +return do_mprotect_ext (start, len, prot,NO_KEY ); }#ifdef CONFIG_ARCH_HAS_PKEYS
@@ -585,7 +587,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, SYSCALL_DEFINE4(pkey_mprotect, unsigned long, start, size_t, len, unsigned long, prot, int, pkey) { -return do_mprotect_pkey (start, len, prot, pkey); +return do_mprotect_ext (start, len, prot, pkey); } SYSCALL_DEFINE2(pkey_alloc, unsigned long, flags, unsigned long, init_val)
Signature · 1 line
2.14.1
Re: [RFC v2 02/13] mm: Generalize the mprotect implementation to support extensions
T24gTW9uLCAyMDE4LTEyLTAzIGF0IDIzOjM5IC0wODAwLCBBbGlzb24gU2Nob2ZpZWxkIHdyb3Rl Og0KPiBUb2RheSBtcHJvdGVjdCBpcyBpbXBsZW1lbnRlZCB0byBzdXBwb3J0IGxlZ2FjeSBtcHJv dGVjdCBiZWhhdmlvcg0KPiBwbHVzIGFuIGV4dGVuc2lvbiBmb3IgbWVtb3J5IHByb3RlY3Rpb24g a2V5cy4gTWFrZSBpdCBtb3JlIGdlbmVyaWMNCj4gc28gdGhhdCBpdCBjYW4gc3VwcG9ydCBhZGRp dGlvbmFsIGV4dGVuc2lvbnMgaW4gdGhlIGZ1dHVyZS4NCj4gDQo+IFRoaXMgaXMgZG9uZSBpcyBw cmVwYXJhdGlvbiBmb3IgYWRkaW5nIGEgbmV3IHN5c3RlbSBjYWxsIGZvciBtZW1vcnkNCj4gZW5j eXB0aW9u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Cj4gICNpZmRlZiBD T05GSUdfQVJDSF9IQVNfUEtFWVMNCj4gQEAgLTU4NSw3ICs1ODcsNyBAQCBTWVNDQUxMX0RFRklO RTMobXByb3RlY3QsIHVuc2lnbmVkIGxvbmcsIHN0YXJ0LCBzaXplX3QsDQo+IGxlbiwNCj4gIFNZ U0NBTExfREVGSU5FNChwa2V5X21wcm90ZWN0LCB1bnNpZ25lZCBsb25nLCBzdGFydCwgc2l6ZV90 LCBsZW4sDQo+ICAJCXVuc2lnbmVkIGxvbmcsIHByb3QsIGludCwgcGtleSkNCj4gIHsNCj4gLQly ZXR1cm4gZG9fbXByb3RlY3RfcGtleShzdGFydCwgbGVuLCBwcm90LCBwa2V5KTsNCj4gKwlyZXR1 cm4gZG9fbXByb3RlY3RfZXh0KHN0YXJ0LCBsZW4sIHByb3QsIHBrZXkpOw0KPiAgfQ0KPiAgDQo+ ICBTWVNDQUxMX0RFRklORTIocGtleV9hbGxvYywgdW5zaWduZWQgbG9uZywgZmxhZ3MsIHVuc2ln bmVkIGxvbmcsIGluaXRfdmFsKQ0KDQpXb3VsZCBzcXVhc2ggdGhpcyB3aGF0ZXZlciB0aGlzIGlz IHJlcXVpcmVkIGZvci4gVGhpcyBzcGxpdCBtYWtlcw0KcmV2aWV3IG1vcmUgY29tcGxleCAoSU1I TykuDQoNCi9KYXJra28NCg=
RFC v2 3/13 syscall/x86: Wire up a new system call for memory encryption keys
In reply to Alison Schofieldencrypt_mprotect() is a new system call to support memory encryption.
It takes the same parameters as legacy mprotect, plus an additional key serial number that is mapped to an encryption keyid.
--- arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + include/linux/syscalls.h | 2 ++ include/uapi/asm-generic/unistd.h | 4 +++- kernel/sys_ni.c | 2 ++ 5 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -398,3 +398,4 @@ 384 i386 arch_prctl sys_arch_prctl __ia32_compat_sys_arch_prctl 385 i386 io_pgetevents sys_io_pgetevents __ia32_compat_sys_io_pgetevents 386 i386 rseq sys_rseq __ia32_sys_rseq +387 i386 encrypt_mprotect sys_encrypt_mprotect __ia32_sys_encrypt_mprotect
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -343,6 +343,7 @@ 332 common statx __x64_sys_statx 333 common io_pgetevents __x64_sys_io_pgetevents 334 common rseq __x64_sys_rseq +335 common encrypt_mprotect __x64_sys_encrypt_mprotect # # x32-specific system call numbers start at 512 to avoid cache impact
include/linux/syscalls.h +2 -0
@@ -907,6 +907,8 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags, unsigned mask, struct statx __user *buffer);asmlinkage long sys_rseq (struct rseq __user *rseq,uint32_t rseq_len,int flags,uint32_t sig); +asmlinkage long sys_encrypt_mprotect (unsigned long start,size_t len, +unsigned long prot,key_serial_t serial);/* * Architecture-specific system calls
include/uapi/asm-generic/unistd.h +3 -1
@@ -738,9 +738,11 @@ __SYSCALL(__NR_statx, sys_statx) __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents)#define __NR_rseq 293 __SYSCALL(__NR_rseq, sys_rseq) +#define __NR_encrypt_mprotect 294 +__SYSCALL(__NR_encrypt_mprotect, sys_encrypt_mprotect)#undef __NR_syscalls -#define __NR_syscalls 294 +#define __NR_syscalls 295/* * 32 bit systems traditionally used different
kernel/sys_ni.c +2 -0
@@ -336,6 +336,8 @@ COND_SYSCALL(pkey_mprotect);COND_SYSCALL (pkey_alloc);COND_SYSCALL (pkey_free); +/* multi-key total memory encryption keys */ +COND_SYSCALL (encrypt_mprotect);/* * Architecture specific weak syscall entries.
Signature · 1 line
2.14.1
RFC v2 4/13 x86/mm: Add helper functions for MKTME memory encryption keys
In reply to Alison SchofieldDefine a global mapping structure to manage the mapping of userspace Keys to hardware KeyIDs in MKTME (Multi-Key Total Memory Encryption). Implement helper functions that access this mapping structure.
The helpers will be used by these MKTME API's:
Quoted 2 lines
Key Service API:
security/keys/mktme_keys.c
encrypt_mprotect()system call:mm/mprotect.c
--- arch/x86/include/asm/mktme.h | 12 ++++++ arch/x86/mm/mktme.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+)
arch/x86/include/asm/mktme.h +12 -0
@@ -12,6 +12,18 @@ extern phys_addr_t mktme_keyid_mask;extern int mktme_nr_keyids;extern int mktme_keyid_shift; +/* Manage mappings between hardware KeyIDs and userspace Keys */ +extern int mktme_map_alloc (void ); +extern void mktme_map_free (void ); +extern void mktme_map_lock (void ); +extern void mktme_map_unlock (void ); +extern int mktme_map_mapped_keyids (void ); +extern void mktme_map_set_keyid (int keyid,void *key); +extern void mktme_map_free_keyid (int keyid); +extern int mktme_map_keyid_from_key (void *key); +extern void *mktme_map_key_from_keyid (int keyid); +extern int mktme_map_get_free_keyid (void ); +DECLARE_STATIC_KEY_FALSE (mktme_enabled_key);static inline bool mktme_enabled (void ) {
arch/x86/mm/mktme.c +91 -0
97 lines not on this page · raw message
Signature · 1 line
2.14.1
Peter Zijlstra
maintainerRe: [RFC v2 04/13] x86/mm: Add helper functions for MKTME memory encryption keys
arch/x86/mm/mktme.c int __vma_keyid(struct vm_area_struct *vma) · line 113
Quoted 7 lines · Alison Schofield
arch/x86/mm/mktme.c +7
-0+int mktme_map_keyid_from_key (void *key) +{ +int i; + +for (i =1 ; i <= mktme_nr_keyids; i++) +if (mktme_map->key[i] = key) +return i;
CodingStyle
arch/x86/mm/mktme.c int __vma_keyid(struct vm_area_struct *vma) · line 129
Quoted 10 lines
arch/x86/mm/mktme.c +10
-0+return 0 ; +} +int mktme_map_get_free_keyid (void ) +{ +int i; + +if (mktme_map->mapped_keyids < mktme_nr_keyids) { +for (i =1 ; i <= mktme_nr_keyids; i++) +if (mktme_map->key[i] =0 ) +return i;
CodingStyle
Quoted 3 lines
arch/x86/mm/mktme.c +3
-0+ } +return 0 ; +}
Re: [RFC v2 04/13] x86/mm: Add helper functions for MKTME memory encryption keys
Quoted 5 lines · Peter Zijlstra
On Mon, Dec 03, 2018 at 11:39:51PM -0800, Alison Schofield wrote:
CodingStyle
CodingStyle
Thanks Peter. I'll repair all the badly nested if statements.
Re: [RFC v2 04/13] x86/mm: Add helper functions for MKTME memory encryption keys
In reply to Alison SchofieldQuoted 8 lines · Alison Schofield
Define a global mapping structure to manage the mapping of userspace Keys to hardware KeyIDs in MKTME (Multi-Key Total Memory Encryption). Implement helper functions that access this mapping structure.
Why is a key “void *”? Who owns the memory? Can a real type be used?
Re: [RFC v2 04/13] x86/mm: Add helper functions for MKTME memory encryption keys
Quoted 11 lines · Andy Lutomirski
Quoted 8 lines · Alison Schofield
Define a global mapping structure to manage the mapping of userspace Keys to hardware KeyIDs in MKTME (Multi-Key Total Memory Encryption). Implement helper functions that access this mapping structure.
Why is a key “void *”? Who owns the memory? Can a real type be used?
It's of type "struct key" of the kernel key service. Replacing void w 'struct key'.
Re: [RFC v2 04/13] x86/mm: Add helper functions for MKTME memory encryption keys
In reply to Alison SchofieldT24gTW9uLCAyMDE4LTEyLTAzIGF0IDIzOjM5IC0wODAwLCBBbGlzb24gU2Nob2ZpZWxkIHdyb3Rl Og0KPiArZXh0ZXJuIGludCBta3RtZV9tYXBfYWxsb2Modm9pZCk7DQo+ICtleHRlcm4gdm9pZCBt a3RtZV9tYXBfZnJlZSh2b2lkKTsNCj4gK2V4dGVybiB2b2lkIG1rdG1lX21hcF9sb2NrKHZvaWQp Ow0KPiArZXh0ZXJuIHZvaWQgbWt0bWVfbWFwX3VubG9jayh2b2lkKTsNCj4gK2V4dGVybiBpbnQg bWt0bWVfbWFwX21hcHBlZF9rZXlpZHModm9pZCk7DQo+ICtleHRlcm4gdm9pZCBta3RtZV9tYXBf c2V0X2tleWlkKGludCBrZXlpZCwgdm9pZCAqa2V5KTsNCj4gK2V4dGVybiB2b2lkIG1rdG1lX21h cF9mcmVlX2tleWlkKGludCBrZXlpZCk7DQo+ICtleHRlcm4gaW50IG1rdG1lX21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0KDQpXaGF0IGFyZSAidXNl cnNwYWNlIEtleXMiIGFueXdheSBhbmQgd2h5IEtleSBhbmQgbm90IGtleT8NCg0KPiArICogU2Vy dmljZSBBUEkgYW5kIHRoZSBlbmNyeXB0X21wcm90ZWN0KCkgc3lzdGVtIGNhbGwuDQo+ICsgKi8N Cj4gKw0KPiArc3RydWN0IG1rdG1lX21hcHBpbmcgew0KPiArCXN0cnVjdCBtdXRleAlsb2NrOwkJ LyogcHJvdGVjdCB0aGlzIG1hcCAmIEhXIHN0YXRlICovDQo+ICsJdW5zaWduZWQgaW50CW1hcHBl ZF9rZXlpZHM7DQo+ICsJdm9pZAkJKmtleVtdOw0KPiArfTsNCg0KUGVyc29uYWxseSwgSSBwcmVm ZXIgbm90IHRvIGFsaWduIHN0cnVjdCBmaWVsZHMgKEkgZG8gYWxpZ24gZW51bXMNCmJlY2F1c2Ug dGhlcmUgaXQgbWFrZXMgbW9yZSBzZW5zZSkgYXMgb2Z0ZW4geW91IGVuZCB1cCByZWFsaWduaW5n DQpldmVyeXRoaW5nLg0KDQpEb2N1bWVudGF0aW9uIHdvdWxkIGJyaW5nIG1vcmUgY2xhcml0eS4g Rm9yIGV4YW1wbGUsIHdoYXQgZG9lcyBrZXlbXQ0KY29udGFpbiwgd2h5IHRoZXJlIGlzIGEgbG9j ayBhbmQgd2hhdCBtYXBwZWRfa2V5aWRzIGZpZWxkIGNvbnRhaW5zPw0KDQovSmFya2tvDQo
RFC v2 5/13 x86/mm: Set KeyIDs in encrypted VMAs
In reply to Alison SchofieldMKTME architecture requires the KeyID to be placed in PTE bits 51:46. To create an encrypted VMA, place the KeyID in the upper bits of vm_page_prot that matches the position of those PTE bits.
When the VMA is assigned a KeyID it is always considered a KeyID change. The VMA is either going from not encrypted to encrypted, or from encrypted with any KeyID to encrypted with any other KeyID. To make the change safely, remove the user pages held by the VMA and unlink the VMA's anonymous chain.
--- arch/x86/include/asm/mktme.h | 4 ++++ arch/x86/mm/mktme.c | 26 ++++++++++++++++++++++++++ include/linux/mm.h | 6 ++++++ 3 files changed, 36 insertions(+)
arch/x86/include/asm/mktme.h +4 -0
@@ -24,6 +24,10 @@ extern int mktme_map_keyid_from_key(void *key);extern void *mktme_map_key_from_keyid (int keyid);extern int mktme_map_get_free_keyid (void ); +/* Set the encryption keyid bits in a VMA */ +extern void mprotect_set_encrypt (struct vm_area_struct *vma,int newkeyid, +unsigned long start,unsigned long end); +DECLARE_STATIC_KEY_FALSE (mktme_enabled_key);static inline bool mktme_enabled (void ) {
arch/x86/mm/mktme.c +26 -0
@@ -1,5 +1,6 @@#include <linux/mm.h> #include <linux/highmem.h> +#include <linux/rmap.h> #include <asm/mktme.h> #include <asm/set_memory.h>
@@ -131,6 +132,31 @@ int mktme_map_get_free_keyid(void)return 0 ; } +/* Set the encryption keyid bits in a VMA */ +void mprotect_set_encrypt (struct vm_area_struct *vma,int newkeyid, +unsigned long start,unsigned long end) +{ +int oldkeyid =vma_keyid (vma); +pgprotval_t newprot; + +/* Unmap pages with old KeyID if there's any. */ +zap_page_range (vma, start, end - start); + +if (oldkeyid == newkeyid) +return ; + + newprot =pgprot_val (vma->vm_page_prot); + newprot &= ~mktme_keyid_mask; + newprot |= (unsigned long )newkeyid << mktme_keyid_shift; + vma->vm_page_prot =__pgprot (newprot); + +/* +* The VMA doesn't have any inherited pages. +* Start anon VMA tree from scratch. +*/ +unlink_anon_vmas (vma); +} +/* Prepare page to be used for encryption. Called from page allocator. */ void __prep_encrypted_page (struct page *page,int order,int keyid,bool zero) {
include/linux/mm.h +6 -0
@@ -2806,5 +2806,11 @@ void __init setup_nr_node_ids(void);static inline void setup_nr_node_ids (void ) {}#endif +#ifndef CONFIG_X86_INTEL_MKTME +static inline void mprotect_set_encrypt (struct vm_area_struct *vma, +int newkeyid, +unsigned long start, +unsigned long end) {} +#endif /* CONFIG_X86_INTEL_MKTME */ #endif /* __KERNEL__ */ #endif /* _LINUX_MM_H */
Signature · 1 line
2.14.1
Re: [RFC v2 05/13] x86/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mgNCj4gQEAgLTI4MDYsNSArMjgwNiwxMSBAQCB2b2lkIF9faW5pdCBzZXR1cF9ucl9ub2Rl X2lkcyh2b2lkKTsNCj4gIHN0YXRpYyBpbmxpbmUgdm9pZCBzZXR1cF9ucl9ub2RlX2lkcyh2b2lk KSB7fQ0KPiAgI2VuZGlmDQo+ICANCj4gKyNpZm5kZWYgQ09ORklHX1g4Nl9JTlRFTF9NS1RNRQ0K PiArc3RhdGljIGlubGluZSB2b2lkIG1wcm90ZWN0X3NldF9lbmNyeXB0KHN0cnVjdCB2bV9hcmVh X3N0cnVjdCAqdm1hLA0KPiArCQkJCQlpbnQgbmV3a2V5aWQsDQo+ICsJCQkJCXVuc2lnbmVkIGxv bmcgc3RhcnQsDQo+ICsJCQkJCXVuc2lnbmVkIGxvbmcgZW5kKSB7fQ0KDQpBZGQgYSBuZXcgbGlu ZSBhbmQNCg0Kew0KfQ0KDQoNCj4gKyNlbmRpZiAvKiBDT05GSUdfWDg2X0lOVEVMX01LVE1FICov DQo+ICAjZW5kaWYgLyogX19LRVJORUxfXyAqLw0KPiAgI2VuZGlmIC8qIF9MSU5VWF9NTV9IICov DQoNCi9KYXJra28NCg=
RFC v2 6/13 mm: Add the encrypt_mprotect() system call
In reply to Alison SchofieldImplement memory encryption with a new system call that is an extension of the legacy mprotect() system call.
In encrypt_mprotect the caller must pass a handle to a previously allocated and programmed encryption key. Validate the key and store the keyid bits in the vm_page_prot for each VMA in the protection range.
--- fs/exec.c | 4 ++-- include/linux/key.h | 2 ++ include/linux/mm.h | 3 ++- mm/mprotect.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 62 insertions(+), 10 deletions(-)
fs/exec.c +2 -2
@@ -752,8 +752,8 @@ int setup_arg_pages(struct linux_binprm *bprm, vm_flags |= mm->def_flags; vm_flags |=VM_STACK_INCOMPLETE_SETUP ; - ret =mprotect_fixup (vma, &prev, vma->vm_start, vma->vm_end, - vm_flags); + ret =mprotect_fixup (vma, &prev, vma->vm_start, vma->vm_end, vm_flags, +-1 );if (ret) goto out_unlock;BUG_ON (prev != vma);
include/linux/key.h +2 -0
@@ -346,6 +346,8 @@ static inline key_serial_t key_serial(const struct key *key)extern void key_set_timeout (struct key *,unsigned ); +extern key_ref_t lookup_user_key (key_serial_t id,unsigned long lflags, +key_perm_t perm);/* * The permissions required on a key that we're looking up. */
include/linux/mm.h +2 -1
@@ -1607,7 +1607,8 @@ extern unsigned long change_protection(struct vm_area_struct *vma, unsigned long int dirty_accountable, int prot_numa);extern int mprotect_fixup (struct vm_area_struct *vma,struct vm_area_struct **pprev,unsigned long start, -unsigned long end,unsigned long newflags); +unsigned long end,unsigned long newflags, +int newkeyid);/* * doesn't attempt to fault and will return short.
mm/mprotect.c +56 -7
116 lines not on this page · raw message
Signature · 1 line
2.14.1
Re: [RFC v2 06/13] mm: Add the encrypt_mprotect() system call
T24gTW9uLCAyMDE4LTEyLTAzIGF0IDIzOjM5IC0wODAwLCBBbGlzb24gU2Nob2ZpZWxkIHdyb3Rl Og0KPiBJbXBsZW1lbnQgbWVtb3J5IGVuY3J5cHRpb24gd2l0aCBhIG5ldyBzeXN0ZW0gY2FsbCB0 aGF0IGlzIGFuDQo+IGV4dGVuc2lvbiBvZiB0aGUgbGVnYWN5IG1wcm90ZWN0KCkgc3lzdGVtIGNh bGwuDQo+IA0KPiBJbiBlbmNyeXB0X21wcm90ZWN0IHRoZSBjYWxsZXIgbXVzdCBwYXNzIGEgaGFu ZGxlIHRvIGEgcHJldmlvdXNseQ0KPiBhbGxvY2F0ZWQgYW5kIHByb2dyYW1tZWQgZW5jcnlwdGlv biBrZXkuIFZhbGlkYXRlIHRoZSBrZXkgYW5kIHN0b3JlDQo+IHRoZSBrZXlpZCBiaXRzIGluIHRo ZSB2bV9wYWdlX3Byb3QgZm9yIGVhY2ggVk1BIGluIHRoZSBwcm90ZWN0aW9uDQo+IHJhbmdlLg0K PiANCj4gU2lnbmVkLW9mZi1ieTogQWxpc29uIFNjaG9maWVsZCA8YWxpc29uLnNjaG9maWVsZEBp bnRlbC5jb20+DQo+IFNpZ25lZC1vZmYtYnk6IEtpcmlsbCBBLiBTaHV0ZW1vdiA8a2lyaWxsLnNo dXRlbW92QGxpbnV4LmludGVsLmNvbT4NCg0KV2h5IHlvdSBkb24ndCB1c2UgdGhhdCBOT19LRVkg aW4gdGhpcyBwYXRjaD8NCg0KL0phcmtrbw0K
RFC v2 7/13 x86/mm: Add helpers for reference counting encrypted VMAs
In reply to Alison SchofieldIn order to safely manage the usage of memory encryption keys, VMAs using each KeyID need to be counted. This count allows the MKTME (Multi-Key Total Memory Encryption) Key Service to know when the KeyID resource is actually in use, or when it is idle and may be considered for reuse.
Define a global refcount_t array and provide helper functions to manipulate the counts.
--- arch/x86/include/asm/mktme.h | 9 +++++++ arch/x86/mm/mktme.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/mm.h | 2 ++ 3 files changed, 69 insertions(+)
arch/x86/include/asm/mktme.h +9 -0
@@ -28,6 +28,15 @@ extern int mktme_map_get_free_keyid(void);extern void mprotect_set_encrypt (struct vm_area_struct *vma,int newkeyid,unsigned long start,unsigned long end); +/* Manage the MTKME encrypt_count references */ +extern int mktme_alloc_encrypt_array (void ); +extern void mktme_free_encrypt_array (void ); +extern int mktme_read_encrypt_ref (int keyid); +extern void vma_get_encrypt_ref (struct vm_area_struct *vma); +extern void vma_put_encrypt_ref (struct vm_area_struct *vma); +extern void key_get_encrypt_ref (int keyid); +extern void key_put_encrypt_ref (int keyid); +DECLARE_STATIC_KEY_FALSE (mktme_enabled_key);static inline bool mktme_enabled (void ) {
arch/x86/mm/mktme.c +58 -0
64 lines not on this page · raw message
include/linux/mm.h +2 -0
@@ -2812,6 +2812,8 @@ static inline void mprotect_set_encrypt(struct vm_area_struct *vma, int newkeyid, unsigned long start, unsigned long end) {} +static inline void vma_get_encrypt_ref (struct vm_area_struct *vma) {} +static inline void vma_put_encrypt_ref (struct vm_area_struct *vma) {}#endif /* CONFIG_X86_INTEL_MKTME */ #endif /* __KERNEL__ */ #endif /* _LINUX_MM_H */
Signature · 1 line
2.14.1
Peter Zijlstra
maintainerRe: [RFC v2 07/13] x86/mm: Add helpers for reference counting encrypted VMAs
arch/x86/mm/mktme.c void mprotect_set_encrypt(struct vm_area_struct *vma, int newkeyid, · line 201
Quoted 8 lines · Alison Schofield
arch/x86/mm/mktme.c +8
-0+void vma_put_encrypt_ref (struct vm_area_struct *vma) +{ +if (vma_keyid (vma)) +if (refcount_dec_and_test (&encrypt_count[vma_keyid (vma)])) { +mktme_map_lock (); +mktme_map_free_keyid (vma_keyid (vma)); +mktme_map_unlock (); + }
This violates CodingStyle
arch/x86/mm/mktme.c void mprotect_set_encrypt(struct vm_area_struct *vma, int newkeyid, · line 212
Quoted 6 lines
arch/x86/mm/mktme.c +5
-0+} +void key_put_encrypt_ref (int keyid) +{ +if (refcount_dec_and_test (&encrypt_count[keyid])) { +mktme_map_lock ();
That smells like it wants to use refcount_dec_and_lock() instead.
arch/x86/mm/mktme.c void mprotect_set_encrypt(struct vm_area_struct *vma, int newkeyid, · line 216
Quoted 4 lines
arch/x86/mm/mktme.c +4
-0+mktme_map_free_keyid (keyid); +mktme_map_unlock (); + } +}
Also, if you write that like:
if (!refcount_dec_and_lock(&encrypt_count[keyid], &lock)) return;
you loose an indent level.
Re: [RFC v2 07/13] x86/mm: Add helpers for reference counting encrypted VMAs
Quoted 12 lines · Peter Zijlstra
arch/x86/mm/mktme.c void mprotect_set_encrypt(struct vm_area_struct *vma, int newkeyid, · line 201
Quoted 8 lines · Alison Schofield
arch/x86/mm/mktme.c +8
-0+void vma_put_encrypt_ref (struct vm_area_struct *vma) +{ +if (vma_keyid (vma)) +if (refcount_dec_and_test (&encrypt_count[vma_keyid (vma)])) { +mktme_map_lock (); +mktme_map_free_keyid (vma_keyid (vma)); +mktme_map_unlock (); + }This violates CodingStyle
Got it!
Will fix this and the other instances where you noticed poorly nested if statements.
Quoted 11 lines
arch/x86/mm/mktme.c void mprotect_set_encrypt(struct vm_area_struct *vma, int newkeyid, · line 212
Quoted 2 lines
arch/x86/mm/mktme.c +2
-0+if (refcount_dec_and_test (&encrypt_count[keyid])) { +mktme_map_lock ();That smells like it wants to use
refcount_dec_and_lock()instead.Also, if you write that like:
if (!refcount_dec_and_lock(&encrypt_count[keyid], &lock)) return;you loose an indent level.
Looks good! I need to make sure it's OK to switch to a spinlock to use the *_lock functions.
RFC v2 8/13 mm: Use reference counting for encrypted VMAs
In reply to Alison SchofieldThe MKTME (Multi-Key Total Memory Encryption) Key Service needs a reference count on encrypted VMAs. This reference count is used to determine when a hardware encryption keyid is in use, which in turn, tells the key service what operations can be safely performed with this keyid.
The approach is:
1) Increment/decrement the reference count during encrypt_mprotect() system call for initial or updated encryption on a VMA.
2) Piggy back on the new vm_area_dup/free() helpers. If the VMAs being duplicated, or freed are encrypted, adjust the reference count.
--- arch/x86/mm/mktme.c | 2 ++ kernel/fork.c | 2 ++ 2 files changed, 4 insertions(+)
arch/x86/mm/mktme.c +2 -0
@@ -145,10 +145,12 @@ void mprotect_set_encrypt(struct vm_area_struct *vma, int newkeyid,if (oldkeyid == newkeyid)return ; +vma_put_encrypt_ref (vma); newprot =pgprot_val (vma->vm_page_prot); newprot &= ~mktme_keyid_mask; newprot |= (unsigned long )newkeyid << mktme_keyid_shift; vma->vm_page_prot =__pgprot (newprot); +vma_get_encrypt_ref (vma);/* * The VMA doesn't have any inherited pages.
kernel/fork.c +2 -0
@@ -341,12 +341,14 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig)if (new) { *new = *orig;INIT_LIST_HEAD (&new->anon_vma_chain); +vma_get_encrypt_ref (new); }return new; }void vm_area_free (struct vm_area_struct *vma) { +vma_put_encrypt_ref (vma);kmem_cache_free (vm_area_cachep, vma); }
Signature · 1 line
2.14.1
RFC v2 9/13 mm: Restrict memory encryption to anonymous VMA's
In reply to Alison SchofieldMemory encryption is only supported for mappings that are ANONYMOUS. Test the entire range of VMA's in an encrypt_mprotect() request to make sure they all meet that requirement before encrypting any.
The encrypt_mprotect syscall will return -EINVAL and will not encrypt any VMA's if this check fails.
--- mm/mprotect.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
mm/mprotect.c +24 -0
@@ -345,6 +345,24 @@ static int prot_none_walk(struct vm_area_struct *vma, unsigned long start,return walk_page_range (start, end, &prot_none_walk); } +/* +* Encrypted mprotect is only supported on anonymous mappings. +* All VMA's in the requested range must be anonymous. If this +* test fails on any single VMA, the entire mprotect request fails. +*/ +bool mem_supports_encryption (struct vm_area_struct *vma,unsigned long end) +{ +struct vm_area_struct *test_vma = vma; + +do { +if (!vma_is_anonymous (test_vma)) +return false; + + test_vma = test_vma->vm_next; + }while (test_vma && test_vma->vm_start < end); +return true; +} + int mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev, unsigned long start, unsigned long end, unsigned long newflags,
@@ -531,6 +549,12 @@ static int do_mprotect_ext(unsigned long start, size_t len, goto out; } } + +if (keyid >0 && !mem_supports_encryption (vma, end)) { + error = -EINVAL ; + goto out; + } +if (start > vma->vm_start) prev = vma;
Signature · 1 line
2.14.1
Peter Zijlstra
maintainerRe: [RFC v2 09/13] mm: Restrict memory encryption to anonymous VMA's
Quoted 9 lines · Alison Schofield
Memory encryption is only supported for mappings that are ANONYMOUS. Test the entire range of VMA's in an
encrypt_mprotect()request to make sure they all meet that requirement before encrypting any.The
encrypt_mprotectsyscall will return-EINVALand will not encrypt any VMA's if this check fails.Signed-off-by Alison Schofield <[email protected]>Signed-off-by Kirill A. Shutemov <[email protected]>
That SoB doesn't make sense; per the From you wrote the patch and signed off on it, wth is Kirill's SoB doing there?
Quoted 5 lines
mm/mprotect.c +0
-0
mm/mprotect.c static int prot_none_walk(struct vm_area_struct *vma, unsigned long start, · line 353
Quoted 9 lines
mm/mprotect.c +6
-0@@ -345,6 +345,24 @@ static int prot_none_walk(struct vm_area_struct *vma, unsigned long start,return walk_page_range (start, end, &prot_none_walk); } +/* +* Encrypted mprotect is only supported on anonymous mappings. +* All VMA's in the requested range must be anonymous. If this +* test fails on any single VMA, the entire mprotect request fails. +*/ +bool mem_supports_encryption (struct vm_area_struct *vma,unsigned long end)
That's a 'weird' interface and cannot do what the comment says it should do.
mm/mprotect.c static int prot_none_walk(struct vm_area_struct *vma, unsigned long start, · line 355
Quoted 2 lines
mm/mprotect.c +2
-0+{ +struct vm_area_struct *test_vma = vma;
That variable is utterly pointless.
Quoted 8 lines
mm/mprotect.c +8
-0+do { +if (!vma_is_anonymous (test_vma)) +return false; + + test_vma = test_vma->vm_next; + }while (test_vma && test_vma->vm_start < end); +return true; +}
Re: [RFC v2 09/13] mm: Restrict memory encryption to anonymous VMA's
Quoted 8 lines · Peter Zijlstra
Quoted 5 lines
+ * Encrypted mprotect is only supported on anonymous mappings.
+ * All VMA's in the requested range must be anonymous. If this
+ * test fails on any single VMA, the entire mprotect request fails.
+ */
+boolmem_supports_encryption(struct vm_area_struct *vma, unsigned long end)That's a 'weird' interface and cannot do what the comment says it should do.
More please? With MKTME, only anonymous memory supports encryption. Is it the naming that's weird, or you don't see it doing what it says?
Quoted 3 lines
mm/mprotect.c static int prot_none_walk(struct vm_area_struct *vma, unsigned long start, · line 355
Quoted 1 line
mm/mprotect.c +1
-0+struct vm_area_struct *test_vma = vma;That variable is utterly pointless.
Got it. Will fix.
Thanks
Peter Zijlstra
maintainerRe: [RFC v2 09/13] mm: Restrict memory encryption to anonymous VMA's
Quoted 7 lines · Alison Schofield
Quoted 6 lines · Peter Zijlstra
Quoted 5 lines
+ * Encrypted mprotect is only supported on anonymous mappings.
+ * All VMA's in the requested range must be anonymous. If this
+ * test fails on any single VMA, the entire mprotect request fails.
+ */
+boolmem_supports_encryption(struct vm_area_struct *vma, unsigned long end)
Quoted 5 lines
Quoted 2 lines
That's a 'weird' interface and cannot do what the comment says it should do.
More please? With MKTME, only anonymous memory supports encryption. Is it the naming that's weird, or you don't see it doing what it says?
It's weird because you don't fully speficy the range -- ie. it cannot verify the vma argument. It is also weird because the start and end are not of the same type -- or rather, there is no start at all.
So while the comment talks about a range, there is not in fact a range (only the implied @start is somewhere inside @vma). The comment also states all vmas in the range, but again, because of a lack of range specification it cannot verify this statement.
Now, I don't necessarily object to the function and its implementation, but that comment is just plain misleading.
RFC v2 10/13 keys/mktme: Add the MKTME Key Service type for memory encryption
In reply to Alison SchofieldMKTME (Multi-Key Total Memory Encryption) is a technology that allows transparent memory encryption in upcoming Intel platforms. MKTME will support mulitple encryption domains, each having their own key. The main use case for the feature is virtual machine isolation. The API needs the flexibility to work for a wide range of uses.
The MKTME key service type manages the addition and removal of the memory encryption keys. It maps Userspace Keys to hardware KeyIDs. It programs the hardware with the user requested encryption options.
The only supported encryption algorithm is AES-XTS 128.
The MKTME key service is half of the MKTME API level solution. It pairs with a new memory encryption system call: encrypt_mprotect() that uses the keys to encrypt memory.
See Documentation/x86/mktme/mktme.rst
--- arch/x86/Kconfig | 1 + include/keys/mktme-type.h | 41 ++++++ security/keys/Kconfig | 11 ++ security/keys/Makefile | 1 + security/keys/mktme_keys.c | 339 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 393 insertions(+) create mode 100644 include/keys/mktme-type.h create mode 100644 security/keys/mktme_keys.c
arch/x86/Kconfig +1 -0
@@ -1531,6 +1531,7 @@ config X86_INTEL_MKTME bool "Intel Multi-Key Total Memory Encryption" select DYNAMIC_PHYSICAL_MASK select PAGE_EXTENSION + select MKTME_KEYS depends on X86_64 && CPU_SUP_INTEL ---help--- Say yes to enable support for Multi-Key Total Memory Encryption.
include/keys/mktme-type.h new file +41 -0
41 lines not on this page · raw message
security/keys/Kconfig +11 -0
@@ -101,3 +101,14 @@ config KEY_DH_OPERATIONS in the kernel. If you are unsure as to whether this is required, answer N. + +config MKTME_KEYS + bool "Multi-Key Total Memory Encryption Keys" + depends on KEYS && X86_INTEL_MKTME + help + This option provides support for Multi-Key Total Memory + Encryption (MKTME) on Intel platforms offering the feature. + MKTME allows userspace to manage the hardware encryption + keys through the kernel key services. + + If you are unsure as to whether this is required, answer N.
security/keys/Makefile +1 -0
@@ -30,3 +30,4 @@ obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += keyctl_pkey.o obj-$(CONFIG_BIG_KEYS) += big_key.o obj-$(CONFIG_TRUSTED_KEYS) += trusted.o obj-$(CONFIG_ENCRYPTED_KEYS) += encrypted-keys/ +obj-$(CONFIG_MKTME_KEYS) += mktme_keys.o
security/keys/mktme_keys.c new file +339 -0
339 lines not on this page · raw message
Signature · 1 line
2.14.1
Re: [RFC v2 10/13] keys/mktme: Add the MKTME Key Service type for memory encryption
T24gTW9uLCAyMDE4LTEyLTAzIGF0IDIzOjM5IC0wODAwLCBBbGlzb24gU2Nob2ZpZWxkIHdyb3Rl Og0KPiBNS1RNRSAoTXVsdGktS2V5IFRvdGFsIE1lbW9yeSBFbmNyeXB0aW9uKSBpcyBhIHRlY2hu b2xvZ3kgdGhhdCBhbGxvd3MNCj4gdHJhbnNwYXJlbnQgbWVtb3J5IGVuY3J5cHRpb24gaW4gdXBj b21pbmcgSW50ZWwgcGxhdGZvcm1zLiBNS1RNRSB3aWxsDQo+IHN1cHBvcnQgbXVsaXRwbGUgZW5j cnlwdGlvbiBkb21haW5zLCBlYWNoIGhhdmluZyB0aGVpciBvd24ga2V5LiBUaGUgbWFpbg0KPiB1 c2UgY2FzZSBmb3IgdGhlIGZlYXR1cmUgaXMgdmlydHVhbCBtYWNoaW5lIGlzb2xhdGlvbi4gVGhl IEFQSSBuZWVkcyB0aGUNCj4gZmxleGliaWxpdHkgdG8gd29yayBmb3IgYSB3aWRlIHJhbmdlIG9m IHVzZXMuDQoNClNvbWUsIG1heWJlIGJydXRhbCwgaG9uZXN0eSAoYXBvbG9naWVzKS4uLg0KDQpI YXZlIG5ldmVyIHJlYWxseSBnb3QgdGhlIGdyaXAgd2h5IGVpdGhlciBTTUUgb3IgVE1FIHdvdWxk IG1ha2UNCmlzb2xhdGlvbiBhbnkgYmV0dGVyLiBJZiB5b3Ug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heWJlIGJydXRhbCwgaG9uZXN0eSAo YXBvbG9naWVzKS4uLg0KPiANCj4gSGF2ZSBuZXZlciByZWFsbHkgZ290IHRoZSBncmlwIHdoeSBl aXRoZXIgU01FIG9yIFRNRSB3b3VsZCBtYWtlDQo+IGlzb2xhdGlvbiBhbnkgYmV0dGVyLiBJZiB5 b3UgY2FuIGJyZWFrIGludG8gaHlwZXJ2aXNvciwgeW91J2xsDQo+IGhhdmUgdGhlc2UgdG9vbHMg YXZhaWxhYmU6DQo+IA0KPiAxLiBSZWFkIHBhZ2UgKGluIGVuY3J5cHRlZCBmb3JtKS4NCj4gMi4g V3JpdGUgcGFnZSAoZm9yIGV4YW1wbGUgcmVwbGF5IGFzIHBhZ2VzIGFyZSBub3QgdmVyc2lvbmVk KS4NCj4gDQo+IHdpdGggYWxsIHRoZSBzaWRlLWNoYW5uZWwgcG9zc2liaWxpdGllcyBvZiBjb3Vy c2Ugc2luY2UgeW91IGNhbg0KPiBjb250cm9sIHRoZSBWTXMgKGluIHdoaWNoIGNvcmUgdGhleSBl eGVjdXRlIGV0Yy4pLg0KPiANCj4gSSd2ZSBzZWVuIG5vdyBTTUUgcHJlc2VudGF0aW9uIHRocmVl IHRpbWVzIGFuZCBpdCBhbHdheXMgbGVhdmVzDQo+IG1lIGFuIGVtcHR5IGZlZWxpbmcuIFRoaXMg ZmVlbHMgdGhlIHNhbWUgc2FtZS4NCg0KSS5lLiBuZWVkIHRvIHRlbGwgdmVyeSBleHBsaWNpdGx5 IHRoZSBzY2VuYXJpbyB3aGVyZSB0aGlzIHdpbGwNCmhlbHAuIE5vdCBzYXlpbmcgdGhhdCB0aGlz IHNob3VsZCByZXNvbHZlIGV2ZXJ5dGhpbmcgYnV0IGl0IG11c3QNCnJlc29sdmUgc29tZXRoaW5n Lg0KDQovSmFya2tvDQo
Re: [RFC v2 10/13] keys/mktme: Add the MKTME Key Service type for memory encryption
In reply to Sakkinen, JarkkoQuoted 11 lines · Jarkko
Quoted 5 lines · Alison Schofield
MKTME (Multi-Key Total Memory Encryption) is a technology that allows transparent memory encryption in upcoming Intel platforms. MKTME will support mulitple encryption domains, each having their own key. The main use case for the feature is virtual machine isolation. The API needs the flexibility to work for a wide range of uses.
Some, maybe brutal, honesty (apologies)...
Have never really got the grip why either SME or TME would make isolation any better. If you can break into hypervisor, you'll have these tools availabe:
For systems using MKTME, the hypervisor is within the "trust boundary".
From what I've read, it is a bit _more_ trusted than with AMD's scheme.
But, yes, if you can mount a successful arbitrary code execution attack against the MKTME hypervisor, you can defeat MKTME's protections. If the kernel creates non-encrypted mappings of memory that's being encrypted with MKTME, an arbitrary read primitive could also be a very valuable in defeating MKTME's protections. That's why Andy is proposing doing something like eXclusive-Page-Frame-Ownership (google XPFO).
Re: [RFC v2 10/13] keys/mktme: Add the MKTME Key Service type for memory encryption
T24gVGh1LCAyMDE4LTEyLTA2IGF0IDA3OjExIC0wODAwLCBEYXZlIEhhbnNlbiB3cm90ZToNCj4g T24gMTIvNi8xOCAxMjo1MSBBTSwgU2Fra2luZW4sIEphcmtrbyB3cm90ZToNCj4gPiBPbiBNb24s IDIwMTgtMTItMDMgYXQgMjM6MzkgLTA4MDAsIEFsaXNvbiBTY2hvZmllbGQgd3JvdGU6DQo+ID4g PiBNS1RNRSAoTXVsdGktS2V5IFRvdGFsIE1lbW9yeSBFbmNyeXB0aW9uKSBpcyBhIHRlY2hub2xv Z3kgdGhhdCBhbGxvd3MNCj4gPiA+IHRyYW5zcGFyZW50IG1lbW9yeSBlbmNyeXB0aW9uIGluIHVw Y29taW5nIEludGVsIHBsYXRmb3Jtcy4gTUtUTUUgd2lsbA0KPiA+ID4gc3VwcG9ydCBtdWxpdHBs ZSBlbmNyeXB0aW9uIGRvbWFpbnMsIGVhY2ggaGF2aW5nIHRoZWlyIG93biBrZXkuIFRoZSBtYWlu DQo+ID4gPiB1c2UgY2FzZSBmb3IgdGhlIGZlYXR1cmUgaXMgdmlydHVhbCBtYWNoaW5lIGlzb2xh dGlvbi4gVG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wcm90ZWN0aW9ucy4gIFRo YXQncyB3aHkgQW5keSBpcyBwcm9wb3NpbmcNCj4gZG9pbmcgc29tZXRoaW5nIGxpa2UgZVhjbHVz aXZlLVBhZ2UtRnJhbWUtT3duZXJzaGlwIChnb29nbGUgWFBGTykuDQoNClRoYW5rcywgSSB3YXMg bm90IGF3YXJlIG9mIFhQRk8gYnV0IEkgZm91bmQgYSBuaWNlIH4yIHBhZ2UgYXJ0aWNsZSBhYm91 dCBpdDoNCg0KaHR0cHM6Ly9sd24ubmV0L0FydGljbGVzLzcwMDY0Ny8NCg0KSSB0aGluayB0aGUg cGVyZm9ybWFuY2UgaGl0IGlzIHRoZSBuZWNlc3NhcnkgcHJpY2UgdG8gcGF5IChpZiB5b3Ugd2Fu dA0Kc29tZXRoaW5nIG1vcmUgb3BhcXVlIHRoYW4ganVzdCB0aGUgdXN1YWwgIm1pbGl0YXJ5IGdy YWRlIHNlY3VyaXR5IikuIEF0DQptaW5pbXVtLCBpdCBzaG91bGQgYmUgYW4gb3B0LWluIGZlYXR1 cmUuDQoNCi9KYXJra28NCg=
RFC v2 11/13 keys/mktme: Program memory encryption keys on a system wide basis
In reply to Alison SchofieldThe kernel manages the MKTME (Multi-Key Total Memory Encryption) Keys as a system wide single pool of keys. The hardware, however, manages the keys on a per physical package basis. Each physical package maintains a Key Table that all CPU's in that package share.
In order to maintain the consistent, system wide view that the kernel requires, program all physical packages during a key program request.
--- security/keys/mktme_keys.c | 61 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-)
security/keys/mktme_keys.c +60 -1
@@ -21,6 +21,7 @@#include "internal.h" struct kmem_cache *mktme_prog_cache;/* Hardware programming cache */ +cpumask_var_t mktme_leadcpus;/* one cpu per pkg to program keys */ static const char *const mktme_program_err[] = {"KeyID was successfully programmed" ,/* 0 */
@@ -59,6 +60,37 @@ static void mktme_destroy_key(struct key *key)key_put_encrypt_ref (mktme_map_keyid_from_key (key)); } +struct mktme_hw_program_info { +struct mktme_key_program *key_program; +unsigned long status; +}; + +/* Program a KeyID on a single package. */ +static void mktme_program_package (void *hw_program_info) +{ +struct mktme_hw_program_info *info = hw_program_info; +int ret; + + ret =mktme_key_program (info->key_program); +if (ret !=MKTME_PROG_SUCCESS ) +WRITE_ONCE (info->status, ret); +} + +/* Program a KeyID across the entire system. */ +static int mktme_program_system (struct mktme_key_program *key_program, +cpumask_var_t mktme_cpumask) +{ +struct mktme_hw_program_info info = { + .key_program = key_program, + .status =MKTME_PROG_SUCCESS , + }; +get_online_cpus (); +on_each_cpu_mask (mktme_cpumask, mktme_program_package, &info,1 ); +put_online_cpus (); + +return info.status; +} +/* Copy the payload to the HW programming structure and program this KeyID */ static int mktme_program_keyid (int keyid,struct mktme_payload *payload) {
@@ -84,7 +116,7 @@ static int mktme_program_keyid(int keyid, struct mktme_payload *payload) kprog->key_field_2[i] ^= kern_entropy[i]; } } - ret =mktme_key_program (kprog); + ret =mktme_program_system (kprog, mktme_leadcpus);kmem_cache_free (mktme_prog_cache, kprog);return ret; }
@@ -299,6 +331,28 @@ struct key_type key_type_mktme = { .destroy = mktme_destroy_key, }; +static int mktme_build_leadcpus_mask (void ) +{ +int online_cpu, mktme_cpu; +int online_pkgid, mktme_pkgid =-1 ; + +if (!zalloc_cpumask_var (&mktme_leadcpus,GFP_KERNEL )) +return -ENOMEM ; + +for_each_online_cpu (online_cpu) { + online_pkgid =topology_physical_package_id (online_cpu); + +for_each_cpu (mktme_cpu, mktme_leadcpus) { + mktme_pkgid =topology_physical_package_id (mktme_cpu); +if (mktme_pkgid == online_pkgid) +break ; + } +if (mktme_pkgid != online_pkgid) +cpumask_set_cpu (online_cpu, mktme_leadcpus); + } +return 0 ; +} +/* * Allocate the global mktme_map structure based on the available keyids. * Create a cache for the hardware structure. Initialize the encrypt_count
@@ -323,10 +377,15 @@ static int __init init_mktme(void)if (mktme_alloc_encrypt_array () <0 ) goto free_cache; +if (mktme_build_leadcpus_mask () <0 ) + goto free_array; + ret =register_key_type (&key_type_mktme);if (!ret)return ret;/* SUCCESS */ +free_cpumask_var (mktme_leadcpus); +free_array:mktme_free_encrypt_array (); free_cache:kmem_cache_destroy (mktme_prog_cache);
Signature · 1 line
2.14.1
Peter Zijlstra
maintainerRe: [RFC v2 11/13] keys/mktme: Program memory encryption keys on a system wide basis
Quoted 4 lines · Alison Schofield
security/keys/mktme_keys.c +4
-0+struct mktme_hw_program_info { +struct mktme_key_program *key_program; +unsigned long status; +};
security/keys/mktme_keys.c static void mktme_destroy_key(struct key *key) · line 76
Quoted 10 lines
security/keys/mktme_keys.c +10
-0+ +/* Program a KeyID on a single package. */ +static void mktme_program_package (void *hw_program_info) +{ +struct mktme_hw_program_info *info = hw_program_info; +int ret; + + ret =mktme_key_program (info->key_program); +if (ret !=MKTME_PROG_SUCCESS ) +WRITE_ONCE (info->status, ret);
What's the purpose of that WRITE_ONCE()?
Quoted 41 lines
security/keys/mktme_keys.c +26
-1+} + +/* Program a KeyID across the entire system. */ +static int mktme_program_system (struct mktme_key_program *key_program, +cpumask_var_t mktme_cpumask) +{ +struct mktme_hw_program_info info = { + .key_program = key_program, + .status =MKTME_PROG_SUCCESS , + }; +get_online_cpus (); +on_each_cpu_mask (mktme_cpumask, mktme_program_package, &info,1 ); +put_online_cpus (); + +return info.status; +} +/* Copy the payload to the HW programming structure and program this KeyID */ static int mktme_program_keyid (int keyid,struct mktme_payload *payload) {@@ -84,7 +116,7 @@ static int mktme_program_keyid(int keyid, struct mktme_payload *payload) kprog->key_field_2[i] ^= kern_entropy[i]; } } - ret =mktme_key_program (kprog); + ret =mktme_program_system (kprog, mktme_leadcpus);kmem_cache_free (mktme_prog_cache, kprog);return ret; }@@ -299,6 +331,28 @@ struct key_type key_type_mktme = { .destroy = mktme_destroy_key, }; +static int mktme_build_leadcpus_mask (void ) +{ +int online_cpu, mktme_cpu; +int online_pkgid, mktme_pkgid =-1 ; + +if (!zalloc_cpumask_var (&mktme_leadcpus,GFP_KERNEL )) +return -ENOMEM ; +
security/keys/mktme_keys.c struct key_type key_type_mktme = { · line 351
Quoted 10 lines
security/keys/mktme_keys.c +10
-0+for_each_online_cpu (online_cpu) { + online_pkgid =topology_physical_package_id (online_cpu); + +for_each_cpu (mktme_cpu, mktme_leadcpus) { + mktme_pkgid =topology_physical_package_id (mktme_cpu); +if (mktme_pkgid = online_pkgid) +break ; + } +if (mktme_pkgid != online_pkgid) +cpumask_set_cpu (online_cpu, mktme_leadcpus);
Do you really need LOCK prefixed bit set here?
security/keys/mktme_keys.c struct key_type key_type_mktme = { · line 354
Quoted 3 lines
security/keys/mktme_keys.c +3
-0+ } +return 0 ; +}
How is that serialized and kept relevant in the face of hotplug?
Also, do you really need O(n^2) to find the first occurence of a value in an array?
Re: [RFC v2 11/13] keys/mktme: Program memory encryption keys on a system wide basis
Quoted 18 lines · Peter Zijlstra
Quoted 4 lines · Alison Schofield
security/keys/mktme_keys.c +4
-0+struct mktme_hw_program_info { +struct mktme_key_program *key_program; +unsigned long status; +};security/keys/mktme_keys.c static void mktme_destroy_key(struct key *key) · line 76
Quoted 10 lines
security/keys/mktme_keys.c +10
-0+ +/* Program a KeyID on a single package. */ +static void mktme_program_package (void *hw_program_info) +{ +struct mktme_hw_program_info *info = hw_program_info; +int ret; + + ret =mktme_key_program (info->key_program); +if (ret !=MKTME_PROG_SUCCESS ) +WRITE_ONCE (info->status, ret);What's the purpose of that
WRITE_ONCE()?
[I suggested the code to Alison.]
Yes, you're right. Simple assignment will do.
Signature · 1 line
Kirill A. Shutemov
Re: [RFC v2 11/13] keys/mktme: Program memory encryption keys on a system wide basis
Quoted 20 lines · Kirill A. Shutemov
Quoted 18 lines · Peter Zijlstra
Quoted 4 lines · Alison Schofield
security/keys/mktme_keys.c +4
-0+struct mktme_hw_program_info { +struct mktme_key_program *key_program; +unsigned long status; +};security/keys/mktme_keys.c static void mktme_destroy_key(struct key *key) · line 76
Quoted 10 lines
security/keys/mktme_keys.c +10
-0+ +/* Program a KeyID on a single package. */ +static void mktme_program_package (void *hw_program_info) +{ +struct mktme_hw_program_info *info = hw_program_info; +int ret; + + ret =mktme_key_program (info->key_program); +if (ret !=MKTME_PROG_SUCCESS ) +WRITE_ONCE (info->status, ret);What's the purpose of that
WRITE_ONCE()?
Quoted 3 lines
[I suggested the code to Alison.]
Yes, you're right. Simple assignment will do.
Will do. Thanks!
Quoted 3 lines
Signature · 2 lines
-- Kirill A. Shutemov
Re: [RFC v2 11/13] keys/mktme: Program memory encryption keys on a system wide basis
In reply to Peter ZijlstraQuoted 14 lines · Peter Zijlstra
Quoted 12 lines · Alison Schofield
security/keys/mktme_keys.c +12
-0+static int mktme_build_leadcpus_mask (void ) +{ +int online_cpu, mktme_cpu; +int online_pkgid, mktme_pkgid =-1 ; + +if (!zalloc_cpumask_var (&mktme_leadcpus,GFP_KERNEL )) +return -ENOMEM ; + +for_each_online_cpu (online_cpu) { + online_pkgid =topology_physical_package_id (online_cpu); + +for_each_cpu (mktme_cpu, mktme_leadcpus) {
Quoted 8 lines
security/keys/mktme_keys.c struct key_type key_type_mktme = { · line 351
Quoted 6 lines
security/keys/mktme_keys.c +6
-0+ mktme_pkgid =topology_physical_package_id (mktme_cpu); +if (mktme_pkgid == online_pkgid) +break ; + } +if (mktme_pkgid != online_pkgid) +cpumask_set_cpu (online_cpu, mktme_leadcpus);Do you really need LOCK prefixed bit set here?
No. Changed to __cpumask_set_cpu(). Will check for other instances where I can skip LOCK prefix.
Quoted 1 line
How is that serialized and kept relevant in the face of hotplug?
mktme_leadcpus is updated on hotplug startup and teardowns.
Quoted 2 lines
Also, do you really need O(n^2) to find the first occurence of a value in an array?
How about this O(n)?
unsigned long *pkg_map;
int cpu, pkgid;
if (!zalloc_cpumask_var(&mktme_leadcpus, GFP_KERNEL))
return -ENOMEM;
pkg_map = bitmap_zalloc(topology_max_packages(), GFP_KERNEL);
if (!pkg_map) {
free_cpumask_var(mktme_leadcpus);
return -ENOMEM;
}
for_each_online_cpu(cpu) {
pkgid = topology_physical_package_id(cpu);
if (!test_and_set_bit(pkgid, pkg_map))
__cpumask_set_cpu(cpu, mktme_leadcpus);
}Peter Zijlstra
maintainerRe: [RFC v2 11/13] keys/mktme: Program memory encryption keys on a system wide basis
Quoted 23 lines · Alison Schofield
Quoted 14 lines · Peter Zijlstra
Quoted 12 lines · Alison Schofield
security/keys/mktme_keys.c +12
-0+static int mktme_build_leadcpus_mask (void ) +{ +int online_cpu, mktme_cpu; +int online_pkgid, mktme_pkgid =-1 ; + +if (!zalloc_cpumask_var (&mktme_leadcpus,GFP_KERNEL )) +return -ENOMEM ; + +for_each_online_cpu (online_cpu) { + online_pkgid =topology_physical_package_id (online_cpu); + +for_each_cpu (mktme_cpu, mktme_leadcpus) {Quoted 8 lines
security/keys/mktme_keys.c struct key_type key_type_mktme = { · line 351
Quoted 6 lines
security/keys/mktme_keys.c +6
-0+ mktme_pkgid =topology_physical_package_id (mktme_cpu); +if (mktme_pkgid = online_pkgid) +break ; + } +if (mktme_pkgid != online_pkgid) +cpumask_set_cpu (online_cpu, mktme_leadcpus);Do you really need LOCK prefixed bit set here?
Quoted 5 lines
No. Changed to
__cpumask_set_cpu(). Will check for other instances where I can skip LOCK prefix.Quoted 1 line
How is that serialized and kept relevant in the face of hotplug?
mktme_leadcpusis updated on hotplug startup and teardowns.
Not in this patch it is not. That is added in a subsequent patch, which means that during bisection hotplug is utterly wrecked if you happen to land between these patches, that is bad.
Quoted 5 lines
Quoted 2 lines
Also, do you really need O(n^2) to find the first occurence of a value in an array?
How about this O(n)?
Quoted 14 lines
unsigned long *pkg_map;
int cpu, pkgid;
if (!zalloc_cpumask_var(&mktme_leadcpus, GFP_KERNEL))
return -ENOMEM;
pkg_map = bitmap_zalloc(topology_max_packages(), GFP_KERNEL);
if (!pkg_map) {
free_cpumask_var(mktme_leadcpus);
return -ENOMEM;
}
for_each_online_cpu(cpu) {
pkgid = topology_physical_package_id(cpu);
if (!test_and_set_bit(pkgid, pkg_map))You again don't need that LOCK prefix here.
__test_and_set_bit() :-)
Quoted 2 lines
__cpumask_set_cpu(cpu, mktme_leadcpus); }
Right.
Re: [RFC v2 11/13] keys/mktme: Program memory encryption keys on a system wide basis
Quoted 11 lines · Peter Zijlstra
Quoted 5 lines · Alison Schofield
Quoted 3 lines · Peter Zijlstra
On Mon, Dec 03, 2018 at 11:39:58PM -0800, Alison Schofield wrote:
How is that serialized and kept relevant in the face of hotplug?
mktme_leadcpusis updated on hotplug startup and teardowns.Not in this patch it is not. That is added in a subsequent patch, which means that during bisection hotplug is utterly wrecked if you happen to land between these patches, that is bad.
The Key Service support is split between 4 main patches (10-13), but the dependencies go further back in the patchset.
If the bisect need outweighs any benefit from reviewing in pieces, then these patches can be squashed to a single patch:
keys/mktme: Add the MKTME Key Service type for memory encryption keys/mktme: Program memory encryption keys on a system wide basis keys/mktme: Save MKTME data if kernel cmdline parameter allows keys/mktme: Support CPU Hotplug for MKTME keys
Am I interpreting your point correctly?
Thanks,
Alison
RFC v2 12/13 keys/mktme: Save MKTME data if kernel cmdline parameter allows
In reply to Alison SchofieldMKTME (Multi-Key Total Memory Encryption) key payloads may include data encryption keys, tweak keys, and additional entropy bits. These are used to program the MKTME encryption hardware. By default, the kernel destroys this payload data once the hardware is programmed.
However, in order to fully support CPU Hotplug, saving the key data becomes important. The MKTME Key Service cannot allow a new physical package to come online unless it can program the new packages Key Table to match the Key Tables of all existing physical packages.
With CPU generated keys (a.k.a. random keys or ephemeral keys) the saving of user key data is not an issue. The kernel and MKTME hardware can generate strong encryption keys without recalling any user supplied data.
With USER directed keys (a.k.a. user type) saving the key programming data (data and tweak key) becomes an issue. The data and tweak keys are required to program those keys on a new physical package.
In preparation for adding CPU hotplug support:
Add an 'mktme_vault' where key data is stored.
Add 'mktme_savekeys' kernel command line parameter that directs what key data can be stored. If it is not set, kernel does not store users data key or tweak key.
Add 'mktme_bitmap_user_type' to track when USER type keys are in use. If no USER type keys are currently in use, a physical package may be brought online, despite the absence of 'mktme_savekeys'.
--- Documentation/admin-guide/kernel-parameters.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 11 +++++ arch/x86/mm/mktme.c | 2 + security/keys/mktme_keys.c | 65 +++++++++++++++++++++++++ 4 files changed, 79 insertions(+)
Documentation/admin-guide/kernel-parameters.rst +1 -0
@@ -120,6 +120,7 @@ parameter is applicable:: Documentation/m68k/kernel-options.txt. MDA MDA console support is enabled. MIPS MIPS architecture is enabled. + MKTME Multi-Key Total Memory Encryption is enabled. MOUSE Appropriate mouse support is enabled. MSI Message Signaled Interrupts (PCI). MTD MTD (Memory Technology Device) support is enabled.
Documentation/admin-guide/kernel-parameters.txt +11 -0
@@ -2497,6 +2497,17 @@ in the "bleeding edge" mini2440 support kernel at http://repo.or.cz/w/linux-2.6/mini2440.git + mktme_savekeys [X86, MKTME] When CONFIG_X86_INTEL_MKTME is set + this parameter allows the kernel to save the user + specified MKTME key payload. Saving this payload + means that the MKTME Key Service can always allows + the addition of new physical packages. If the + mktme_savekeys parameter is not present, users key + data will not be saved, and new physical packages + may only be added to the system if no user type + MKTME keys are in use. + See Documentation/x86/mktme.rst + mminit_loglevel= [KNL] When CONFIG_DEBUG_MEMORY_INIT is set, this parameter allows control of the logging verbosity for
arch/x86/mm/mktme.c +2 -0
@@ -99,10 +99,12 @@ void mktme_map_set_keyid(int keyid, void *key) mktme_map->mapped_keyids++; } +extern unsigned long *mktme_bitmap_user_type;void mktme_map_free_keyid (int keyid) { mktme_map->key[keyid] =0 ; mktme_map->mapped_keyids--; +clear_bit (keyid, mktme_bitmap_user_type); }int mktme_map_keyid_from_key (void *key)
security/keys/mktme_keys.c +65 -0
113 lines not on this page · raw message
Signature · 1 line
2.14.1
Peter Zijlstra
maintainerRe: [RFC v2 12/13] keys/mktme: Save MKTME data if kernel cmdline parameter allows
Quoted 1 line · Alison Schofield
Change-Id: If57414862f1ac131dd97e29bf4f3937ac33777f6
Does not belong in patches..
Re: [RFC v2 12/13] keys/mktme: Save MKTME data if kernel cmdline parameter allows
In reply to Alison SchofieldT24gTW9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2F2ZWtleXMnLg0KDQpPdmVyYWxsLCBJ IGFtIG5vdCBzdXJlIHdoZXRoZXIgc2F2aW5nIGtleSBpcyBnb29kIGlkZWEsIHNpbmNlIGl0IGJy ZWFrcyBjb2xkYm9vdCBhdHRhY2sgSU1ITy4gV2UNCm5lZWQgdG8gdHJhZGVvZmYgYmV0d2VlbiBz dXBwb3J0aW5nIENQVSBob3RwbHVnIGFuZCBzZWN1cml0eS4gSSBhbSBub3Qgc3VyZSB3aGV0aGVy IHN1cHBvcnRpbmcgQ1BVDQpob3RwbHVnIGlzIHRoYXQgaW1wb3J0YW50LCBzaW5jZSBmb3Igc29t ZSBvdGhlciBmZWF0dXJlcyBzdWNoIGFzIFNHWCwgd2UgZG9uJ3Qgc3VwcG9ydCBDUFUgaG90cGx1 Zw0KYW55d2F5Lg0KDQpBbHRlcm5hdGl2ZWx5LCB3ZSBjYW4gY2hvb3NlIHRvIHVzZSBwZXItc29j a2V0IGtleUlELCBidXQgbm90IHRvIHByb2dyYW0ga2V5SUQgZ2xvYmFsbHkgYWNyb3NzIGFsbA0K c29ja2V0cywgc28geW91IGRvbid0IGhhdmUgdG8gc2F2ZSBrZXkgd2hpbGUgc3RpbGwgc3VwcG9y dGluZyBDUFUgaG90cGx1Zy4NCg0KVGhhbmtzLA0KLUthaQ=
Re: [RFC v2 12/13] keys/mktme: Save MKTME data if kernel cmdline parameter allows
Quoted 1 line · Kai
On Mon, 2018-12-03 at 23:39 -0800, Alison Schofield wrote:
8< ------------
Quoted 6 lines
Quoted 6 lines
Add an '
mktme_vault' where key data is stored.Add '
mktme_savekeys' kernel command line parameter that directs what key data can be stored. If it is not set, kernel does not store users data key or tweak key.
Quoted 8 lines
Quoted 3 lines
Add '
mktme_bitmap_user_type' to track when USER type keys are in use. If no USER type keys are currently in use, a physical package may be brought online, despite the absence of 'mktme_savekeys'.Overall, I am not sure whether saving key is good idea, since it breaks coldboot attack IMHO. We need to tradeoff between supporting CPU hotplug and security. I am not sure whether supporting CPU hotplug is that important, since for some other features such as SGX, we don't support CPU hotplug anyway.
Yes, saving the key data exposes it in a cold boot attack.
Here we have 2 conflicting requirements. Do not save the data and support CPU hotplug. I don't think CPU hotplug support is budging! If the risk of offering the mktme_savekeys option is too dangerous, then we can't have user type keys.
Is mktme_savekeys options too risky to offer?
(That's not just a question for you Kai ;). I'll pursue too.)
Quoted 3 lines
Alternatively, we can choose to use per-socket keyID, but not to program keyID globally across all sockets, so you don't have to save key while still supporting CPU hotplug.
An alternative, with a lot of impact to the core linux support for MKTME. I don't think we need to go there. I'll leave this thought for a Kirill or Dave to perhaps elaborate on.
Alison
Quoted 3 lines
Thanks,
-Kai
Re: [RFC v2 12/13] keys/mktme: Save MKTME data if kernel cmdline parameter allows
In reply to Huang, KaiQuoted 32 lines · Kai
Quoted 23 lines · Alison Schofield
MKTME (Multi-Key Total Memory Encryption) key payloads may include data encryption keys, tweak keys, and additional entropy bits. These are used to program the MKTME encryption hardware. By default, the kernel destroys this payload data once the hardware is programmed.
However, in order to fully support CPU Hotplug, saving the key data becomes important. The MKTME Key Service cannot allow a new physical package to come online unless it can program the new packages Key Table to match the Key Tables of all existing physical packages.
With CPU generated keys (a.k.a. random keys or ephemeral keys) the saving of user key data is not an issue. The kernel and MKTME hardware can generate strong encryption keys without recalling any user supplied data.
With USER directed keys (a.k.a. user type) saving the key programming data (data and tweak key) becomes an issue. The data and tweak keys are required to program those keys on a new physical package.
In preparation for adding CPU hotplug support:
Add an '
mktme_vault' where key data is stored.Quoted 7 lines
Add '
mktme_savekeys' kernel command line parameter that directs what key data can be stored. If it is not set, kernel does not store users data key or tweak key.Add '
mktme_bitmap_user_type' to track when USER type keys are in use. If no USER type keys are currently in use, a physical package may be brought online, despite the absence of 'mktme_savekeys'.
Quoted 5 lines
Overall, I am not sure whether saving key is good idea, since it breaks coldboot attack IMHO. We need to tradeoff between supporting CPU hotplug and security. I am not sure whether supporting CPU hotplug is that important, since for some other features such as SGX, we don't support CPU hotplug anyway.
What is the application for saving the key anyway?
With my current knowledge, I'm not even sure what is the application for user provided keys.
/Jarkko
Re: [RFC v2 12/13] keys/mktme: Save MKTME data if kernel cmdline parameter allows
Quoted 39 lines · Jarkko Sakkinen
Quoted 32 lines · Kai
Quoted 23 lines · Alison Schofield
MKTME (Multi-Key Total Memory Encryption) key payloads may include data encryption keys, tweak keys, and additional entropy bits. These are used to program the MKTME encryption hardware. By default, the kernel destroys this payload data once the hardware is programmed.
However, in order to fully support CPU Hotplug, saving the key data becomes important. The MKTME Key Service cannot allow a new physical package to come online unless it can program the new packages Key Table to match the Key Tables of all existing physical packages.
With CPU generated keys (a.k.a. random keys or ephemeral keys) the saving of user key data is not an issue. The kernel and MKTME hardware can generate strong encryption keys without recalling any user supplied data.
With USER directed keys (a.k.a. user type) saving the key programming data (data and tweak key) becomes an issue. The data and tweak keys are required to program those keys on a new physical package.
In preparation for adding CPU hotplug support:
Add an '
mktme_vault' where key data is stored.Quoted 7 lines
Add '
mktme_savekeys' kernel command line parameter that directs what key data can be stored. If it is not set, kernel does not store users data key or tweak key.Add '
mktme_bitmap_user_type' to track when USER type keys are in use. If no USER type keys are currently in use, a physical package may be brought online, despite the absence of 'mktme_savekeys'.Quoted 5 lines
Overall, I am not sure whether saving key is good idea, since it breaks coldboot attack IMHO. We need to tradeoff between supporting CPU hotplug and security. I am not sure whether supporting CPU hotplug is that important, since for some other features such as SGX, we don't support CPU hotplug anyway.
Quoted 4 lines
What is the application for saving the key anyway?
With my current knowledge, I'm not even sure what is the application for user provided keys.
Ugh, right of course, you need to save the key in order to support hotplug.
Cold boot is like the main security use case for this (probably would be worth to mention this in the documentation).
/Jarkko
Re: [RFC v2 12/13] keys/mktme: Save MKTME data if kernel cmdline parameter allows
In reply to Huang, KaiQuoted 3 lines · Kai
Alternatively, we can choose to use per-socket keyID, but not to program keyID globally across all sockets, so you don't have to save key while still supporting CPU hotplug.
Per-socket KeyID approach would make things more complex. For instance KeyID on its own will not be enough to refer a key. You will need a node too. It will also require a way to track whether theirs an KeyID on other node for the key.
It also makes memory management less flexible: runtime migration of the memory between nodes will be limited and it can hurt memory availablity for non-encrypted tasks too.
In general, I don't see per-socket KeyID handling very attractive. It creates more problems than solves.
Signature · 1 line
Kirill A. Shutemov
RFC v2 13/13 keys/mktme: Support CPU Hotplug for MKTME keys
In reply to Alison SchofieldThe MKTME (Multi-Key Memory Encryption Keys) hardware resides on each physical package. The kernel maintains one Key Table on each physical package and these Key Tables must all remain in sync. (From here on, package means physical package.)
Although every CPU on that package has the ability to program the Key Table, the kernel uses one 'lead' cpu per package to program the Key Tables. Typically, keys are programmed one at a time, across all packages, as the 'add key' requests come in from userspace.
Some CPU hotplug scenarios are handled quite simply:
Quoted 5 lines
Teardown a non lead CPU --> do nothing
Teardown a lead CPU --> pick a new lead CPU
Teardown a lead/last CPU of a package --> forget this package Startup a CPU in a known package --> do nothing
Startup a CPU in a new package and no keys are programmed --> do nothing
Then there is the more interesting case for MKTME: a CPU is starting up for a new package and keys are programmed on the existing packages. The Key Table on the new package will need to be programmed to match the Key Tables on all existing packages.
The issue is whether or not the Key Service has the information it needs to program the new Key Table. To address this, a new kernel commandline parameter 'mktme_savekeys' was introduced in a previous patch. It allows the kernel to save the data needed to program keys, beyond their first add key request.
When 'mktme_savekeys' is not present, new packages may still be added if all currently programmed keys are not USER type. This means that CPU generated keys are an option for users not wanting to save key data, but who also want to support the addition of new packages.
--- security/keys/mktme_keys.c | 135 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 126 insertions(+), 9 deletions(-)
security/keys/mktme_keys.c +126 -9
@@ -86,21 +86,29 @@ static void mktme_program_package(void *hw_program_info)/* Program a KeyID across the entire system. */ static int mktme_program_system (struct mktme_key_program *key_program, -cpumask_var_t mktme_cpumask) +cpumask_var_t mktme_cpumask,int hotplug) {struct mktme_hw_program_info info = { .key_program = key_program, .status =MKTME_PROG_SUCCESS , }; -get_online_cpus (); -on_each_cpu_mask (mktme_cpumask, mktme_program_package, &info,1 ); -put_online_cpus (); + +if (!hotplug) { +get_online_cpus (); +on_each_cpu_mask (mktme_cpumask, mktme_program_package, + &info,1 ); +put_online_cpus (); + }else { +on_each_cpu_mask (mktme_cpumask, mktme_program_package, + &info,1 ); + }return info.status; }/* Copy the payload to the HW programming structure and program this KeyID */ -static int mktme_program_keyid (int keyid,struct mktme_payload *payload) +static int mktme_program_keyid (int keyid,struct mktme_payload *payload, +cpumask_var_t mask,int hotplug) {struct mktme_key_program *kprog =NULL ;u8 kern_entropy[MKTME_AES_XTS_SIZE ];
@@ -124,7 +132,7 @@ static int mktme_program_keyid(int keyid, struct mktme_payload *payload) kprog->key_field_2[i] ^= kern_entropy[i]; } } - ret =mktme_program_system (kprog, mktme_leadcpus); + ret =mktme_program_system (kprog, mktme_leadcpus, hotplug);kmem_cache_free (mktme_prog_cache, kprog);return ret; }
@@ -173,7 +181,7 @@ static int mktme_update_key(struct key *key,/* Forget if key was user type. */ clear_bit (keyid, mktme_bitmap_user_type); - ret =mktme_program_keyid (keyid, payload); + ret =mktme_program_keyid (keyid, payload, mktme_leadcpus,0 );if (ret !=MKTME_PROG_SUCCESS ) {pr_debug ("%s: %s\n" , __func__, mktme_program_err[ret]); ret = -ENOKEY ;
@@ -202,7 +210,7 @@ int mktme_instantiate_key(struct key *key, struct key_preparsed_payload *prep) ret = -ENOKEY ; goto out; } - ret =mktme_program_keyid (keyid, payload); + ret =mktme_program_keyid (keyid, payload, mktme_leadcpus,0 );if (ret !=MKTME_PROG_SUCCESS ) {pr_debug ("%s: %s\n" , __func__, mktme_program_err[ret]); ret = -ENOKEY ;
@@ -375,6 +383,10 @@ struct key_type key_type_mktme = { .destroy = mktme_destroy_key, }; +/* +* Build mktme_leadcpus mask to include one cpu per physical package. +* The mask is used to program the Key Table on each physical package. +*/ static int mktme_build_leadcpus_mask (void ) {int online_cpu, mktme_cpu;
@@ -397,6 +409,102 @@ static int mktme_build_leadcpus_mask(void)return 0 ; } +/* A new packages Key Table is programmed with data saved in mktme_vault. */ +static int mktme_program_new_package (cpumask_var_t mask) +{ +struct key *key; +int hotplug =1 ; +int keyid, ret; + +/* When a KeyID slot is freed, it's corresponding Key is 0 */ +for (keyid =1 ; keyid <= mktme_nr_keyids; keyid++) { + key =mktme_map_key_from_keyid (keyid); +if (!key) +continue ; +/* If one key fails to program, fail the entire package. */ + ret =mktme_program_keyid (keyid, &mktme_vault[keyid], + mask, hotplug); +if (ret !=MKTME_PROG_SUCCESS ) { +pr_debug ("%s: %s\n" , __func__, mktme_program_err[ret]); + ret = -ENOKEY ; +break ; + } + } +return ret; +} + +static int mktme_hotplug_cpu_startup (unsigned int cpu) +{ +int lead_cpu, ret =0 ; +cpumask_var_t newmask; +int pkgid =topology_physical_package_id (cpu); + +mktme_map_lock (); + +/* Nothing to do if a lead CPU exists for this package. */ +for_each_cpu (lead_cpu, mktme_leadcpus) +if (topology_physical_package_id (lead_cpu) == pkgid) + goto out_unlock; + +/* No keys to program. Just add the new lead CPU to mask. */ +if (!mktme_map_mapped_keyids ()) + goto out_add_cpu; + +/* Keys need to be programmed. Confirm programming can be done. */ +if (!mktme_savekeys && + (bitmap_weight (mktme_bitmap_user_type, mktme_nr_keyids))) { + ret = -EPERM ; + goto out_unlock; + } + +/* Program only this packages Key Table, not all Key Tables. */ +if (!zalloc_cpumask_var (&newmask,GFP_KERNEL )) { + ret = -ENOMEM ; + goto out_unlock; + } +cpumask_set_cpu (cpu, newmask); + ret =mktme_program_new_package (newmask); +if (ret <0 ) { +free_cpumask_var (newmask); + goto out_unlock; + } + +free_cpumask_var (newmask); +out_add_cpu: +/* Make this cpu a lead cpu for all future Key programming requests. */ +cpumask_set_cpu (cpu, mktme_leadcpus); +out_unlock: +mktme_map_unlock (); +return ret; +} + +static int mktme_hotplug_cpu_teardown (unsigned int cpu) +{ +int pkgid, online_cpu; + +mktme_map_lock (); +/* Teardown cpu is not a lead cpu, nothing to do. */ +if (!cpumask_test_and_clear_cpu (cpu, mktme_leadcpus)) + goto out; +/* +* Teardown cpu is a lead cpu. If the physical package +* is still present, pick a new lead cpu. Beware: the +* teardown cpu is still in the online_cpu mask. Do +* not pick it again. +*/ + pkgid =topology_physical_package_id (cpu); +for_each_online_cpu (online_cpu) +if (online_cpu != cpu && + pkgid ==topology_physical_package_id (online_cpu)) { +cpumask_set_cpu (online_cpu, mktme_leadcpus); +break ; + } +out: +mktme_map_unlock (); +/* Teardowns always succeed. */ +return 0 ; +} +/* * Allocate the global mktme_map structure based on the available keyids. * Create a cache for the hardware structure. Initialize the encrypt_count
@@ -405,7 +513,7 @@ static int mktme_build_leadcpus_mask(void)*/ static int __init init_mktme (void ) { -int ret; +int ret, cpuhp;/* Verify keys are present */ if (!(mktme_nr_keyids >0 ))
@@ -433,10 +541,19 @@ static int __init init_mktme(void)if (!mktme_vault) goto free_bitmap; + cpuhp =cpuhp_setup_state_nocalls (CPUHP_AP_ONLINE_DYN , +"keys/mktme_keys:online" , + mktme_hotplug_cpu_startup, + mktme_hotplug_cpu_teardown); +if (cpuhp <0 ) + goto free_vault; + ret =register_key_type (&key_type_mktme);if (!ret)return ret;/* SUCCESS */ +cpuhp_remove_state_nocalls (cpuhp); +free_vault:kfree (mktme_vault); free_bitmap:bitmap_free (mktme_bitmap_user_type);
Signature · 1 line
2.14.1
Peter Zijlstra
maintainerRe: [RFC v2 13/13] keys/mktme: Support CPU Hotplug for MKTME keys
security/keys/mktme_keys.c static int mktme_build_leadcpus_mask(void) · line 501
Quoted 6 lines · Alison Schofield
security/keys/mktme_keys.c +6
-0+for_each_online_cpu (online_cpu) +if (online_cpu != cpu && + pkgid =topology_physical_package_id (online_cpu)) { +cpumask_set_cpu (online_cpu, mktme_leadcpus); +break ; + }
That's a capital offence right there.
Re: [RFC v2 13/13] keys/mktme: Support CPU Hotplug for MKTME keys
Quoted 9 lines · Peter Zijlstra
security/keys/mktme_keys.c static int mktme_build_leadcpus_mask(void) · line 501
Quoted 6 lines · Alison Schofield
security/keys/mktme_keys.c +6
-0+for_each_online_cpu (online_cpu) +if (online_cpu != cpu && + pkgid ==topology_physical_package_id (online_cpu)) { +cpumask_set_cpu (online_cpu, mktme_leadcpus); +break ; + }That's a capital offence right there.
Got it!
Peter Zijlstra
maintainerRe: [RFC v2 13/13] keys/mktme: Support CPU Hotplug for MKTME keys
In reply to Alison SchofieldQuoted 14 lines · Alison Schofield
static int mktme_program_system(struct
mktme_key_program*key_program,security/keys/mktme_keys.c +4
-4- cpumask_var_t mktme_cpumask) + cpumask_var_t mktme_cpumask, int hotplug) {struct mktme_hw_program_info info = { .key_program = key_program, .status =MKTME_PROG_SUCCESS , }; -get_online_cpus (); -on_each_cpu_mask (mktme_cpumask, mktme_program_package, &info,1 ); -put_online_cpus (); + +if (!hotplug) { +get_online_cpus ();
security/keys/mktme_keys.c static void mktme_program_package(void *hw_program_info) · line 107
Quoted 10 lines
security/keys/mktme_keys.c +7
-0+on_each_cpu_mask (mktme_cpumask, mktme_program_package, + &info,1 ); +put_online_cpus (); + }else { +on_each_cpu_mask (mktme_cpumask, mktme_program_package, + &info,1 ); + }return info.status; }
That is pretty horrible; and I think easily avoided.
Re: [RFC v2 13/13] keys/mktme: Support CPU Hotplug for MKTME keys
Quoted 23 lines · Peter Zijlstra
Quoted 22 lines · Alison Schofield
static int mktme_program_system(struct
mktme_key_program*key_program,security/keys/mktme_keys.c +11
-4- cpumask_var_t mktme_cpumask) + cpumask_var_t mktme_cpumask, int hotplug) {struct mktme_hw_program_info info = { .key_program = key_program, .status =MKTME_PROG_SUCCESS , }; -get_online_cpus (); -on_each_cpu_mask (mktme_cpumask, mktme_program_package, &info,1 ); -put_online_cpus (); + +if (!hotplug) { +get_online_cpus (); +on_each_cpu_mask (mktme_cpumask, mktme_program_package, + &info,1 ); +put_online_cpus (); + }else { +on_each_cpu_mask (mktme_cpumask, mktme_program_package, + &info,1 ); + }
Quoted 4 lines
Quoted 2 lines
return info.status;
}That is pretty horrible; and I think easily avoided.
Agree it's ugly. Not sure we share the same reasoning. I realize that the hotplug case is on the current cpu and so that whole one_each_cpu_mask() call is not needed. mktme_program_package() can just be called on the current cpu.
The ugliness that haunts me is that I wanted to reuse this code path, and so I passed that 'hotplug' parameter along as a differentiator between hotplug & 'typical' key programming.
I'll rework this.
Peter Zijlstra
maintainerQuoted 1 line · Alison Schofield
(Multi-Key Total Memory Encryption)
I think that MKTME is a horrible name, and doesn't appear to accurately describe what it does either. Specifically the 'total' seems out of place, it doesn't require all memory to be encrypted.
Quoted 6 lines · Peter Zijlstra
Quoted 1 line · Alison Schofield
(Multi-Key Total Memory Encryption)
I think that MKTME is a horrible name, and doesn't appear to accurately describe what it does either. Specifically the 'total' seems out of place, it doesn't require all memory to be encrypted.
MKTME implies TME. TME is enabled by BIOS and it encrypts all memory with CPU-generated key. MKTME allows to use other keys or disable encryption for a page.
But, yes, name is not good.
Signature · 1 line
Kirill A. Shutemov
T24gVHVlLCAyMDE4LTEyLTA0IGF0IDEyOjQ2ICswMzAwLCBLaXJpbGwgQS4gU2h1dGVtb3Ygd3Jv dGU6DQo+IE9uIFR1ZSwgRGVjIDA0LCAyMDE4IGF0IDA5OjI1OjUwQU0gKzAwMDAsIFBldGVyIFpp amxzdHJhIHdyb3RlOg0KPiA+IE9uIE1vbiwgRGVjIDAzLCAyMDE4IGF0IDExOjM5OjQ3UE0gLTA4 MDAsIEFsaXNvbiBTY2hvZmllbGQgd3JvdGU6DQo+ID4gPiAoTXVsdGktS2V5IFRvdGFsIE1lbW9y eSBFbmNyeXB0aW9uKQ0KPiA+IA0KPiA+IEkgdGhpbmsgdGhhdCBNS1RNRSBpcyBhIGhvcnJpYmxl IG5hbWUsIGFuZCBkb2Vzbid0IGFwcGVhciB0byBhY2N1cmF0ZWx5DQo+ID4gZGVzY3JpYmUgd2hh dCBpdCBkb2VzIGVpdGhlci4gU3BlY2lmaWNhbGx5IHRoZSAndG90YWwnIHNlZW1zIG91dCBvZg0K PiA+IHBsYWNlLCBpdCBkb2Vzbid0IHJlcXVpcmUgYWxsIG1lbW9yeSB0byBiZSBlbmNyeXB0ZWQu DQo+IA0KPiBNS1RNRSBpbXBsaWVzIFRNRS4gVE1FIGlzIGVuYWJsZWQgYnkgQklPUyBhbmQgaXQg ZW5jcnlwdHMgYWxsIG1lbW9yeSB3aXRoDQo+IENQVS1nZW5lcmF0ZWQga2V5LiBNS1RNRSBhbGxv d3MgdG8gdXNlIG90aGVyIGtleXMgb3IgZGlzYWJsZSBlbmNyeXB0aW9uDQo+IGZvciBhIHBhZ2Uu DQoNCldoZW4geW91IHNheSAiZGlzYWJsZSBlbmNyeXB0aW9uIHRvIGEgcGFnZSIgZG9lcyB0aGUg ZW5jcnlwdGlvbiBnZXQNCmFjdHVhbGx5IGRpc2FibGVkIG9yIGRvZXMgdGhlIENQVSBqdXN0IGRl Y3J5cHQgaXQgdHJhbnNwYXJlbnRseSBpLmUuDQp3aGF0IGhhcHBlbnMgcGh5c2ljYWxseT8NCg0K PiBCdXQsIHllcywgbmFtZSBpcyBub3QgZ29vZC4NCg0KL0phcmtrbw0K
Quoted 9 lines · Jarkko
Quoted 8 lines · Kirill A. Shutemov
Quoted 6 lines · Peter Zijlstra
Quoted 1 line · Alison Schofield
(Multi-Key Total Memory Encryption)
I think that MKTME is a horrible name, and doesn't appear to accurately describe what it does either. Specifically the 'total' seems out of place, it doesn't require all memory to be encrypted.
Quoted 7 lines
Quoted 3 lines
MKTME implies TME. TME is enabled by BIOS and it encrypts all memory with CPU-generated key. MKTME allows to use other keys or disable encryption for a page.
When you say "disable encryption to a page" does the encryption get actually disabled or does the CPU just decrypt it transparently i.e. what happens physically?
Yes, it gets disabled. Physically. It overrides TME encryption.
Signature · 1 line
Kirill A. Shutemov
Quoted 4 lines · Kirill A. Shutemov
Quoted 3 lines
When you say "disable encryption to a page" does the encryption get actually disabled or does the CPU just decrypt it transparently i.e. what happens physically?
Yes, it gets disabled. Physically. It overrides TME encryption.
I know MKTME itself has a runtime overhead and we expect it to have a performance impact in the low single digits. Does TME have that overhead? Presumably MKTME plus no-encryption is not expected to have the overhead.
We should probably m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c2U/KS4gQnV0IE1LVE1FIG1pZ2h0 IGhhdmUgYWRkaXRpb25hbCBvdmVyaGVhZCBmcm9tIHNvZnR3YXJlIGltcGxlbWVudGF0aW9uIGlu IGtlcm5lbD8NCg0KVGhhbmtzLA0KLUthaQ=
T24gVGh1LCAyMDE4LTEyLTA2IGF0IDE0OjIyICswMzAwLCBLaXJpbGwgQS4gU2h1dGVtb3Ygd3Jv dGU6DQo+IFdoZW4geW91IHNheSAiZGlzYWJsZSBlbmNyeXB0aW9uIHRvIGEgcGFnZSIgZG9lcyB0 aGUgZW5jcnlwdGlvbiBnZXQNCj4gPiBhY3R1YWxseSBkaXNhYmxlZCBvciBkb2VzIHRoZSBDUFUg anVzdCBkZWNyeXB0IGl0IHRyYW5zcGFyZW50bHkgaS5lLg0KPiA+IHdoYXQgaGFwcGVucyBwaHlz aWNhbGx5Pw0KPiANCj4gWWVzLCBpdCBnZXRzIGRpc2FibGVkLiBQaHlzaWNhbGx5LiBJdCBvdmVy cmlkZXMgVE1FIGVuY3J5cHRpb24uDQoNCk9LLCB0aGFua3MgZm9yIGNvbmZpcm1hdGlvbi4gQlRX LCBob3cgbXVjaCBpcyB0aGUgcGVuYWx0eSB0byBrZWVwIGl0DQphbHdheXMgZW5hYmxlZD8gSXMg aXQgc29tZXRoaW5nIHRoYXQgd291bGQgbm90IG1ha2Ugc2Vuc2UgZm9yIHNvbWUNCm90aGVyIHJl YXNvbnM/DQoNCi9KYXJra28NCg=
Quoted 10 lines · Jarkko
Quoted 5 lines · Kirill A. Shutemov
When you say "disable encryption to a page" does the encryption get
Quoted 2 lines
actually disabled or does the CPU just decrypt it transparently i.e. what happens physically?
Yes, it gets disabled. Physically. It overrides TME encryption.
OK, thanks for confirmation. BTW, how much is the penalty to keep it always enabled? Is it something that would not make sense for some other reasons?
We don't have any numbers to share at this point.
Signature · 1 line
Kirill A. Shutemov
Andy Lutomirski
maintainerQuoted 14 lines · Alison Schofield
Hi Thomas, David,
Here is an updated RFC on the API's to support MKTME. (Multi-Key Total Memory Encryption)
This RFC presents the 2 API additions to support the creation and usage of memory encryption keys:
1) Kernel Key Service type "mktme"
2) System callencrypt_mprotect()This patchset is built upon Kirill Shutemov's work for the core MKTME support.
Quoted 7 lines
David: Please let me know if the changes made, based on your review, are reasonable. I don't think that the new changes touch key service specific areas (much).
Thomas: Please provide feedback on
encrypt_mprotect(). If not a review, then a direction check would be helpful.
I'm not Thomas, but I think it's the wrong direction. As it stands, encrypt_mprotect() is an incomplete version of mprotect() (since it's missing the protection key support), and it's also functionally just MADV_DONTNEED. In other words, the sole user-visible effect appears to be that the existing pages are blown away. The fact that it changes the key in use doesn't seem terribly useful, since it's anonymous memory, and the most secure choice is to use CPU-managed keying, which appears to be the default anyway on TME systems. It also has totally unclear semantics WRT swap, and, off the top of my head, it looks like it may have serious cache-coherency issues and like swapping the pages might corrupt them, both because there are no flushes and because the direct-map alias looks like it will use the default key and therefore appear to contain the wrong data.
I would propose a very different direction: don't try to support MKTME at all for anonymous memory, and instead figure out the important use cases and support them directly. The use cases that I can think of off the top of my head are:
1. pmem. This should probably use a very different API.
2. Some kind of VM hardening, where a VM's memory can be protected a little tiny bit from the main kernel. But I don't see why this is any better than XPO (eXclusive Page-frame Ownership), which brings to mind:
The main implementation concern I have with this patch set is cache coherency and handling of the direct map. Unless I missed something, you're not doing anything about the direct map, which means that you have RW aliases of the same memory with different keys. For use case #2, this probably means that you need to either get rid of the direct map and make get_user_pages() fail, or you need to change the key on the direct map as well, probably using the pageattr.c code.
As for caching, As far as I can tell from reading the preliminary docs, Intel's MKTME, much like AMD's SME, is basically invisible to the hardware cache coherency mechanism. So, if you modify a physical address with one key (or SME-enable bit), and you read it with another, you get garbage unless you flush. And, if you modify memory with one key then remap it with a different key without flushing in the mean time, you risk corruption. And, what's worse, if I'm reading between the lines in the docs correctly, if you use PCONFIG to change a key, you may need to do a bunch of cache flushing to ensure you get reasonable effects. (If you have dirty cache lines for some (PA, key) and you PCONFIG to change the underlying key, you get different results depending on whether the writeback happens before or after the package doing the writeback notices the PCONFIG.)
Finally, If you're going to teach the kernel how to have some user pages that aren't in the direct map, you've essentially done XPO, which is nifty but expensive. And I think that doing this gets you essentially all the benefit of MKTME for the non-pmem use case. Why exactly would any software want to use anything other than a CPU-managed key for anything other than pmem?
--Andy
Andy Lutomirski
maintainerQuoted 5 lines · Andy Lutomirski
Quoted 1 line · Alison Schofield
Quoted 7 lines
Finally, If you're going to teach the kernel how to have some user pages that aren't in the direct map, you've essentially done XPO, which is nifty but expensive. And I think that doing this gets you essentially all the benefit of MKTME for the non-pmem use case. Why exactly would any software want to use anything other than a CPU-managed key for anything other than pmem?
Let me say this less abstractly. Here's a somewhat concrete actual proposal. Make a new memfd_create() flag like MEMFD_ISOLATED. The semantics are that the underlying pages are made not-present in the direct map when they're allocated (which is hideously slow, but so be it), and that anything that tries to get_user_pages() the resulting pages fails. And then make sure we have all the required APIs so that QEMU can still map this stuff into a VM.
If there is indeed a situation in which MKTME-ifying the memory adds some value, then we can consider doing that.
And maybe we get fancy and encrypt this memory when it's swapped, but maybe we should just encrypt everything when it's swapped.
Quoted 9 lines · Andy Lutomirski
Quoted 7 lines · Andy Lutomirski
On Mon, Dec 3, 2018 at 11:37 PM Alison Schofield <[email protected]> wrote:
Finally, If you're going to teach the kernel how to have some user pages that aren't in the direct map, you've essentially done XPO, which is nifty but expensive. And I think that doing this gets you essentially all the benefit of MKTME for the non-pmem use case. Why exactly would any software want to use anything other than a CPU-managed key for anything other than pmem?
Quoted 7 lines
Let me say this less abstractly. Here's a somewhat concrete actual proposal. Make a new
memfd_create()flag likeMEMFD_ISOLATED. The semantics are that the underlying pages are made not-present in the direct map when they're allocated (which is hideously slow, but so be it), and that anything that tries toget_user_pages()the resulting pages fails. And then make sure we have all the required APIs so that QEMU can still map this stuff into a VM.
I think we need get_user_pages(). We want direct I/O to work, *and* we really want direct device assignment into VMs.
Quoted 2 lines
And maybe we get fancy and encrypt this memory when it's swapped, but maybe we should just encrypt everything when it's swapped.
We decided long ago (and this should be in the patches somewhere) that we wouldn't force memory to be encrypted in swap. We would just recommend it in the documentation as a best practice, especially when using MKTME.
We can walk that back, of course, but that's what we're doing at the moment.
T24gVHVlLCAyMDE4LTEyLTA0IGF0IDExOjE5IC0wODAwLCBBbmR5IEx1dG9taXJza2kgd3JvdGU6 DQo+IEknbSBub3QgVGhvbWFzLCBidXQgSSB0aGluayBpdCdzIHRoZSB3cm9uZyBkaXJlY3Rpb24u ICBBcyBpdCBzdGFuZHMsDQo+IGVuY3J5cHRfbXByb3RlY3QoKSBpcyBhbiBpbmNvbXBsZXRlIHZl cnNpb24gb2YgbXByb3RlY3QoKSAoc2luY2UgaXQncw0KPiBtaXNzaW5nIHRoZSBwcm90ZWN0aW9u IGtleSBzdXBwb3J0KSwgYW5kIGl0J3MgYWxzbyBmdW5jdGlvbmFsbHkganVzdA0KPiBNQURWX0RP TlRORUVELiAgSW4gb3RoZXIgd29yZHMsIHRoZSBzb2xlIHVzZXItdmlzaWJsZSBlZmZlY3QgYXBw ZWFycw0KPiB0byBiZSB0aGF0IHRoZSBleGlzdGluZyBwYWdlcyBhcmUgYmxvd24gYXdheS4gIFRo ZSBmYWN0IHRoYXQgaXQNCj4gY2hhbmdlcyB0aGUga2V5IGluIHVzZSBkb2Vzbid0IHNlZW0gdGVy cmlibHkgdXNlZnVsLCBzaW5jZSBpdCdzDQo+IGFub255bW91cyBtZW1vcnksIGFuZCB0aGUgbW9z dCBzZWN1cmUgY2hvaWNlIGlzIHRvIHVzZSBDUFUtbWFuYWdlZA0KPiBrZXlpbmcsIHdoaWNoIGFw cGVhcnMgdG8gYmUgdGhlIGRlZmF1bHQgYW55d2F5IG9uIFRNRSBzeXN0ZW1zLiAgSXQNCj4gYWxz byBoYXMgdG90YWxseSB1bmNsZWFyIHNlbWFudGljcyBXUlQgc3dhcCwgYW5kLCBvZmYgdGhlIHRv cCBvZiBteQ0KPiBoZWFkLCBpdCBsb29rcyBsaWtlIGl0IG1heSBoYXZlIH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ZmZXJlbnQgQVBJLg0KPiA+IA0KPiA+IDIuIFNvbWUga2luZCBvZiBWTSBoYXJkZW5p bmcsIHdoZXJlIGEgVk0ncyBtZW1vcnkgY2FuIGJlIHByb3RlY3RlZCBhDQo+ID4gbGl0dGxlIHRp bnkgYml0IGZyb20gdGhlIG1haW4ga2VybmVsLiAgQnV0IEkgZG9uJ3Qgc2VlIHdoeSB0aGlzIGlz IGFueQ0KPiA+IGJldHRlciB0aGFuIFhQTyAoZVhjbHVzaXZlIFBhZ2UtZnJhbWUgT3duZXJzaGlw KSwgd2hpY2ggYnJpbmdzIHRvDQo+ID4gbWluZDoNCj4gDQo+IFdoYXQgaXMgdGhlIHRocmVhdCBt b2RlbCBhbnl3YXkgZm9yIEFNRCBhbmQgSW50ZWwgdGVjaG5vbG9naWVzPw0KPiANCj4gRm9yIG1l IGl0IGxvb2tzIGxpa2UgdGhhdCB5b3UgY2FuIHJlYWQsIHdyaXRlIGFuZCBldmVuIHJlcGxheSAN Cj4gZW5jcnlwdGVkIHBhZ2VzIGJvdGggaW4gU01FIGFuZCBUTUUuIA0KDQpSaWdodC4gTmVpdGhl ciBvZiB0aGVtIChpbmNsdWRpbmcgTUtUTUUpIHByZXZlbnRzIHJlcGxheSBhdHRhY2suIEJ1dCBp biBteSB1bmRlcnN0YW5kaW5nIFNFViBkb2Vzbid0DQpwcmV2ZW50IHJlcGxheSBhdHRhY2sgZWl0 aGVyIHNpbmNlIGl0IGRvZXNuJ3QgaGF2ZSBpbnRlZ3JpdHkgcHJvdGVjdGlvbi4NCg0KVGhhbmtz LA0KLUthaQ0K
Quoted 28 lines · Kai
Quoted 27 lines · Jarkko
Quoted 25 lines · Andy Lutomirski
I'm not Thomas, but I think it's the wrong direction. As it stands,
encrypt_mprotect()is an incomplete version ofmprotect()(since it's missing the protection key support), and it's also functionally justMADV_DONTNEED. In other words, the sole user-visible effect appears to be that the existing pages are blown away. The fact that it changes the key in use doesn't seem terribly useful, since it's anonymous memory, and the most secure choice is to use CPU-managed keying, which appears to be the default anyway on TME systems. It also has totally unclear semantics WRT swap, and, off the top of my head, it looks like it may have serious cache-coherency issues and like swapping the pages might corrupt them, both because there are no flushes and because the direct-map alias looks like it will use the default key and therefore appear to contain the wrong data.I would propose a very different direction: don't try to support MKTME at all for anonymous memory, and instead figure out the important use cases and support them directly. The use cases that I can think of off the top of my head are:
1. pmem. This should probably use a very different API.
2. Some kind of VM hardening, where a VM's memory can be protected a little tiny bit from the main kernel. But I don't see why this is any better than XPO (eXclusive Page-frame Ownership), which brings to mind:
Quoted 8 lines
Quoted 4 lines
What is the threat model anyway for AMD and Intel technologies?
For me it looks like that you can read, write and even replay encrypted pages both in SME and TME.
Right. Neither of them (including MKTME) prevents replay attack. But in my understanding SEV doesn't prevent replay attack either since it doesn't have integrity protection.
Yep, it doesn't :-) That's why I've been wondering after seeing presentations concerning SME and SVE what they are good for.
Cold boot attacks are definitely at least something where these techs can help...
/Jarkko
Quoted 27 lines · Jarkko
Quoted 19 lines · Andy Lutomirski
I'm not Thomas, but I think it's the wrong direction. As it stands,
encrypt_mprotect()is an incomplete version ofmprotect()(since it's missing the protection key support), and it's also functionally justMADV_DONTNEED. In other words, the sole user-visible effect appears to be that the existing pages are blown away. The fact that it changes the key in use doesn't seem terribly useful, since it's anonymous memory, and the most secure choice is to use CPU-managed keying, which appears to be the default anyway on TME systems. It also has totally unclear semantics WRT swap, and, off the top of my head, it looks like it may have serious cache-coherency issues and like swapping the pages might corrupt them, both because there are no flushes and because the direct-map alias looks like it will use the default key and therefore appear to contain the wrong data.I would propose a very different direction: don't try to support MKTME at all for anonymous memory, and instead figure out the important use cases and support them directly. The use cases that I can think of off the top of my head are:
Quoted 6 lines
1. pmem. This should probably use a very different API.
2. Some kind of VM hardening, where a VM's memory can be protected a little tiny bit from the main kernel. But I don't see why this is any better than XPO (eXclusive Page-frame Ownership), which brings to mind:
Quoted 4 lines
What is the threat model anyway for AMD and Intel technologies?
For me it looks like that you can read, write and even replay encrypted pages both in SME and TME.
What replay attack are you talking about? MKTME uses AES-XTS with physical address tweak. So the data is tied to the place in physical address space and replacing one encrypted page with another encrypted page from different address will produce garbage on decryption.
Signature · 1 line
Kirill A. Shutemov
T24gRnJpLCAyMDE4LTEyLTA3IGF0IDE0OjU3ICswMzAwLCBLaXJpbGwgQS4gU2h1dGVtb3Ygd3Jv dGU6DQo+ID4gV2hhdCBpcyB0aGUgdGhyZWF0IG1vZGVsIGFueXdheSBmb3IgQU1EIGFuZCBJbnRl bCB0ZWNobm9sb2dpZXM/DQo+ID4gDQo+ID4gRm9yIG1lIGl0IGxvb2tzIGxpa2UgdGhhdCB5b3Ug Y2FuIHJlYWQsIHdyaXRlIGFuZCBldmVuIHJlcGxheSANCj4gPiBlbmNyeXB0ZWQgcGFnZXMgYm90 aCBpbiBTTUUgYW5kIFRNRS4gDQo+IA0KPiBXaGF0IHJlcGxheSBhdHRhY2sgYXJlIHlvdSB0YWxr aW5nIGFib3V0PyBNS1RNRSB1c2VzIEFFUy1YVFMgd2l0aCBwaHlzaWNhbA0KPiBhZGRyZXNzIHR3 ZWFrLiBTbyB0aGUgZGF0YSBpcyB0aWVkIHRvIHRoZSBwbGFjZSBpbiBwaHlzaWNhbCBhZGRyZXNz IHNwYWNlIGFuZA0KPiByZXBsYWNpbmcgb25lIGVuY3J5cHRlZCBwYWdlIHdpdGggYW5vdGhlciBl bmNyeXB0ZWQgcGFnZSBmcm9tIGRpZmZlcmVudA0KPiBhZGRyZXNzIHdpbGwgcHJvZHVjZSBnYXJi YWdlIG9uIGRlY3J5cHRpb24uDQoNCkp1c3QgdHJ5aW5nIHRvIHVuZGVyc3RhbmQgaG93IHRoaXMg d29ya3MuDQoNClNvIHlvdSB1c2UgcGh5c2ljYWwgYWRkcmVzcyBsaWtlIGEgbm9uY2UvdmVyc2lv biBmb3IgdGhlIHBhZ2UgYW5kDQp0aHVzIHByZXZlbnQgcmVwbGF5PyBXYXMgbm90IGF3YXJlIG9m IHRoaXMuDQoNCi9KYXJ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GlzLg0KDQpUaGUgYnJ1dGFs IGZhY3QgaXMgdGhhdCBhIHBoeXNpY2FsIGFkZHJlc3MgaXMgYW4gYXN0cm9ub21pY2FsIHN0cmV0 Y2gNCmZyb20gYSByYW5kb20gdmFsdWUgb3IgaW5jcmVhc2luZyBjb3VudGVyLiBUaHVzLCBpdCBp cyBmYWlyIHRvIHNheSB0aGF0DQpNS1RNRSBwcm92aWRlcyBvbmx5IG5haXZlIG1lYXN1cmVzIGFn YWluc3QgcmVwbGF5IGF0dGFja3MuLi4NCg0KL0phcmtrbw0K
Andy Lutomirski
maintainerQuoted 14 lines · Jarkko
Quoted 12 lines · Jarkko Sakkinen
Quoted 10 lines · Kirill A. Shutemov
Quoted 4 lines
What is the threat model anyway for AMD and Intel technologies?
For me it looks like that you can read, write and even replay encrypted pages both in SME and TME.
What replay attack are you talking about? MKTME uses AES-XTS with physical address tweak. So the data is tied to the place in physical address space and
replacing one encrypted page with another encrypted page from different address will produce garbage on decryption.
Quoted 9 lines
Quoted 4 lines
Just trying to understand how this works.
So you use physical address like a nonce/version for the page and thus prevent replay? Was not aware of this.
The brutal fact is that a physical address is an astronomical stretch from a random value or increasing counter. Thus, it is fair to say that MKTME provides only naive measures against replay attacks...
And this is potentially a big deal, since there are much simpler replay attacks that can compromise the system. For example, if I can replay the contents of a page table, I can write to freed memory.
--Andy
T24gRnJpLCAyMDE4LTEyLTA3IGF0IDIzOjQ1ICswMDAwLCBTYWtraW5lbiwgSmFya2tvIHdyb3Rl Og0KPiBPbiBGcmksIDIwMTgtMTItMDcgYXQgMTM6NTkgLTA4MDAsIEphcmtrbyBTYWtraW5lbiB3 cm90ZToNCj4gPiBPbiBGcmksIDIwMTgtMTItMDcgYXQgMTQ6NTcgKzAzMDAsIEtpcmlsbCBBLiBT aHV0ZW1vdiB3cm90ZToNCj4gPiA+ID4gV2hhdCBpcyB0aGUgdGhyZWF0IG1vZGVsIGFueXdheSBm b3IgQU1EIGFuZCBJbnRlbCB0ZWNobm9sb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 ZWQuDQoyLiBUaGUgaHlwZXJ2aXNvciBkb2VzIG5vdCBsZWFrIHNlY3JldHMuDQoNCldoZW4gKDEp IGFuZCAoMikgaG9sZCBbMV0sIHdlIGhhcmRlbiBWTXMgaW4gdHdvIGRpZmZlcmVudCB3YXlzOg0K DQpBLiBWTXMgY2Fubm90IGxlYWsgZGF0YSB0byBlYWNoIG90aGVyIG9yIGNhbiB0aGV5IHdpdGgg TDFURiB3aGVuIEhUDQogICBpcyBlbmFibGVkPw0KQi4gUHJvdGVjdHMgYWdhaW5zdCBjb2xkIGJv b3QgYXR0YWNrcy4NCg0KSXNuJ3QgdGhpcyB3aGF0IHRoaXMgYWJvdXQgaW4gdGhlIG51dHNoZWxs IHJvdWdobHk/DQoNClsxXSBYUEZPIGNvdWxkIHBvdGVudGlhbGx5IGJlIGFuIG9wdC1pbiBmZWF0 dXJlIHRoYXQgcmVkdWNlcyB0aGUNCiAgICBkYW1hZ2Ugd2hlbiBlaXRoZXIgb2YgdGhlc2UgYXNz dW1wdGlvbnMgaGFzIGJlZW4gYnJva2VuLg0KDQovSmFya2tvDQo
Andy Lutomirski
maintainerQuoted 11 lines · Jarkko
Quoted 3 lines · Jarkko Sakkinen
The brutal fact is that a physical address is an astronomical stretch from a random value or increasing counter. Thus, it is fair to say that MKTME provides only naive measures against replay attacks...
I'll try to summarize how I understand the high level security model of MKTME because (would be good idea to document it).
Assumptions:
Quoted 7 lines
1. The hypervisor has not been infiltrated.
2. The hypervisor does not leak secrets.When (1) and (2) hold [1], we harden VMs in two different ways:
A. VMs cannot leak data to each other or can they with L1TF when HT
is enabled?
I strongly suspect that, on L1TF-vulnerable CPUs, MKTME provides no protection whatsoever. It sounds like MKTME is implemented in the memory controller -- as far as the rest of the CPU and the cache hierarchy are concerned, the MKTME key selction bits are just part of the physical address. So an attack like L1TF that leaks a cacheline that's selected by physical address will leak the cleartext if the key selection bits are set correctly.
(I suppose that, if the attacker needs to brute-force the physical address, then MKTME makes it a bit harder because the effective physical address space is larger.)
Quoted 1 line
B. Protects against cold boot attacks.
TME does this, AFAIK. MKTME does, too, unless the "user" mode is used, in which case the protection is weaker.
Quoted 7 lines
Isn't this what this about in the nutshell roughly?
[1] XPFO could potentially be an opt-in feature that reduces the damage when either of these assumptions has been broken.
/Jarkko
T24gV2VkLCAyMDE4LTEyLTEyIGF0IDA4OjI5IC0wODAwLCBBbmR5IEx1dG9taXJza2kgd3JvdGU6 DQo+IE9uIFdlZCwgRGVjIDEyLCAyMDE4IGF0IDc6MzEgQU0gU2Fra2luZW4sIEphcmtrbw0KPiA8 amFya2tvLnNha2tpbmVuQGludGVsLmNvbT4gd3JvdGU6DQo+ID4gT24gRnJpLCAyMDE4LTEyLTA3 IGF0IDE1OjQ1IC0wODAwLCBKYXJra28gU2Fra2luZW4gd3JvdGU6DQo+ID4gPiBUaGUgYnJ1dGFs IGZhY3QgaXMgdGhhdCBhIHBoeXNpY2FsIGFkZHJlc3MgaXMgYW4gYXN0cm9ub21pY2FsIHN0cmV0 Y2gNCj4gPiA+IGZyb20gYSByYW5kb20gdmFsdWUgb3IgaW5jcmVhc2luZyBjb3VudGVyLiBUaHVz LCBpdCBpcyBmYWlyIHRvIHNheSB0aGF0DQo+ID4gPiBNS1RNRSBwcm92aWRlcyBvbmx5IG5haXZl IG1lYXN1cmVzIGFnYWluc3QgcmVwbGF5IGF0dGFja3MuLi4NCj4gPiANCj4gPiBJJ2xsIHRyeSB0 byBzdW1tYXJpemUgaG93IEkgdW5kZXJzdGFuZCB0aGUgaGlnaCBsZXZlbCBzZWN1cml0eQ0KPiA+ IG1vZGVsIG9mIE1LVE1FIGJlY2F1c2UgKHdvdWxkIGJlIGdvb2QgaWRlYSB0byBkb2N1bWVudCBp dCkuDQo+ID4gDQo+ID4gQXNzdW1wdGlvbnM6DQo+ID4gDQo+ID4gMS4gVGhlIGh5cGVydmlzb3Ig aGFzIG5vdCBiZWVuIGluZmlsdHJhdGVkLg0KPiA+IDIuIFRoZSBoeXBlcnZpc29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L VE1FIGlzIGltcGxlbWVudGVkIGluIHRoZQ0KPiBtZW1vcnkgY29udHJvbGxlciAtLSBhcyBmYXIg YXMgdGhlIHJlc3Qgb2YgdGhlIENQVSBhbmQgdGhlIGNhY2hlIGhpZXJhcmNoeQ0KPiBhcmUgY29u Y2VybmVkLCB0aGUgTUtUTUUga2V5IHNlbGN0aW9uIGJpdHMgYXJlIGp1c3QgcGFydCBvZiB0aGUg cGh5c2ljYWwNCj4gYWRkcmVzcy4gIFNvIGFuIGF0dGFjayBsaWtlIEwxVEYgdGhhdCBsZWFrcyBh IGNhY2hlbGluZSB0aGF0J3Mgc2VsZWN0ZWQgYnkNCj4gcGh5c2ljYWwgYWRkcmVzcyB3aWxsIGxl YWsgdGhlIGNsZWFydGV4dCBpZiB0aGUga2V5IHNlbGVjdGlvbiBiaXRzIGFyZSBzZXQNCj4gY29y cmVjdGx5Lg0KDQpSaWdodC4gTUtUTUUgZG9lc24ndCBwcmV2ZW50IGNhY2hlIGJhc2VkIGF0dGFj ay4gRGF0YSBpbiBjYWNoZSBpcyBpbiBjbGVhci4NCg0KVGhhbmtzLA0KLUthaQ0KDQo
Quoted 9 lines · Kirill A. Shutemov
Quoted 4 lines
What is the threat model anyway for AMD and Intel technologies?
For me it looks like that you can read, write and even replay encrypted pages both in SME and TME.
What replay attack are you talking about? MKTME uses AES-XTS with physical address tweak. So the data is tied to the place in physical address space and replacing one encrypted page with another encrypted page from different address will produce garbage on decryption.
What if you have some control over the physical addresses you write the stolen encrypted page to? For instance, VM_Eve might manage to use physical address space previously used by VM_Alice by getting the hypervisor to move memory around (memory pressure, force other VMs out via some type of DOS attack, etc.).
Say:
C is VM_Alice's clear text at hwaddr
E = mktme_encrypt(VM_Allice_key, hwaddr, C)
Eve somehow stole the encrypted bits E
Eve would need to write the page E without further encryption to make sure that the DRAM contains the original stolen bits E, not encrypted again with VM_Eve's key or mktme_encrypt(VM_Eve_key, hwaddr, E) would be present in the DRAM which is not helpful. But with MKTME under the current proposal VM_Eve can disable encryption for a given mapping, right? (See also Note 1)
Eve gets the HV to move VM_Alice back over the same physical address, Eve "somehow" gets VM_Alice to read that page and use its content (which would likely be a use of uninitialized memory bug, from VM_Alice's perspective) and you have a replay attack?
For TME, this doesn't work as you cannot partially disable encryption, so if Eve tries to write the stolen encrypted bits E, even in the "right place", they get encrypted again to tme_encrypt(hwaddr, E). Upon decryption, VM_Alice will get E, not C.
Note 1: Actually, even if with MKTME you cannot disable encryption but *if* Eve knows its own key, Eve can always write a preimage P that the CPU encrypts to E for VM_Alice to read back and decrypt:
P = mktme_decrypt(VM_Eve_key, hwaddr, E)
This is not possible with TME as Eve doesn't know the key used by the CPU and cannot compute P.
Quoted 3 lines · Andy Lutomirski
I'm not Thomas, but I think it's the wrong direction. As it stands,
encrypt_mprotect()is an incomplete version ofmprotect()(since it's missing the protection key support),
I thought about this when I added mprotect_pkey(). We start with:
mprotect(addr, len, prot);
then
mprotect_pkey(addr, len, prot);
then
mprotect_pkey_encrypt(addr, len, prot, key);
That doesn't scale because we eventually havemprotect_and_a_history_of_mm_features(). :)
What I was hoping to see was them do this (apologies for the horrible indentation:
ptr = mmap(..., PROT_NONE); mprotect_pkey( addr, len, PROT_NONE, pkey); mprotect_encrypt(addr, len, PROT_NONE, keyid); mprotect( addr, len, real_prot);
The point is that you *can* stack these things and don't have to have an mprotect_kitchen_sink() if you use PROT_NONE for intermediate permissions during setup.
Quoted 4 lines
and it's also functionally just
MADV_DONTNEED. In other words, the sole user-visible effect appears to be that the existing pages are blown away. The fact that it changes the key in use doesn't seem terribly useful, since it's anonymous memory,
It's functionally MADV_DONTNEED, plus a future promise that your writes will never show up as plaintext on the DIMM.
We also haven't settled on the file-backed properties. For file-backed, my hope was that you could do:
ptr = mmap(fd, size, prot);
printf("ciphertext: %x\n", *ptr);
mprotect_encrypt(ptr, len, prot, keyid);
printf("plaintext: %x\n", *ptr);Quoted 7 lines
and the most secure choice is to use CPU-managed keying, which appears to be the default anyway on TME systems. It also has totally unclear semantics WRT swap, and, off the top of my head, it looks like it may have serious cache-coherency issues and like swapping the pages might corrupt them, both because there are no flushes and because the direct-map alias looks like it will use the default key and therefore appear to contain the wrong data.
I think we fleshed this out on IRC a bit, but the other part of the implementation is described here: https://lwn.net/Articles/758313/, and contains a direct map per keyid. When you do phys_to_virt() and friends, you get the correct, decrypted view direct map which is appropriate for the physical page. And, yes, this has very consequential security implications.
Quoted 11 lines
I would propose a very different direction: don't try to support MKTME at all for anonymous memory, and instead figure out the important use cases and support them directly. The use cases that I can think of off the top of my head are:
1. pmem. This should probably use a very different API.
2. Some kind of VM hardening, where a VM's memory can be protected a little tiny bit from the main kernel. But I don't see why this is any better than XPO (eXclusive Page-frame Ownership), which brings to mind:
The XPO approach is "fun", and would certainly be a way to keep the direct map from being exploited to get access to plain-text mappings of ciphertext.
But, it also has massive performance implications and we didn't quite want to go there quite yet.
Quoted 7 lines
The main implementation concern I have with this patch set is cache coherency and handling of the direct map. Unless I missed something, you're not doing anything about the direct map, which means that you have RW aliases of the same memory with different keys. For use case #2, this probably means that you need to either get rid of the direct map and make
get_user_pages()fail, or you need to change the key on the direct map as well, probably using thepageattr.ccode.
The current, public hardware spec has a description of what's required to maintain cache coherency. Basically, you can keep as many mappings of a physical page as you want, but only write to one mapping at a time, and clflush the old one when you want to write to a new one.
Quoted 7 lines
As for caching, As far as I can tell from reading the preliminary docs, Intel's MKTME, much like AMD's SME, is basically invisible to the hardware cache coherency mechanism. So, if you modify a physical address with one key (or SME-enable bit), and you read it with another, you get garbage unless you flush. And, if you modify memory with one key then remap it with a different key without flushing in the mean time, you risk corruption.
Yes, all true (at least with respect to Intel's implementation).
Quoted 7 lines
And, what's worse, if I'm reading
between the lines in the docs correctly, if you use PCONFIG to change a key, you may need to do a bunch of cache flushing to ensure you get reasonable effects. (If you have dirty cache lines for some (PA, key) and you PCONFIG to change the underlying key, you get different results depending on whether the writeback happens before or after the package doing the writeback notices the PCONFIG.)
We're not going to allow a key to be PCONFIG'd while there are any physical pages still associated with it. There are per-VMA refcounts tied back to the keyid slots, IIRC. So, before PCONFIG can happen, we just need to make sure that all the VMAs are gone, all the pages are freed, and all dirty cachelines have been clflushed.
This is where get_user_pages() is our mortal enemy, though. I hope we got that right. Kirill/Alison, we should chat about this one. :)
Quoted 6 lines
Finally, If you're going to teach the kernel how to have some user pages that aren't in the direct map, you've essentially done XPO, which is nifty but expensive. And I think that doing this gets you essentially all the benefit of MKTME for the non-pmem use case. Why exactly would any software want to use anything other than a CPU-managed key for anything other than pmem?
It is handy, for one, to let you "cluster" key usage. If you have 5 Pepsi VMs and 5 Coke VMs, each Pepsi one using the same key and each Coke one using the same key, you can boil it down to only 2 hardware keyid slots that get used, and do this transparently.
But, I think what you're implying is that the security properties of user-supplied keys can only be *worse* than using CPU-generated keys (assuming the CPU does a good job generating it). So, why bother allowing user-specified keys in the first place?
It's a good question and I don't have a solid answer for why folks want this. I'll find out.
Andy Lutomirski
maintainerQuoted 24 lines · Dave Hansen
Quoted 3 lines · Andy Lutomirski
I'm not Thomas, but I think it's the wrong direction. As it stands,
encrypt_mprotect()is an incomplete version ofmprotect()(since it's missing the protection key support),I thought about this when I added
mprotect_pkey(). We start with:mprotect(addr, len, prot);then
mprotect_pkey(addr, len, prot);then
mprotect_pkey_encrypt(addr, len, prot, key);That doesn't scale because we eventually have
mprotect_and_a_history_of_mm_features(). :)What I was hoping to see was them do this (apologies for the horrible indentation:
Quoted 8 lines
ptr = mmap(..., PROT_NONE); mprotect_pkey( addr, len, PROT_NONE, pkey); mprotect_encrypt(addr, len, PROT_NONE, keyid); mprotect( addr, len, real_prot);The point is that you *can* stack these things and don't have to have an
mprotect_kitchen_sink()if you usePROT_NONEfor intermediate permissions during setup.
Sure, but then why call it mprotect at all? How about:
mmap(..., PROT_NONE);mencrypt(..., keyid);mprotect_pkey(...);
But wouldn't this be much nicer:
int fd = memfd_create(...); memfd_set_tme_key(fd, keyid); /* fails if len != 0 */ mmap(fd, ...);
Quoted 8 lines
Quoted 5 lines
and it's also functionally just
MADV_DONTNEED. In other words, the sole user-visible effect appears to be that the existing pages are blown away. The fact that it changes the key in use doesn't seem terribly useful, since it's anonymous memory,It's functionally
MADV_DONTNEED, plus a future promise that your writes will never show up as plaintext on the DIMM.
But that's mostly vacuous. If I read the docs right, MKTME systems also support TME, so you *already* have that promise, unless the firmware totally blew it. If we want a boot option to have the kernel use MKTME to forcibly encrypt everything regardless of what the TME MSRs say, I'd be entirely on board. Heck, the implementation would be quite simple because we mostly reuse the SME code.
Quoted 8 lines
We also haven't settled on the file-backed properties. For file-backed, my hope was that you could do:
ptr = mmap(fd, size, prot); printf("ciphertext: %x\n", *ptr); mprotect_encrypt(ptr, len, prot, keyid); printf("plaintext: %x\n", *ptr);
Why would you ever want the plaintext? Also, how does this work on a normal fs, where relocation of the file would cause the ciphertext to get lost? It really seems to be that it should look more like dm-crypt where you encrypt a filesystem. Maybe you'd just configure the pmem device to be encrypted before you mount it, or you'd get a new pmem-mktme device node instead. This would also avoid some nasty multiple-copies-of-the-direct-map issue, since you'd only ever have one of them mapped.
Quoted 9 lines
Quoted 8 lines
The main implementation concern I have with this patch set is cache coherency and handling of the direct map. Unless I missed something, you're not doing anything about the direct map, which means that you have RW aliases of the same memory with different keys. For use case #2, this probably means that you need to either get rid of the direct map and make
get_user_pages()fail, or you need to change the key on the direct map as well, probably using thepageattr.ccode.
Quoted 4 lines
The current, public hardware spec has a description of what's required to maintain cache coherency. Basically, you can keep as many mappings of a physical page as you want, but only write to one mapping at a time, and clflush the old one when you want to write to a new one.
Surely you at least have to clflush the old mapping and then the new mapping, since the new mapping could have been speculatively read.
Quoted 11 lines
Quoted 6 lines
Finally, If you're going to teach the kernel how to have some user pages that aren't in the direct map, you've essentially done XPO, which is nifty but expensive. And I think that doing this gets you essentially all the benefit of MKTME for the non-pmem use case. Why exactly would any software want to use anything other than a CPU-managed key for anything other than pmem?
It is handy, for one, to let you "cluster" key usage. If you have 5 Pepsi VMs and 5 Coke VMs, each Pepsi one using the same key and each Coke one using the same key, you can boil it down to only 2 hardware keyid slots that get used, and do this transparently.
I understand this from a marketing perspective but not a security perspective. Say I'm Coke and you've sold me some VMs that are "encrypted with a Coke-specific key and no other VMs get to use that key." I can't think of *any* not-exceedingly-contrived attack in which this makes the slightest difference. If Pepsi tries to attack Coke without MKTME, then they'll either need to get the hypervisor to leak Coke's data through the direct map or they'll have to find some way to corrupt a page table or use something like L1TF to read from a physical address Coke owns. With MKTME, if they can read through the host direct map, then they'll get Coke's cleartext, and if they can corrupt a page table or use L1TF to read from your memory, they'll get Coke's cleartext.
TME itself provides a ton of protection -- you can't just barge into the datacenter, refrigerate the DIMMs, walk away with them, and read off everyone's data.
Am I missing something?
Quoted 5 lines
But, I think what you're implying is that the security properties of user-supplied keys can only be *worse* than using CPU-generated keys (assuming the CPU does a good job generating it). So, why bother allowing user-specified keys in the first place?
That too :)
[ only responding to the pmem side of things... ]
Quoted 2 lines · Andy Lutomirski
On Wed, Dec 5, 2018 at 3:49 PM Dave Hansen <[email protected]> wrote:
[..]
Quoted 8 lines
Quoted 7 lines
We also haven't settled on the file-backed properties. For file-backed, my hope was that you could do:
ptr = mmap(fd, size, prot); printf("ciphertext: %x\n", *ptr); mprotect_encrypt(ptr, len, prot, keyid); printf("plaintext: %x\n", *ptr);
Quoted 8 lines
Why would you ever want the plaintext? Also, how does this work on a normal fs, where relocation of the file would cause the ciphertext to get lost? It really seems to be that it should look more like dm-crypt where you encrypt a filesystem. Maybe you'd just configure the pmem device to be encrypted before you mount it, or you'd get a new pmem-mktme device node instead. This would also avoid some nasty multiple-copies-of-the-direct-map issue, since you'd only ever have one of them mapped.
Yes, this is really the only way it can work. Otherwise you need to teach the filesystem that "these blocks can't move without the key because encryption", and have an fs-feature flag to say "you can't mount this legacy / encryption unaware filesystem from an older kernel because we're not sure you'll move something and break the encryption".
So pmem namespaces (volumes) would be encrypted providing something similar to dm-crypt, although we're looking at following the lead of the fscrypt key management scheme.
Quoted 13 lines · Andy Lutomirski
Quoted 11 lines · Dave Hansen
What I was hoping to see was them do this (apologies for the horrible indentation:
ptr = mmap(..., PROT_NONE); mprotect_pkey( addr, len, PROT_NONE, pkey); mprotect_encrypt(addr, len, PROT_NONE, keyid); mprotect( addr, len, real_prot);The point is that you *can* stack these things and don't have to have an
mprotect_kitchen_sink()if you usePROT_NONEfor intermediate permissions during setup.
Quoted 5 lines
Sure, but then why call it mprotect at all? How about:
mmap(..., PROT_NONE);mencrypt(..., keyid);mprotect_pkey(...);
That would totally work too. I just like the idea of a family of mprotect() syscalls that do mprotect() plus one other thing. What you're proposing is totally equivalent where we have mprotect_pkey() always being the *last* thing that gets called, plus a family of things that we expect to get called on something that's probably PROT_NONE.
Quoted 5 lines
But wouldn't this be much nicer:
int fd =
memfd_create(...);memfd_set_tme_key(fd, keyid); /* fails if len != 0 */mmap(fd, ...);
No. :)
One really big advantage with protection keys, or this implementation is that you don't have to implement an allocator. You can use it with any old malloc() as long as you own a whole page.
The pages also fundamentally *stay* anonymous in the VM and get all the goodness that comes with that, like THP.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
and it's also functionally just
MADV_DONTNEED. In other words, the sole user-visible effect appears to be that the existing pages are blown away. The fact that it changes the key in use doesn't seem terribly useful, since it's anonymous memory,It's functionally
MADV_DONTNEED, plus a future promise that your writes will never show up as plaintext on the DIMM.
Quoted 6 lines
But that's mostly vacuous. If I read the docs right, MKTME systems also support TME, so you *already* have that promise, unless the firmware totally blew it. If we want a boot option to have the kernel use MKTME to forcibly encrypt everything regardless of what the TME MSRs say, I'd be entirely on board. Heck, the implementation would be quite simple because we mostly reuse the SME code.
Yeah, that's true. I seem to always forget about the TME case! :)
"It's functionally MADV_DONTNEED, plus a future promise that your writes will never be written to the DIMM with the TME key."
But, this gets us back to your very good question about what good this does in the end. What value does _that_ scheme provide over TME? We're admittedly weak on specific examples there, but I'm working on it.
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
the direct map as well, probably using the
pageattr.ccode.The current, public hardware spec has a description of what's required to maintain cache coherency. Basically, you can keep as many mappings of a physical page as you want, but only write to one mapping at a time, and clflush the old one when you want to write to a new one.
Surely you at least have to clflush the old mapping and then the new mapping, since the new mapping could have been speculatively read.
Nope. The coherency is "fine" unless you have writeback of an older cacheline that blows away newer data. CPUs that support MKTME are guaranteed to never do writeback of the lines that could be established speculatively or from prefetching.
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Finally, If you're going to teach the kernel how to have some user pages that aren't in the direct map, you've essentially done XPO, which is nifty but expensive. And I think that doing this gets you essentially all the benefit of MKTME for the non-pmem use case. Why exactly would any software want to use anything other than a CPU-managed key for anything other than pmem?
It is handy, for one, to let you "cluster" key usage. If you have 5 Pepsi VMs and 5 Coke VMs, each Pepsi one using the same key and each Coke one using the same key, you can boil it down to only 2 hardware keyid slots that get used, and do this transparently.
Quoted 12 lines
I understand this from a marketing perspective but not a security perspective. Say I'm Coke and you've sold me some VMs that are "encrypted with a Coke-specific key and no other VMs get to use that key." I can't think of *any* not-exceedingly-contrived attack in which this makes the slightest difference. If Pepsi tries to attack Coke without MKTME, then they'll either need to get the hypervisor to leak Coke's data through the direct map or they'll have to find some way to corrupt a page table or use something like L1TF to read from a physical address Coke owns. With MKTME, if they can read through the host direct map, then they'll get Coke's cleartext, and if they can corrupt a page table or use L1TF to read from your memory, they'll get Coke's cleartext.
The design definitely has the hypervisor in the trust boundary. If the hypervisor is evil, or if someone evil compromises the hypervisor, MKTME obviously provides less protection.
I guess the question ends up being if this makes its protections weak enough that we should not bother merging it in its current form.
I still have the homework assignment to go figure out why folks want the protections as they stand.
Andy Lutomirski
maintainerQuoted 9 lines · Dave Hansen
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
the direct map as well, probably using the
pageattr.ccode.The current, public hardware spec has a description of what's required to maintain cache coherency. Basically, you can keep as many mappings of a physical page as you want, but only write to one mapping at a time, and clflush the old one when you want to write to a new one.
Quoted 7 lines
Quoted 2 lines
Surely you at least have to clflush the old mapping and then the new mapping, since the new mapping could have been speculatively read.
Nope. The coherency is "fine" unless you have writeback of an older cacheline that blows away newer data. CPUs that support MKTME are guaranteed to never do writeback of the lines that could be established speculatively or from prefetching.
How is that sufficient? Suppose I have some physical page mapped with keys 1 and 2. #1 is logically live and I write to it. Then I prefetch or otherwise populate mapping 2 into the cache (in the S state, presumably). Now I clflush mapping 1 and read 2. It contains garbage in the cache, but the garbage in the cache is inconsistent with the garbage in memory. This can’t be a good thing, even if no writeback occurs.
I suppose the right fix is to clflush the old mapping and then to zero the new mapping.
Quoted 26 lines
Quoted 13 lines
Quoted 8 lines
Quoted 7 lines
Finally, If you're going to teach the kernel how to have some user pages that aren't in the direct map, you've essentially done XPO, which is nifty but expensive. And I think that doing this gets you essentially all the benefit of MKTME for the non-pmem use case. Why exactly would any software want to use anything other than a CPU-managed key for anything other than pmem?
Quoted 4 lines
It is handy, for one, to let you "cluster" key usage. If you have 5 Pepsi VMs and 5 Coke VMs, each Pepsi one using the same key and each Coke one using the same key, you can boil it down to only 2 hardware keyid slots that get used, and do this transparently.
Quoted 12 lines
I understand this from a marketing perspective but not a security perspective. Say I'm Coke and you've sold me some VMs that are "encrypted with a Coke-specific key and no other VMs get to use that key." I can't think of *any* not-exceedingly-contrived attack in which this makes the slightest difference. If Pepsi tries to attack Coke without MKTME, then they'll either need to get the hypervisor to leak Coke's data through the direct map or they'll have to find some way to corrupt a page table or use something like L1TF to read from a physical address Coke owns. With MKTME, if they can read through the host direct map, then they'll get Coke's cleartext, and if they can corrupt a page table or use L1TF to read from your memory, they'll get Coke's cleartext.
Quoted 6 lines
The design definitely has the hypervisor in the trust boundary. If the hypervisor is evil, or if someone evil compromises the hypervisor, MKTME obviously provides less protection.
I guess the question ends up being if this makes its protections weak enough that we should not bother merging it in its current form.
Indeed, but I’d ask another question too: I expect that MKTME is weak enough that it will be improved, and without seeing the improvement, it seems quite plausible that using the improvement will require radically reworking the kernel implementation.
As a straw man, suppose we get a way to say “this key may only be accessed through such-and-such VPID or by using a special new
restricted facility for the hypervisor to request access”. Now we
have some degree of serious protection, but it doesn’t work, by design, for anonymous memory. Similarly, something that looks more like AMD's SEV would be very very awkward to support with anything like the current API proposal.
Quoted 3 lines
I still have the homework assignment to go figure out why folks want the protections as they stand.
Quoted 14 lines · Andy Lutomirski
Quoted 5 lines · Dave Hansen
The coherency is "fine" unless you have writeback of an older cacheline that blows away newer data. CPUs that support MKTME are guaranteed to never do writeback of the lines that could be established speculatively or from prefetching.
How is that sufficient? Suppose I have some physical page mapped with keys 1 and 2. #1 is logically live and I write to it. Then I prefetch or otherwise populate mapping 2 into the cache (in the S state, presumably). Now I clflush mapping 1 and read 2. It contains garbage in the cache, but the garbage in the cache is inconsistent with the garbage in memory. This can’t be a good thing, even if no writeback occurs.
Quoted 2 lines
I suppose the right fix is to clflush the old mapping and then to zero the new mapping.
Yep. Practically, you need to write to the new mapping to give it any meaning. Those writes effectively blow away any previously cached, garbage contents.
I think you're right, though, that the cached data might not be _consistent_ with what is in memory. It feels really dirty, but I can't think of any problems that it actually causes.
DQo+IA0KPiBUTUUgaXRzZWxmIHByb3ZpZGVzIGEgdG9uIG9mIHByb3RlY3Rpb24gLS0geW91IGNh bid0IGp1c3QgYmFyZ2UgaW50bw0KPiB0aGUgZGF0YWNlbnRlciwgcmVmcmlnZXJhdGUgdGhlIERJ TU1zLCB3YWxrIGF3YXkgd2l0aCB0aGVtLCBhbmQgcmVhZA0KPiBvZmYgZXZlcnlvbmUncyBkYXRh Lg0KPiANCj4gQW0gSSBtaXNzaW5nIHNvbWV0aGluZz8NCg0KSSB0aGluayB3ZSBjYW4gbWFrZSBz dWNoIGFzc3VtcHRpb24gaW4gbW9zdCBjYXNlcywgYnV0IEkgdGhpbmsgaXQncyBiZXR0ZXIgdGhh dCB3ZSBkb24ndCBtYWtlIGFueQ0KYXNzdW1wdGlvbiBhdCBhbGwuIEZvciBleGFtcGxlLCB0aGUg YWRtaW4gb2YgZGF0YSBjZW50ZXIgKG9yIGFueW9uZSkgd2hvIGhhcyBwaH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lcXVpcmUgdGVuYW50IHRvIHNlbmQg a2V5IHRvIENTUC4gRm9yIGV4YW1wbGUsIHRoZSBWTQ0KaW1hZ2UgY2FuIGJlIHByb3ZpZGVkIGJ5 IHRlbmFudCBhbmQgZW5jcnlwdGVkIGJ5IHRlbmFudCdzIG93biBrZXksIGFuZCB0ZW5hbnQgbmVl ZHMgdG8gc2VuZCBrZXkgdG8NCkNTUCB3aGVuIGFza2luZyBDU1AgdG8gcnVuIHRoYXQgZW5jcnlw dGVkIGltYWdlLiBCdXQgdGVuYW50IHdpbGwgbmVlZCB0byB0cnVzdCBDU1AgaW4gc3VjaCBjYXNl LA0Kd2hpY2ggYnJpbmdzIHVzIHdoeSB0ZW5hbnQgd2FudHMgdG8gdXNlIGhpcyBvd24gaW1hZ2Ug YXQgZmlyc3QgcGxhY2UgKEkgaGF2ZSB0byBzYXkgSSBteXNlbGYgaXMgbm90DQpjb252aW5jZWQg dGhlIHZhbHVlIG9mIHN1Y2ggdXNlIGNhc2UpLiBJIHRoaW5rIHRoZXJlIGFyZSB0d28gbGV2ZWxz IG9mIHRydXN0aW5lc3MgaW52b2x2ZWQgaGVyZTogMSkNCnRlbmFudCBuZWVkcyB0byB0cnVzdCBD U1AgYW55d2F5OyAyKSBidXQgQ1NQIG5lZWRzIHRvIGNvbnZpbmNlIHRlbmFudCB0aGF0IENTUCBj YW4gYmUgdHJ1c3RlZCwgaWUsDQpieSBwcm92aW5nIGl0IGNhbiBwcmV2ZW50IHBvdGVudGlhbCBh dHRhY2sgZnJvbSBtYWxpY2lvdXMgZW1wbG95ZWUgKGllLCBieSByYWlzaW5nIGJhciBieSB1c2lu Zw0KTUtUTUUpLCBldGMuDQoNClRoYW5rcywNCi1LYWk
Quoted 3 lines · Kai
I think one usage of user-specified key is for NVDIMM, since CPU key will be gone after machine reboot, therefore if NVDIMM is encrypted by CPU key we are not able to retrieve it once shutdown/reboot, etc.
I think we all agree that the NVDIMM uses are really useful.
But, these patches don't implement that. So, if NVDIMMs are the only reasonable use case, we shouldn't merge these patches until we add NVDIMM support.
Andy Lutomirski
maintainerQuoted 25 lines · Kai
Quoted 8 lines
TME itself provides a ton of protection -- you can't just barge into the datacenter, refrigerate the DIMMs, walk away with them, and read off everyone's data.
Am I missing something?
I think we can make such assumption in most cases, but I think it's better that we don't make any assumption at all. For example, the admin of data center (or anyone) who has physical access to servers may do something malicious. I am not expert but there should be other physical attack methods besides coldboot attack, if the malicious employee can get physical access to server w/o being detected.
Quoted 8 lines
Quoted 6 lines
But, I think what you're implying is that the security properties of user-supplied keys can only be *worse* than using CPU-generated keys (assuming the CPU does a good job generating it). So, why bother allowing user-specified keys in the first place?
That too :)
Quoted 7 lines
I think one usage of user-specified key is for NVDIMM, since CPU key will be gone after machine reboot, therefore if NVDIMM is encrypted by CPU key we are not able to retrieve it once shutdown/reboot, etc.
There are some other use cases that already require tenant to send key to CSP. For example, the VM image can be provided by tenant and encrypted by tenant's own key, and tenant needs to send key to CSP when asking CSP to run that encrypted image.
I can imagine a few reasons why one would want to encrypt one’s image. For example, the CSP could issue a public key and state, or even attest, that the key is wrapped and locked to particular PCRs of their TPM or otherwise protected by an enclave that verifies that the key is only used to decrypt the image for the benefit of a hypervisor.
I don’t see what MKTME has to do with this. The only remotely plausible way I can see to use MKTME for this is to have the hypervisor load a TPM (or other enclave) protected key into an MKTME user key slot and to load customer-provided ciphertext into the corresponding physical memory (using an MKTME no-encrypt slot). But this has three major problems. First, it's effectively just a fancy way to avoid one AES pass over the data. Second, sensible scheme for this type of VM image protection would use *authenticated* encryption or at least verify a signature, which MKTME can't do. The third problem is the real show-stopper, though: this scheme requires that the ciphertext go into predetermined physical addresses, which would be a giant mess.
Quoted 3 lines · Andy Lutomirski
The third problem is the real show-stopper, though: this scheme requires that the ciphertext go into predetermined physical addresses, which would be a giant mess.
There's a more fundamental problem than that. The tweak fed into the actual AES-XTS operation is determined by the firmware, programmed into the memory controller, and is not visible to software. So, not only would you need to put stuff at a fixed physical address, the tweaks can change from boot-to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