All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Olaf Hering <olaf@aepfle.de>
Cc: qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	"open list:All patches CC here" <qemu-devel@nongnu.org>,
	Max Reitz <mreitz@redhat.com>,
	"open list:X86" <xen-devel@lists.xensource.com>,
	Anthony Perard <anthony.perard@citrix.com>
Subject: Re: [Qemu-devel] [PATCH] xen_disk: convert discard input to byte ranges
Date: Tue, 22 Nov 2016 10:32:27 -0600	[thread overview]
Message-ID: <1340ce97-092f-877a-d244-f0bf1b50e6e6@redhat.com> (raw)
In-Reply-To: <20161122161235.GA24220@aepfle.de>

[-- Attachment #1: Type: text/plain, Size: 1401 bytes --]

On 11/22/2016 10:12 AM, Olaf Hering wrote:
> On Fri, Nov 18, Eric Blake wrote:
> 
>> if (sec_start > (INT64_MAX >> BDRV_SECTOR_BITS) - sec_count)
> 
> I have looked at this for a while now and cant spot how this would cover
> all cases. Are you saying there should be just a single overflow check,
> yours? My change has two: one to check for wrap around and to check
> against the upper limit. My check happens to work with 0/UINT64_MAX or
> INT64_MAX/INT64_MAX as input, yours appearently not.
> Obviously I'm missing something essential.

I never suggested eliminating the wraparound check, only simplifying the
overflow check.  You could combine the wraparound and overflow into one:

if (sec_start + sec_count < sec_count ||
    sec_start > (INT64_MAX >> BDRV_SECTOR_BITS) - sec_count) {
    return false;
}

Remember, sec_start and sec_count were both typed as unsigned 64-bit
values, so everything in the above computation is well-defined
arithmetic, and you catch all cases of trying to add two numbers into
something that doesn't fit in 64 bits, as well as all cases of the
addition fitting in 64 bits but going beyond the maximum possible sector
number (since it is not possible to have a sector number whose
corresponding offset would exceed 63 bits).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Eric Blake <eblake@redhat.com>
To: Olaf Hering <olaf@aepfle.de>
Cc: Kevin Wolf <kwolf@redhat.com>,
	"open list:X86" <xen-devel@lists.xensource.com>,
	qemu-block@nongnu.org,
	"open list:All patches CC here" <qemu-devel@nongnu.org>,
	Max Reitz <mreitz@redhat.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Anthony Perard <anthony.perard@citrix.com>
Subject: Re: [Qemu-devel] [PATCH] xen_disk: convert discard input to byte ranges
Date: Tue, 22 Nov 2016 10:32:27 -0600	[thread overview]
Message-ID: <1340ce97-092f-877a-d244-f0bf1b50e6e6@redhat.com> (raw)
In-Reply-To: <20161122161235.GA24220@aepfle.de>


[-- Attachment #1.1.1: Type: text/plain, Size: 1401 bytes --]

On 11/22/2016 10:12 AM, Olaf Hering wrote:
> On Fri, Nov 18, Eric Blake wrote:
> 
>> if (sec_start > (INT64_MAX >> BDRV_SECTOR_BITS) - sec_count)
> 
> I have looked at this for a while now and cant spot how this would cover
> all cases. Are you saying there should be just a single overflow check,
> yours? My change has two: one to check for wrap around and to check
> against the upper limit. My check happens to work with 0/UINT64_MAX or
> INT64_MAX/INT64_MAX as input, yours appearently not.
> Obviously I'm missing something essential.

I never suggested eliminating the wraparound check, only simplifying the
overflow check.  You could combine the wraparound and overflow into one:

if (sec_start + sec_count < sec_count ||
    sec_start > (INT64_MAX >> BDRV_SECTOR_BITS) - sec_count) {
    return false;
}

Remember, sec_start and sec_count were both typed as unsigned 64-bit
values, so everything in the above computation is well-defined
arithmetic, and you catch all cases of trying to add two numbers into
something that doesn't fit in 64 bits, as well as all cases of the
addition fitting in 64 bits but going beyond the maximum possible sector
number (since it is not possible to have a sector number whose
corresponding offset would exceed 63 bits).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2016-11-22 16:32 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18 10:24 [Qemu-devel] [PATCH] xen_disk: convert discard input to byte ranges Olaf Hering
2016-11-18 10:24 ` Olaf Hering
2016-11-18 10:30 ` [Qemu-devel] " Olaf Hering
2016-11-18 10:30   ` Olaf Hering
2016-11-23 10:49   ` [Qemu-devel] " Olaf Hering
2016-11-23 10:49     ` Olaf Hering
2016-11-23 11:02     ` [Qemu-devel] " Olaf Hering
2016-11-23 11:02       ` Olaf Hering
2016-11-23 18:51       ` [Qemu-devel] " Stefano Stabellini
2016-11-23 18:51         ` Stefano Stabellini
2016-11-18 13:43 ` [Qemu-devel] " Eric Blake
2016-11-18 13:43   ` Eric Blake
2016-11-18 14:19   ` Olaf Hering
2016-11-18 14:19     ` Olaf Hering
2016-11-18 14:35     ` Eric Blake
2016-11-18 14:35       ` Eric Blake
2016-11-18 15:38       ` Kevin Wolf
2016-11-18 15:38         ` Kevin Wolf
2016-11-18 16:39 ` Eric Blake
2016-11-18 16:39   ` Eric Blake
2016-11-18 17:41   ` Olaf Hering
2016-11-18 17:41     ` Olaf Hering
2016-11-18 18:50     ` Eric Blake
2016-11-18 18:50       ` Eric Blake
2016-11-22 16:12       ` Olaf Hering
2016-11-22 16:12         ` Olaf Hering
2016-11-22 16:32         ` Eric Blake [this message]
2016-11-22 16:32           ` Eric Blake
2016-11-22 17:00           ` Olaf Hering
2016-11-22 17:00             ` Olaf Hering
2016-11-22 17:11             ` Eric Blake
2016-11-22 17:11               ` Eric Blake

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=1340ce97-092f-877a-d244-f0bf1b50e6e6@redhat.com \
    --to=eblake@redhat.com \
    --cc=anthony.perard@citrix.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=olaf@aepfle.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.