qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* qemu-img.c possibly overflowing shifts by BDRV_SECTOR_BITS
@ 2021-11-09 19:07 Peter Maydell
  2021-11-10 11:36 ` Kevin Wolf
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2021-11-09 19:07 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Kevin Wolf, Hanna Reitz, Qemu-block

Hi; Coverity is complaining about some of the places in qemu-img.c
where it takes a 32-bit variable and shifts it left by BDRV_SECTOR_BITS
to convert a sector count to a byte count, because it's doing the
shift in 32-bits rather than 64 and so Coverity thinks there might
be overflow (CID 1465221, 1465219). Is it right and we need extra
casts to force the shift to be done in 64 bits, or is there some
constraint that means we know the sector counts are always small
enough that the byte count is 2GB or less ?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: qemu-img.c possibly overflowing shifts by BDRV_SECTOR_BITS
  2021-11-09 19:07 qemu-img.c possibly overflowing shifts by BDRV_SECTOR_BITS Peter Maydell
@ 2021-11-10 11:36 ` Kevin Wolf
  2021-11-10 14:31   ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Wolf @ 2021-11-10 11:36 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Hanna Reitz, QEMU Developers, Qemu-block

Am 09.11.2021 um 20:07 hat Peter Maydell geschrieben:
> Hi; Coverity is complaining about some of the places in qemu-img.c
> where it takes a 32-bit variable and shifts it left by BDRV_SECTOR_BITS
> to convert a sector count to a byte count, because it's doing the
> shift in 32-bits rather than 64 and so Coverity thinks there might
> be overflow (CID 1465221, 1465219). Is it right and we need extra
> casts to force the shift to be done in 64 bits, or is there some
> constraint that means we know the sector counts are always small
> enough that the byte count is 2GB or less ?

These are false positives. n is limited to BDRV_REQUEST_MAX_SECTORS
already when it starts out in convert_iteration_sectors() (which is
enough to make the calculation safe), but for the specific code path, I
think it's even guaranteed to be further limited to s->buf_sectors which
is 16 MB at most (MAX_BUF_SECTORS in qemu-img.c).

Kevin



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: qemu-img.c possibly overflowing shifts by BDRV_SECTOR_BITS
  2021-11-10 11:36 ` Kevin Wolf
@ 2021-11-10 14:31   ` Peter Maydell
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2021-11-10 14:31 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: Hanna Reitz, QEMU Developers, Qemu-block

On Wed, 10 Nov 2021 at 11:36, Kevin Wolf <kwolf@redhat.com> wrote:
>
> Am 09.11.2021 um 20:07 hat Peter Maydell geschrieben:
> > Hi; Coverity is complaining about some of the places in qemu-img.c
> > where it takes a 32-bit variable and shifts it left by BDRV_SECTOR_BITS
> > to convert a sector count to a byte count, because it's doing the
> > shift in 32-bits rather than 64 and so Coverity thinks there might
> > be overflow (CID 1465221, 1465219). Is it right and we need extra
> > casts to force the shift to be done in 64 bits, or is there some
> > constraint that means we know the sector counts are always small
> > enough that the byte count is 2GB or less ?
>
> These are false positives. n is limited to BDRV_REQUEST_MAX_SECTORS
> already when it starts out in convert_iteration_sectors() (which is
> enough to make the calculation safe), but for the specific code path, I
> think it's even guaranteed to be further limited to s->buf_sectors which
> is 16 MB at most (MAX_BUF_SECTORS in qemu-img.c).

Thanks. I've marked them as false-positives in the coverity UI.

-- PMM


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-10 14:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 19:07 qemu-img.c possibly overflowing shifts by BDRV_SECTOR_BITS Peter Maydell
2021-11-10 11:36 ` Kevin Wolf
2021-11-10 14:31   ` Peter Maydell

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).