From: Tom Lendacky <thomas.lendacky@amd.com>
To: Thomas Courrege <thomas.courrege@thorondor.fr>,
ashish.kalra@amd.com, corbet@lwn.net,
herbert@gondor.apana.org.au, john.allen@amd.com, nikunj@amd.com,
pbonzini@redhat.com, seanjc@google.com
Cc: kvm@vger.kernel.org, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH v3] KVM: SEV: Add KVM_SEV_SNP_HV_REPORT_REQ command
Date: Sat, 24 Jan 2026 10:27:17 -0600 [thread overview]
Message-ID: <2882b35a-89ac-4f91-abf3-a3b64e7770eb@amd.com> (raw)
In-Reply-To: <879f354c-822f-4902-8cc3-6cf9557db969@thorondor.fr>
On 1/24/26 08:40, Thomas Courrege wrote:
> Sorry, i didn't saw the response, i changed the email i use.
>
> On 21-01-2026 00:45, Tom Lendacky wrote:
>> On 12/15/25 08:14, Thomas Courrege wrote:
>>
>>> + size_t rsp_size = sizeof(*report_rsp);
>>> + int ret;
>> The declarations above should be in reverse fir tree order.
>
> Like that ?
> struct sev_data_snp_msg_report_rsp *report_rsp;
> struct sev_data_snp_hv_report_req data;
> struct kvm_sev_snp_hv_report_req params;
> struct kvm_sev_info *sev = to_kvm_sev_info(kvm);
> size_t rsp_size = sizeof(*report_rsp);
> void __user *u_report;
> void __user *u_params;
> int ret;
struct kvm_sev_info *sev = to_kvm_sev_info(kvm);
struct sev_data_snp_msg_report_rsp *report_rsp;
struct kvm_sev_snp_hv_report_req params;
struct sev_data_snp_hv_report_req data;
size_t rsp_size = sizeof(*report_rsp);
void __user *u_report;
void __user *u_params;
int ret;
>>> + if (ret)
>>> + goto e_free_rsp;
>>> +
>>> + if (!report_rsp->status)
>>> + rsp_size += report_rsp->report_size;
>>> +
>>> + if (params.report_len < rsp_size) {
>>> + rsp_size = sizeof(*report_rsp);
>>> + ret = -ENOSPC;
>>> + }
>> This can be contained within the if above it, right?
>>
>> if (!report_rsp->status) {
>> if (params.report_len < (rsp_size + report_rsp->report_size))
>> ret = -ENOSPC;
>> else
>> rsp_size += report_rsp->report_size;
>> }
>
> This leads to an error in case the user wants to query the report size.
>
>
> Using params.report_len = 32, the nested if is true and thus the user get
>
> back the default rsp_size (= 32), not increased with report_size (= 1184).
But isn't params.report_len set below to the proper value since it wasn't
using rsp_size? The rsp_size variable is only used for the copy_to_user()
for the report itself. Assuming you want to copy what's in 'rsp' no matter
the return code you get, then can't you just do:
if (!report_rsp->status) {
if (params.report_len < (rsp_size + report_rsp->report_size))
ret = -ENOSPC;
else
rsp_size += report_rsp->report_size;
params.report_len = sizeof(*report_rsp) + report_rsp->report_size;
}
if (copy_to_user(u_report, report_rsp, rsp_size))
ret = -EFAULT;
Thanks,
Tom
>
>>> +
>>> + if (copy_to_user(u_report, report_rsp, rsp_size))
>>> + ret = -EFAULT;
>>> +
>>> + params.report_len = sizeof(*report_rsp) + report_rsp->report_size;
>> I'm not sure if we can rely on report_rsp->report_size being valid if
>> resport_rsp->status is not zero. So maybe just set this to rsp_size.
>>
>> Thanks,
>> Tom
> maybe something like this ? to avoid copying on ENOSPC, where this issue come from
>
> if (!report_rsp->status)
> rsp_size += report_rsp->report_size;
>
> if (params.report_len < rsp_size) {
> ret = -ENOSPC;
> } else {
> if (copy_to_user(u_report, report_rsp, rsp_size))
> ret = -EFAULT;
> }
>
> params.report_len = rsp_size;
>
>
> To test this specific case :
> https://github.com/Th0rOnDoR/test-length-sev/blob/main/sev_test.c
>
> Thanks,
> Thomas
next prev parent reply other threads:[~2026-01-24 16:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 14:14 [PATCH v3] KVM: SEV: Add KVM_SEV_SNP_HV_REPORT_REQ command Thomas Courrege
2026-01-12 8:12 ` Thomas Courrege
2026-01-20 23:45 ` Tom Lendacky
2026-01-24 14:40 ` Thomas Courrege
2026-01-24 16:27 ` Tom Lendacky [this message]
2026-01-24 20:29 ` xen
-- strict thread matches above, loose matches on Subject: below --
2025-12-15 14:09 Thomas Courrege
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=2882b35a-89ac-4f91-abf3-a3b64e7770eb@amd.com \
--to=thomas.lendacky@amd.com \
--cc=ashish.kalra@amd.com \
--cc=corbet@lwn.net \
--cc=herbert@gondor.apana.org.au \
--cc=john.allen@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=thomas.courrege@thorondor.fr \
--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