virt: tdx-guest: Just leak decrypted memory on unrecoverable errors
authorLi RongQing <lirongqing@baidu.com>
Wed, 19 Jun 2024 11:18:01 +0000 (19:18 +0800)
committerIngo Molnar <mingo@kernel.org>
Sun, 29 Dec 2024 09:18:44 +0000 (10:18 +0100)
In CoCo VMs it is possible for the untrusted host to cause
set_memory_decrypted() to fail such that an error is returned
and the resulting memory is shared. Callers need to take care
to handle these errors to avoid returning decrypted (shared)
memory to the page allocator, which could lead to functional
or security issues.

Leak the decrypted memory when set_memory_decrypted() fails,
and don't need to print an error since set_memory_decrypted()
will call WARN_ONCE().

Fixes: f4738f56d1dc ("virt: tdx-guest: Add Quote generation support using TSM_REPORTS")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20240619111801.25630-1-lirongqing%40baidu.com
drivers/virt/coco/tdx-guest/tdx-guest.c

index d7db6c824e13de307459e853f8a130ecd6186fa1..224e7dde9cdee877fd587d2fc974f2ccc7481d0f 100644 (file)
@@ -124,10 +124,8 @@ static void *alloc_quote_buf(void)
        if (!addr)
                return NULL;
 
-       if (set_memory_decrypted((unsigned long)addr, count)) {
-               free_pages_exact(addr, len);
+       if (set_memory_decrypted((unsigned long)addr, count))
                return NULL;
-       }
 
        return addr;
 }