From: Alex Williamson <alex.williamson@redhat.com>
To: Bandan Das <bsd@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] vfio: add check for memory region overflow condition
Date: Mon, 21 Mar 2016 18:30:52 -0600 [thread overview]
Message-ID: <20160321183052.59e87b29@ul30vt.home> (raw)
In-Reply-To: <jpg1t731ilz.fsf@linux.bootlegged.copy>
On Mon, 21 Mar 2016 20:06:32 -0400
Bandan Das <bsd@redhat.com> wrote:
> Alex Williamson <alex.williamson@redhat.com> writes:
>
> > On Mon, 21 Mar 2016 18:00:50 -0400
> > Bandan Das <bsd@redhat.com> wrote:
> >
> >> vfio_listener_region_add for a iommu mr results in
> >> an overflow assert since emulated iommu memory region is initialized
> >> with UINT64_MAX. Add a check just like memory_region_size()
> >> does.
> >>
> >> Signed-off-by: Bandan Das <bsd@redhat.com>
> >> ---
> >> hw/vfio/common.c | 7 ++++++-
> >> 1 file changed, 6 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> >> index fb588d8..269244b 100644
> >> --- a/hw/vfio/common.c
> >> +++ b/hw/vfio/common.c
> >> @@ -349,7 +349,12 @@ static void vfio_listener_region_add(MemoryListener *listener,
> >> if (int128_ge(int128_make64(iova), llend)) {
> >> return;
> >> }
> >> - end = int128_get64(llend);
> >> +
> >> + if (int128_eq(llend, int128_2_64())) {
> >> + end = UINT64_MAX;
> >> + } else {
> >> + end = int128_get64(llend);
> >> + }
> >>
> >> if ((iova < container->min_iova) || ((end - 1) > container->max_iova)) {
> >> error_report("vfio: IOMMU container %p can't map guest IOVA region"
> >
> > But now all the calculations where we use end-1 are wrong. See the
> > discussion with Pierre Morel in the January qemu-devel archives.
> > There's a solution in there, but I never saw a follow-up from Pierre
> > with a revised patch. Thanks,
>
> I am missing something. When end < UIN64_MAX, end - 1 calculations are valid because
> the patch doesn't change that behavior. When end is UINT64_MAX, int128_get64() doesn't know how
> to calculate this value and we are just feeding it manually. The patch is just the opposite
> of what memory_region_init() did to init the mem region in the first place:
> mr->size = int128_make64(size);
> if (size == UINT64_MAX) {
> mr->size = int128_2_64();
> }
> So, end - 1 is still valid for end = UINT64_MAX, no ?
int128_2_64() is not equal to UINT64_MAX, so assigning UIN64_MAX to
@end is clearing altering the value. If we had a range from zero to
int128_2_64() then the size of that region is int128_2_64(). If we
alter @end to be UINT64_MAX, then the size is only UINT64_MAX and @end
- 1 is off by one versus the case where we use the value directly.
You're effectively changing @end to be the last address in the range,
but only in some cases, and not adjusting the remaining code to match.
Not only that, but the vfio map command is probably going to fail if we
pass in such an unaligned size since the mapping granularity is
likely the system page size. Thanks,
Alex
next prev parent reply other threads:[~2016-03-22 0:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-21 22:00 [Qemu-devel] [PATCH] vfio: add check for memory region overflow condition Bandan Das
2016-03-21 22:34 ` Alex Williamson
2016-03-22 0:06 ` Bandan Das
2016-03-22 0:30 ` Alex Williamson [this message]
2016-03-22 1:54 ` Bandan Das
2016-03-22 2:16 ` Alex Williamson
2016-03-22 18:55 ` Bandan Das
2016-03-22 19:31 ` Alex Williamson
2016-03-22 20:55 ` Bandan Das
2016-03-22 3:01 ` Peter Xu
2016-03-22 19:07 ` Bandan Das
2016-03-22 19:31 ` Alex Williamson
2016-03-23 2:42 ` Peter Xu
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=20160321183052.59e87b29@ul30vt.home \
--to=alex.williamson@redhat.com \
--cc=bsd@redhat.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).