From: Anthony Liguori <anthony@codemonkey.ws>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: amit.shah@redhat.com, quintela@redhat.com, qemu-devel@nongnu.org,
kraxel@redhat.com
Subject: [Qemu-devel] Re: [PATCHv2 09/12] vhost: vhost net support
Date: Sun, 28 Feb 2010 10:02:29 -0600 [thread overview]
Message-ID: <4B8A9395.3070601@codemonkey.ws> (raw)
In-Reply-To: <20100227193824.GA26389@redhat.com>
On 02/27/2010 01:38 PM, Michael S. Tsirkin wrote:
> On Fri, Feb 26, 2010 at 09:18:03AM -0600, Anthony Liguori wrote:
>
>> On 02/26/2010 08:49 AM, Michael S. Tsirkin wrote:
>>
>>> KVM code needs all kind of work-arounds for KVM specific issues.
>>> It also assumes that KVM is registered at startup, so it
>>> does not try to optimize finding slots.
>>>
>>>
>> No, the slot mapping changes dynamically so KVM certainly needs to
>> optimize this.
>>
> Maybe, but it does not, KVM algorithms are n^2 or worse.
>
But n is small and the mappings don't change frequently.
More importantly, they change at the exact same times for vhost as they
do for kvm. So even if vhost has an O(n) algorithm, the KVM code gets
executed either immediately before or immediately after the vhost code
so your optimizations are lost in KVM's O(n^2) algorithm.
>>> Mine has no bugs, let's switch to it!
>>>
>>> Seriously, need to tread very carefully here.
>>> This is why I say: merge it, then look at how to reuse code.
>>>
>>>
>> Once it's merged, there's no incentive to look at reusing code.
>> Again, I don't think this is a huge burden to vhost. The two bits of code
>> literally do exactly the same thing. They just use different data
>> structures that ultimately contain the same values.
>>
> Not exactly. For example kvm track ROM and video ram addresses.
>
KVM treats ROM and RAM the same (it even maps ROM as RAM). There is no
special handling for video ram addresses.
There is some magic in the VGA code to switch the VGA LFB from mmio to
ram when possible but that happens at a higher layer.
>> '++i' is an odd thing to do in C in a for() loop. We're not explicit
>> about it in Coding Style but the vast majority of code just does
>> 'i++'.
>>
> Ugh. Do we really need to specify every little thing?
>
I don't care that much about coding style. I don't care if there are
curly brackets on single line ifs.
However, it's been made very clear to me that most other people do and
that it's something that's important to enforce.
> Hmm. I'll look into it.
> I actually think that for functions that just do a list of things
> unconditionally, without branches or loops, or with just error handling
> as here, it is perfectly fine for them to be of any length.
>
Like I said, just a suggestion.
>>>
>>>> You never unmap() the mapped memory and you're cheating by assuming that
>>>> the virtio rings have a constant mapping for the life time of a guest.
>>>> That's not technically true. My concern is that since a guest can
>>>> trigger remappings (by adjusting PCI mappings) badness can ensue.
>>>>
>>>>
>>> I do not know how this can happen. What do PCI mappings have to do with this?
>>> Please explain. If it can, vhost will need notification to update.
>>>
>>>
>> If a guest modifies the bar for an MMIO region such that it happens to
>> exist in RAM, while this is a bad thing for the guest to do, I don't
>> think we do anything to stop it. When the region gets remapped, the
>> result will be that the mapping will change.
>>
> So IMO this is the bug. If there's a BAR that matches RAM
> physical address, it should never get mapped. Any idea how
> to check this?
>
We could check it when the BAR is mapped in the PCI layer. I'm
suspicious there are other ways a guest can enforce/determine mappings
though.
Generally speaking, I think it's necessary to assume that a guest can
manipulate memory mappings. If we can prove that a guest cannot, it
would definitely simplify the code a lot. I'd love to make the same
assumptions in virtio userspace before it's actually a big source of
overhead.
I'm pretty sure though that we have to let a guest control mappings though.
>> Within qemu, because we carry the qemu_mutex, we know that the mappings
>> are fixed as long as we're in qemu. We're very careful to assume that
>> we don't rely on a mapping past when we drop the qemu_mutex.
>>
>> With vhost, you register a slot table and update it whenever mappings
>> change. I think that's good enough for dealing with ram addresses. But
>> you pass the virtual address for the rings and assume those mappings
>> never change.
>>
> So, the issue IMO is that an MMIO address gets passed instead of RAM.
> There's no reason to put virtio rings not in RAM, we just need to
> verify this.
>
Yes, but we don't always map PCI IO regions as MMIO or PIO. In
particular, for VGA devices (particularly VMware VGA), we map certain IO
regions as RAM because that's how the device is designed. Likewise, if
we do shared memory PCI devices using IO regions as the ram contents, we
would be mapping those as ram too.
So just checking to see if the virtio ring area is RAM or not is not
enough. A guest may do something that causes a virtio ring to still be
ram, but a different ram address. Now the vhost code is writing to RAM
that it thinks is physical address X but is really guest physical address Y.
This is not something that a guest can use to break into qemu, but it is
an emulation bug and depending on the guest OS, it may be possible to
use it to do a privilege escalation within the guest.
I think the only way to handle this is to explicitly check for changes
in the physical addresses the rings are mapped at and do the appropriate
ioctls to vhost to let it know if the ring's address has changed.
>> I'm pretty sure a guest can cause those to change and I'm not 100% sure,
>> but I think it's a potential source of exploits if you assume a mapping.
>> In the very least, a guest can trick vhost into writing to ram that it
>> wouldn't normally write to.
>>
> This seems harmless. guest can write anywhere in ram, anyway.
>
Not all guest code is created equal and if we're writing to the wrong
guest ram location, it can potentially circumvent the guest's security
architecture.
Regards,
Anthony Liguori
next prev parent reply other threads:[~2010-02-28 16:02 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-25 18:27 [Qemu-devel] [PATCHv2 00/12] vhost-net: upstream integration Michael S. Tsirkin
2010-02-25 18:27 ` [Qemu-devel] [PATCHv2 05/12] virtio: add APIs for queue fields Michael S. Tsirkin
2010-02-25 18:49 ` Blue Swirl
2010-02-26 14:53 ` Michael S. Tsirkin
2010-02-25 19:25 ` [Qemu-devel] " Anthony Liguori
2010-02-26 8:46 ` Gleb Natapov
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 09/12] vhost: vhost net support Michael S. Tsirkin
2010-02-25 19:04 ` [Qemu-devel] " Juan Quintela
2010-02-26 14:32 ` Michael S. Tsirkin
2010-02-26 14:38 ` Anthony Liguori
2010-02-26 14:54 ` Michael S. Tsirkin
2010-02-25 19:44 ` Anthony Liguori
2010-02-26 14:49 ` Michael S. Tsirkin
2010-02-26 15:18 ` Anthony Liguori
2010-02-27 19:38 ` Michael S. Tsirkin
2010-02-28 1:59 ` Paul Brook
2010-02-28 10:15 ` Michael S. Tsirkin
2010-02-28 12:45 ` Paul Brook
2010-02-28 14:44 ` Michael S. Tsirkin
2010-02-28 15:23 ` Paul Brook
2010-02-28 15:37 ` Michael S. Tsirkin
2010-02-28 16:02 ` Anthony Liguori [this message]
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 02/12] kvm: add API to set ioeventfd Michael S. Tsirkin
2010-02-25 19:19 ` [Qemu-devel] " Anthony Liguori
2010-03-02 17:41 ` Michael S. Tsirkin
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 04/12] virtio: add notifier support Michael S. Tsirkin
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 01/12] tap: add interface to get device fd Michael S. Tsirkin
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 07/12] virtio: move typedef to qemu-common Michael S. Tsirkin
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 10/12] tap: add vhost/vhostfd options Michael S. Tsirkin
2010-02-25 19:47 ` [Qemu-devel] " Anthony Liguori
2010-02-26 14:51 ` Michael S. Tsirkin
2010-02-26 15:23 ` Anthony Liguori
2010-02-27 19:44 ` Michael S. Tsirkin
2010-02-28 16:08 ` Anthony Liguori
2010-02-28 17:19 ` Michael S. Tsirkin
2010-02-28 20:57 ` Anthony Liguori
2010-02-28 21:01 ` Michael S. Tsirkin
2010-02-28 22:38 ` Anthony Liguori
2010-02-28 22:39 ` Paul Brook
2010-03-01 19:27 ` Michael S. Tsirkin
2010-03-01 21:54 ` Anthony Liguori
2010-03-02 9:57 ` Michael S. Tsirkin
2010-03-02 14:07 ` Anthony Liguori
2010-03-02 14:33 ` Paul Brook
2010-03-02 14:39 ` Anthony Liguori
2010-03-02 14:55 ` Paul Brook
2010-03-02 15:33 ` Anthony Liguori
2010-03-02 15:53 ` Paul Brook
2010-03-02 15:56 ` Michael S. Tsirkin
2010-03-02 16:12 ` Anthony Liguori
2010-03-02 16:21 ` Marcelo Tosatti
2010-03-02 16:12 ` Marcelo Tosatti
2010-03-02 16:56 ` Anthony Liguori
2010-03-02 17:00 ` Michael S. Tsirkin
2010-03-02 18:00 ` Marcelo Tosatti
2010-03-02 18:13 ` Anthony Liguori
2010-03-02 22:41 ` Paul Brook
2010-03-03 14:15 ` Anthony Liguori
2010-03-03 14:43 ` Paul Brook
2010-03-03 16:24 ` Marcelo Tosatti
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 11/12] tap: add API to retrieve vhost net header Michael S. Tsirkin
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 06/12] virtio: add set_status callback Michael S. Tsirkin
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 08/12] virtio-pci: fill in notifier support Michael S. Tsirkin
2010-02-25 19:30 ` [Qemu-devel] " Anthony Liguori
2010-02-28 20:02 ` Michael S. Tsirkin
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 03/12] notifier: event notifier implementation Michael S. Tsirkin
2010-02-25 19:22 ` [Qemu-devel] " Anthony Liguori
2010-02-28 19:59 ` Michael S. Tsirkin
2010-02-25 18:28 ` [Qemu-devel] [PATCHv2 12/12] virtio-net: vhost net support Michael S. Tsirkin
2010-02-25 19:49 ` [Qemu-devel] Re: [PATCHv2 00/12] vhost-net: upstream integration Anthony Liguori
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=4B8A9395.3070601@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=amit.shah@redhat.com \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@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).