Re: [PATCH v3] KVM: SEV: Add KVM_SEV_SNP_HV_REPORT_REQ command

From: Thomas Courrege

Date: Sat Jan 24 2026 - 09:41:09 EST


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;
>> + 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).

>> +
>> + 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