[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <54f916af-1d10-4a8e-1e14-cd261d407dd2@amd.com>
Date: Mon, 19 Jul 2021 09:24:15 -0500
From: Brijesh Singh <brijesh.singh@....com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: brijesh.singh@....com, x86@...nel.org,
linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
linux-efi@...r.kernel.org, platform-driver-x86@...r.kernel.org,
linux-coco@...ts.linux.dev, linux-mm@...ck.org,
linux-crypto@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Joerg Roedel <jroedel@...e.de>,
Tom Lendacky <thomas.lendacky@....com>,
"H. Peter Anvin" <hpa@...or.com>, Ard Biesheuvel <ardb@...nel.org>,
Paolo Bonzini <pbonzini@...hat.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Andy Lutomirski <luto@...nel.org>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Sergio Lopez <slp@...hat.com>, Peter Gonda <pgonda@...gle.com>,
Peter Zijlstra <peterz@...radead.org>,
Srinivas Pandruvada <srinivas.pandruvada@...ux.intel.com>,
David Rientjes <rientjes@...gle.com>,
Dov Murik <dovmurik@...ux.ibm.com>,
Tobin Feldman-Fitzthum <tobin@....com>,
Borislav Petkov <bp@...en8.de>,
Michael Roth <michael.roth@....com>,
Vlastimil Babka <vbabka@...e.cz>, tony.luck@...el.com,
npmccallum@...hat.com, brijesh.ksingh@...il.com
Subject: Re: [PATCH Part2 RFC v4 34/40] KVM: SVM: Add support to handle Page
State Change VMGEXIT
On 7/16/21 4:14 PM, Sean Christopherson wrote:
> On Wed, Jul 07, 2021, Brijesh Singh wrote:
>> +static unsigned long snp_handle_psc(struct vcpu_svm *svm, struct ghcb *ghcb)
>> +{
>> + struct kvm_vcpu *vcpu = &svm->vcpu;
>> + int level, op, rc = PSC_UNDEF_ERR;
>> + struct snp_psc_desc *info;
>> + struct psc_entry *entry;
>> + gpa_t gpa;
>> +
>> + if (!sev_snp_guest(vcpu->kvm))
>> + goto out;
>> +
>> + if (!setup_vmgexit_scratch(svm, true, sizeof(ghcb->save.sw_scratch))) {
>> + pr_err("vmgexit: scratch area is not setup.\n");
>> + rc = PSC_INVALID_HDR;
>> + goto out;
>> + }
>> +
>> + info = (struct snp_psc_desc *)svm->ghcb_sa;
>> + entry = &info->entries[info->hdr.cur_entry];
>
> Grabbing "entry" here is unnecessary and confusing.
Noted.
>
>> +
>> + if ((info->hdr.cur_entry >= VMGEXIT_PSC_MAX_ENTRY) ||
>> + (info->hdr.end_entry >= VMGEXIT_PSC_MAX_ENTRY) ||
>> + (info->hdr.cur_entry > info->hdr.end_entry)) {
>
> There's a TOCTOU bug here if the guest uses the GHCB instead of a scratch area.
> If the guest uses the scratch area, then KVM makes a full copy into kernel memory.
> But if the guest uses the GHCB, then KVM maps the GHCB into kernel address space
> but doesn't make a full copy, i.e. the guest can modify the data while it's being
> processed by KVM.
>
Sure, I can make a full copy of the page-state change buffer.
> IIRC, Peter and I discussed the sketchiness of the GHCB mapping offline a few
> times, but determined that there were no existing SEV-ES bugs because the guest
> could only submarine its own emulation request. But here, it could coerce KVM
> into running off the end of a buffer.
>
> I think you can get away with capturing cur_entry/end_entry locally, though
> copying the GHCB would be more robust. That would also make the code a bit
> prettier, e.g.
>
> cur = info->hdr.cur_entry;
> end = info->hdr.end_entry;
>
>> + rc = PSC_INVALID_ENTRY;
>> + goto out;
>> + }
>> +
>> + while (info->hdr.cur_entry <= info->hdr.end_entry) {
>
> Make this a for loop?
Sure, I can use the for loop. IIRC, in previous review feedbacks I got
the feeling that while() was preferred in the part1 so I used the
similar approach here.
>
> for ( ; cur_entry < end_entry; cur_entry++)
>
>> + entry = &info->entries[info->hdr.cur_entry];
>
> Does this need array_index_nospec() treatment?
>
I don't think so.
thanks
Powered by blists - more mailing lists