linux-coco.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "kirill.shutemov@linux.intel.com"
	<kirill.shutemov@linux.intel.com>,
	"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
	"lirongqing@baidu.com" <lirongqing@baidu.com>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"x86@kernel.org" <x86@kernel.org>
Subject: Re: [PATCH] virt: tdx-guest: Fix the decrypted failure memory free
Date: Thu, 13 Jun 2024 16:10:37 +0000	[thread overview]
Message-ID: <0f6752d0ff95ba9d4fdafdfba1b37c9a140c773d.camel@intel.com> (raw)
In-Reply-To: <20240613111931.43123-1-lirongqing@baidu.com>

Thanks.

On Thu, 2024-06-13 at 19:19 +0800, Li RongQing wrote:
> In CoCo VMs it is possible for the untrusted host to cause
> set_memory_encrypted() or 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.
> 
> When set_memory_decrypted() fails, the memory should be encrypted
> via set_memory_encrypted(); if encrypting the memory fails, leak it
> 
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>  drivers/virt/coco/tdx-guest/tdx-guest.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-
> guest/tdx-guest.c
> index 1253bf7..63271fc 100644
> --- a/drivers/virt/coco/tdx-guest/tdx-guest.c
> +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
> @@ -125,7 +125,8 @@ static void *alloc_quote_buf(void)
>                 return NULL;
>  
>         if (set_memory_decrypted((unsigned long)addr, count)) {
> -               free_pages_exact(addr, len);
> +               if (!set_memory_encrypted((unsigned long)addr, count))
> +                       free_pages_exact(addr, len);

In the other cases the general consensus was to not optimize for this failure.
As in, don't try to re-encrypt the pages first, just give up and leak them on
the first failure. So the fix could just be to remove the free_pages_exact()
call. I think we should stick with that pattern.

>                 return NULL;
>         }

On another note, it looks like that this one popped up after we made the
previous sweep to fix the pattern. Maybe it was in-flight at the time, but since
it even popped up in TDX specific code, it makes me wonder again about how we
can keep on top of the problem.

  parent reply	other threads:[~2024-06-13 16:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-13 11:19 [PATCH] virt: tdx-guest: Fix the decrypted failure memory free Li RongQing
2024-06-13 16:07 ` Dave Hansen
2024-06-13 16:13   ` Edgecombe, Rick P
2024-06-13 16:10 ` Edgecombe, Rick P [this message]
2024-06-14  4:48   ` [外部邮件] " Li,Rongqing

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=0f6752d0ff95ba9d4fdafdfba1b37c9a140c773d.camel@intel.com \
    --to=rick.p.edgecombe@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-coco@lists.linux.dev \
    --cc=lirongqing@baidu.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).