qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* qcow2 api not secured by mutex lock
@ 2019-12-18 10:28 Vladimir Sementsov-Ogievskiy
  2019-12-19 10:02 ` Kevin Wolf
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2019-12-18 10:28 UTC (permalink / raw)
  To: qemu block; +Cc: Kevin Wolf, Denis Lunev, qemu-devel, Max Reitz

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

Hi!

Some time ago, we've faced and fixed the fact that qcow2 bitmap api doesn't
call qcow2_co_mutex_lock, before accessing qcow2 metadata. This was solved by
moving qcow2_co_remove_persistent_dirty_bitmap and
qcow2_co_can_store_new_dirty_bitmap to coroutine and call qcow2_co_mutex_lock.

Now I decided to look at big picture (it is attached).

Boxes are qcow2 driver api, green border means that function calls qcow2_co_mutex_lock
(it doesn't guarantee, that exactly child node call is locked, but it is something).

In the picture there are just all functions, calling qcow2_cache_get/put.. Not all the
functions, that needs locking, but again, it is something.

So, accordingly to the picture, it seems that the following functions lacks locking:

qcow2_co_create

qcow2_snapshot_*
   (but it is both drained and aio context locked, so should be safe, yes?)

qcow2_reopen_bitmaps_rw
qcow2_store_persistent_dirty_bitmaps

qcow2_amend_options

qcow2_make_empty

===

Checking green nodes:

qcow2_co_invalidate_cache actually calls qcow2_close unlocked, it's another reason to fix qcow2_store_persistent_dirty_bitmaps

qcow2_write_snapshots actually called unlocked from qcow2_check_fix_snapshot_table.. It seems unsafe.

===


Not complete audit of course.. What do you think about it? I think, I at least should move
qcow2_store_persistent_dirty_bitmaps and qcow2_reopen_bitmaps_rw to coroutine,
like qcow2_co_remove_persistent_dirty_bitmap.


-- 
Best regards,
Vladimir

[-- Attachment #2: master-block-qcow2-filtered.svg --]
[-- Type: image/svg+xml, Size: 122306 bytes --]

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

end of thread, other threads:[~2019-12-19 10:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-18 10:28 qcow2 api not secured by mutex lock Vladimir Sementsov-Ogievskiy
2019-12-19 10:02 ` Kevin Wolf
2019-12-19 10:25   ` Vladimir Sementsov-Ogievskiy
2019-12-19 10:33   ` Max Reitz
2019-12-19 10:35   ` Max Reitz
2019-12-19 10:53     ` Kevin Wolf

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