qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-block@nongnu.org, hreitz@redhat.com, aesteve@redhat.com,
	nsoffer@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH 1/4] qcow2: Fix theoretical corruption in store_bitmap() error path
Date: Fri, 13 Jan 2023 18:37:27 +0100	[thread overview]
Message-ID: <7d234180-3519-2dde-39f8-daf1f15bc4e2@linaro.org> (raw)
In-Reply-To: <Y8E2S0sQgEPkb0j3@redhat.com>

On 13/1/23 11:45, Kevin Wolf wrote:
> Am 13.01.2023 um 08:30 hat Philippe Mathieu-Daudé geschrieben:
>> On 12/1/23 20:14, Kevin Wolf wrote:
>>> In order to write the bitmap table to the image file, it is converted to
>>> big endian. If the write fails, it is passed to clear_bitmap_table() to
>>> free all of the clusters it had allocated before. However, if we don't
>>> convert it back to native endianness first, we'll free things at a wrong
>>> offset.
>>>
>>> In practical terms, the offsets will be so high that we won't actually
>>> free any allocated clusters, but just run into an error, but in theory
>>> this can cause image corruption.
>>>
>>> Cc: qemu-stable@nongnu.org
>>> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
>>> ---
>>>    block/qcow2-bitmap.c | 5 +++--
>>>    1 file changed, 3 insertions(+), 2 deletions(-)

>> Maybe add a comment here remembering to bswap back to native endianness?
>>
>>> -static inline void bitmap_table_to_be(uint64_t *bitmap_table, size_t size)
>>> +static inline void bitmap_table_bswap_be(uint64_t *bitmap_table, size_t size)
>>>    {
>>
>> This function uses cpu_to_be64(), semantically we convert back calling
>> be64_to_cpu(), but technically both functions end up being the same.
> 
> Yes, but we don't seem to have any public "neutral" functions, it's
> always either from or to.
> 
>> Alternatively:
>>
>>       for (i = 0; i < size; ++i) {
>> -        bitmap_table[i] = cpu_to_be64(bitmap_table[i]);
>> +        bswap64s(&bitmap_table[i]);
>>       }
> 
> Doesn't that swap even on big endian hosts, resulting incorrectly in a
> little endian table?

Oops yes you are right... sorry!

> The closest thing we have that I can see is the be_bswap() macro in
> bswap.h, but it's undefined again at the end of the header.

Indeed.

Regards,

Phil.


  reply	other threads:[~2023-01-13 17:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12 19:14 [PATCH 0/4] qemu-img: Fix exit code for errors closing the image Kevin Wolf
2023-01-12 19:14 ` [PATCH 1/4] qcow2: Fix theoretical corruption in store_bitmap() error path Kevin Wolf
2023-01-13  7:30   ` Philippe Mathieu-Daudé
2023-01-13 10:45     ` Kevin Wolf
2023-01-13 17:37       ` Philippe Mathieu-Daudé [this message]
2023-01-12 19:14 ` [PATCH 2/4] qemu-img commit: Report errors while closing the image Kevin Wolf
2023-01-12 19:14 ` [PATCH 3/4] qemu-img bitmap: " Kevin Wolf
2023-01-13  7:32   ` Philippe Mathieu-Daudé
2023-01-12 19:14 ` [PATCH 4/4] qemu-iotests: Test qemu-img bitmap/commit exit code on error Kevin Wolf
2023-01-13  7:30 ` [PATCH 0/4] qemu-img: Fix exit code for errors closing the image Markus Armbruster
2023-01-13 11:29   ` Kevin Wolf
2023-02-14 20:09     ` Vladimir Sementsov-Ogievskiy
2023-02-15 13:07     ` Markus Armbruster
2023-02-15 20:50       ` Vladimir Sementsov-Ogievskiy
2023-02-22 12:08       ` Reference-counting and finalizers that can fail are uneasy partners (was: [PATCH 0/4] qemu-img: Fix exit code for errors closing the image) Markus Armbruster
2023-02-22 12:54         ` Daniel P. Berrangé
2023-01-17 11:24 ` [PATCH 0/4] qemu-img: Fix exit code for errors closing the image Hanna Czenczek

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=7d234180-3519-2dde-39f8-daf1f15bc4e2@linaro.org \
    --to=philmd@linaro.org \
    --cc=aesteve@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=nsoffer@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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).