qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philippe.mathieu.daude@gmail.com>
To: Tyler Fanelli <tfanelli@redhat.com>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, mtosatti@redhat.com, berrange@redhat.com,
	kvm@vger.kernel.org
Subject: Re: [PATCH v3] i386/sev: Ensure attestation report length is valid before retrieving
Date: Sat, 5 Mar 2022 12:25:12 +0100	[thread overview]
Message-ID: <8624c864-b459-f178-a8be-20ee6bac780b@gmail.com> (raw)
In-Reply-To: <20220304201141.509492-1-tfanelli@redhat.com>

On 4/3/22 21:11, Tyler Fanelli wrote:
> The length of the attestation report buffer is never checked to be
> valid before allocation is made. If the length of the report is returned
> to be 0, the buffer to retrieve the attestation buffer is allocated with
> length 0 and passed to the kernel to fill with contents of the attestation
> report. Leaving this unchecked is dangerous and could lead to undefined
> behavior.
> 
> Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
> ---
>   target/i386/sev.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/target/i386/sev.c b/target/i386/sev.c
> index 025ff7a6f8..e82be3e350 100644
> --- a/target/i386/sev.c
> +++ b/target/i386/sev.c
> @@ -616,6 +616,8 @@ static SevAttestationReport *sev_get_attestation_report(const char *mnonce,
>           return NULL;
>       }
>   
> +    input.len = 0;

I agree with Daniel's review of your v1:

   "The declaration of 'input' already zero initializes."

https://lore.kernel.org/qemu-devel/YiJi9IYqtZvNQIRc@redhat.com/

>       /* Query the report length */
>       ret = sev_ioctl(sev->sev_fd, KVM_SEV_GET_ATTESTATION_REPORT,
>               &input, &err);
> @@ -626,6 +628,11 @@ static SevAttestationReport *sev_get_attestation_report(const char *mnonce,
>                          ret, err, fw_error_to_str(err));
>               return NULL;
>           }
> +    } else if (input.len == 0) {
> +        error_setg(errp, "SEV: Failed to query attestation report:"
> +                         " length returned=%u",
> +                   input.len);
> +        return NULL;
>       }
>   
>       data = g_malloc(input.len);



  reply	other threads:[~2022-03-05 11:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04 20:11 [PATCH v3] i386/sev: Ensure attestation report length is valid before retrieving Tyler Fanelli
2022-03-05 11:25 ` Philippe Mathieu-Daudé [this message]
2022-03-07 10:20 ` Daniel P. Berrangé

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=8624c864-b459-f178-a8be-20ee6bac780b@gmail.com \
    --to=philippe.mathieu.daude@gmail.com \
    --cc=berrange@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=tfanelli@redhat.com \
    /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).