From: Tobin Feldman-Fitzthum <tobin@linux.ibm.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: thomas.lendacky@amd.com, brijesh.singh@amd.com,
Eduardo Habkost <ehabkost@redhat.com>,
jejb@linux.ibm.com, tobin@ibm.com, dgilbert@redhat.com,
qemu-devel@nongnu.org, berrange@redhat.com
Subject: Re: [PATCH v5] sev: add sev-inject-launch-secret
Date: Tue, 20 Oct 2020 17:33:05 -0400 [thread overview]
Message-ID: <dd1b07f9d596432ee5d4ebd740a98c5d@linux.vnet.ibm.com> (raw)
In-Reply-To: <e4bc6348-cda5-e7f5-3753-61f4d3ba0116@redhat.com>
On 2020-10-20 11:56, Paolo Bonzini wrote:
> On 20/10/20 15:54, Eduardo Habkost wrote:
>> On Tue, Oct 20, 2020 at 11:03:51AM +0200, Paolo Bonzini wrote:
>>> On 15/10/20 16:37, tobin@linux.ibm.com wrote:
>>>> -static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error
>>>> **errp)
>>>> +void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, uint64_t size,
>>>> Error **errp)
>>>> {
>>>> MemoryRegionSection mrs =
>>>> memory_region_find(get_system_memory(),
>>>> - addr, 1);
>>>> + addr, size);
>>>
>>> You need to check size against mrs.size and fail if mrs.size is
>>> smaller.
>>> Otherwise, the ioctl can access memory out of range.
>>
>> Good catch! I'm dequeuing it.
>>
>> Is there a reason memory_region_find() doesn't ensure that by
>> default?
>
> IIRC memory_region_find() was used to do DMA in the very first versions
> of "virtio-blk dataplane" so you would call it multiple times in a
> loop.
> So it's like that because it maps the way address_space_map() works.
>
>> The call at virtio_balloon_handle_output() looks suspicious,
>> though, because it looks for a BALLOON_PAGE_SIZE range, but
>> there's no check for the returned section size.
>
> I think it's not a bug because ultimately it's checked in
> ram_block_discard_range, but it's not pretty.
>
> Paolo
Ok, it seems like the best solution is, as Paolo suggested, to add a
simple check at the end of gpa2hva that makes sure mr.size is equal
to size. gpa2hva is used one other place where the size is hard-coded
as 1, so adding the check isn't going to break anything.
Would you like me to resubmit with this tweak?
-Tobin
prev parent reply other threads:[~2020-10-20 21:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-15 14:37 [PATCH v5] sev: add sev-inject-launch-secret tobin
2020-10-15 14:44 ` Brijesh Singh
2020-10-19 14:56 ` Eduardo Habkost
2020-10-19 16:46 ` Eduardo Habkost
2020-10-19 16:47 ` Eduardo Habkost
2020-10-19 21:21 ` Tobin Feldman-Fitzthum
2020-10-20 9:03 ` Paolo Bonzini
2020-10-20 13:54 ` Eduardo Habkost
2020-10-20 15:56 ` Paolo Bonzini
2020-10-20 21:33 ` Tobin Feldman-Fitzthum [this message]
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=dd1b07f9d596432ee5d4ebd740a98c5d@linux.vnet.ibm.com \
--to=tobin@linux.ibm.com \
--cc=berrange@redhat.com \
--cc=brijesh.singh@amd.com \
--cc=dgilbert@redhat.com \
--cc=ehabkost@redhat.com \
--cc=jejb@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thomas.lendacky@amd.com \
--cc=tobin@ibm.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).