block: fix permission update in bdrv_replace_node
PATCH 1/1 block: fix permission update in bdrv_replace_node
It's wrong to OR shared permissions. It may lead to crash on further permission updates.
Also, no needs to consider previously calculated permissions, as at this point we already bind all new parents and bdrv_get_cumulative_perm result is enough. So fix the bug by just set permissions by bdrv_get_cumulative_perm result.
Bug was introduced in long ago 234ac1a9025, in 2.9.
---
Hi all!
I found this bug during my work around backup-top filter. It happens that on filter removing, bdrv_replace_node() breaks permissions in graph which lead to bdrv_set_backing_hd(new backing: NULL) on assert(tighten_restrictions == false).
block.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
block.c +2 -3
@@ -4165,7 +4165,6 @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, {BdrvChild *c, *next;GSList *list =NULL , *p; -uint64_t old_perm, old_shared;uint64_t perm =0 , shared =BLK_PERM_ALL ;int ret;
@@ -4211,8 +4210,8 @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,bdrv_unref (from); } -bdrv_get_cumulative_perm (to, &old_perm, &old_shared); -bdrv_set_perm (to, old_perm | perm, old_shared | shared); +bdrv_get_cumulative_perm (to, &perm, &shared); +bdrv_set_perm (to, perm, shared); out:g_slist_free (list);
Signature · 1 line
2.18.0
Max Reitz
AppliedQuoted 14 lines · Vladimir Sementsov-Ogievskiy
It's wrong to OR shared permissions. It may lead to crash on further permission updates.
Also, no needs to consider previously calculated permissions, as at this point we already bind all new parents andbdrv_get_cumulative_permresult is enough. So fix the bug by just set permissions bybdrv_get_cumulative_permresult.Bug was introduced in long ago
234ac1a9025, in 2.9.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
Hi all!
Quoted 7 lines
I found this bug during my work around backup-top filter. It happens that on filter removing,
bdrv_replace_node()breaks permissions in graph which lead tobdrv_set_backing_hd(new backing: NULL)onassert(tighten_restrictions == false).block.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
Thanks, that makes sense.
Applied to my block branch:
https://git.xanclic.moe/XanClic/qemu/commits/branch/block
Max