From: "Kirill A. Shutemov" Date: Wed, 08 May 2019 14:44:21 +0000 Subject: [PATCH, RFC 61/62] x86/mktme: Document the MKTME API for anonymous memory encryption Message-Id: <20190508144422.13171-62-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-10" Content-Transfer-Encoding: quoted-printable List-Id: References: <20190508144422.13171-1-kirill.shutemov@linux.intel.com> In-Reply-To: <20190508144422.13171-1-kirill.shutemov@linux.intel.com> To: Andrew Morton , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , David Howells Cc: Kees Cook , Dave Hansen , Kai Huang , Jacob Pan , Alison Schofield , linux-mm@kvack.org, kvm@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" From: Alison Schofield Signed-off-by: Alison Schofield Signed-off-by: Kirill A. Shutemov --- Documentation/x86/mktme/index.rst | 1 + Documentation/x86/mktme/mktme_encrypt.rst | 57 +++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Documentation/x86/mktme/mktme_encrypt.rst diff --git a/Documentation/x86/mktme/index.rst b/Documentation/x86/mktme/in= dex.rst index 8cf2b7d62091..ca3c76adc596 100644 --- a/Documentation/x86/mktme/index.rst +++ b/Documentation/x86/mktme/index.rst @@ -9,3 +9,4 @@ Multi-Key Total Memory Encryption (MKTME) mktme_mitigations mktme_configuration mktme_keys + mktme_encrypt diff --git a/Documentation/x86/mktme/mktme_encrypt.rst b/Documentation/x86/= mktme/mktme_encrypt.rst new file mode 100644 index 000000000000..5cdffabc610f --- /dev/null +++ b/Documentation/x86/mktme/mktme_encrypt.rst @@ -0,0 +1,57 @@ +MKTME API: system call encrypt_mprotect() +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ +Synopsis +-------- +int encrypt_mprotect(void \*addr, size_t len, int prot, key_serial_t seria= l); + +Where *key_serial_t serial* is the serial number of a key allocated +using the MKTME Key Service. + +Description +----------- + encrypt_mprotect() encrypts the memory pages containing any part + of the address range in the interval specified by addr and len. + + encrypt_mprotect() supports the legacy mprotect() behavior plus + the enabling of memory encryption. That means that in addition + to encrypting the memory, the protection flags will be updated + as requested in the call. + + The *addr* and *len* must be aligned to a page boundary. + + The caller must have *KEY_NEED_VIEW* permission on the key. + + The range of memory that is to be protected must be mapped as + *ANONYMOUS*. + +Errors +------ + In addition to the Errors returned from legacy mprotect() + encrypt_mprotect will return: + + ENOKEY *serial* parameter does not represent a valid key. + + EINVAL *len* parameter is not page aligned. + + EACCES Caller does not have *KEY_NEED_VIEW* permission on the key. + +EXAMPLE +-------- + Allocate an MKTME Key:: + serial =3D add_key("mktme", "name", "type=3Dcpu algorithm=AEs-xts-= 128" @u + + Map ANONYMOUS memory:: + ptr =3D mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1,= 0); + + Protect memory:: + ret =3D syscall(SYS_encrypt_mprotect, ptr, size, PROT_READ|PROT_WR= ITE, + serial); + + Use the encrypted memory + + Free memory:: + ret =3D munmap(ptr, size); + + Free the key resource:: + ret =3D keyctl(KEYCTL_INVALIDATE, serial); --=20 2.20.1