The comment in share() warns that sharing operates on whole pages and
can expose unintended data to the hypervisor. Memory whose previous
contents must remain private therefore needs to be cleared before
uv_set_shared() makes it accessible to the host.

The common CoCo allocator masks __GFP_ZERO because a private-to-shared
transition may modify memory contents, and currently clears the
allocation after sharing. On s390, that ordering could expose previous
contents before the clear.

Clear the range in set_memory_decrypted() before calling
uv_set_shared(). This also establishes the zeroing guarantee that
subsequent patches will use to remove redundant caller-side clears.

Cc: Alexander Gordeev <[email protected]>
Cc: Gerald Schaefer <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Signed-off-by: Aneesh Kumar K.V (Arm) <[email protected]>
---
 arch/s390/mm/init.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index be7e009e7b59..fdacd9380286 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -129,6 +129,13 @@ int set_memory_encrypted(unsigned long vaddr, int numpages)
 int set_memory_decrypted(unsigned long vaddr, int numpages)
 {
        int i;
+
+       /*
+        * uv_set_shared() exposes existing contents to the host; see the data
+        * leakage warning in share() in asm/uv.h. Clear private data first.
+        */
+       memset((void *)vaddr, 0, (size_t)numpages << PAGE_SHIFT);
+
        /* make specified pages shared (swiotlb, dma_alloca) */
        for (i = 0; i < numpages; ++i) {
                uv_set_shared(virt_to_phys((void *)vaddr));
-- 
2.43.0

Reply via email to