qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block/iscsi: avoid data corruption with cache=writeback
@ 2017-01-16 15:17 Peter Lieven
  2017-01-17 11:28 ` [Qemu-devel] [Qemu-stable] " Fam Zheng
  2017-01-20 16:45 ` [Qemu-devel] " Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Lieven @ 2017-01-16 15:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, qemu-block, Peter Lieven, qemu-stable

nb_cls_shrunk in iscsi_allocmap_update can become -1 if the
request starts and ends within the same cluster. This results
in passing -1 to bitmap_set and bitmap_clear and they don't
handle negative values properly. In the end this leads to data
corruption.

Fixes: e1123a3b40a1a9a625a29c8ed4debb7e206ea690
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/iscsi.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 6aeeb9e..1860f1b 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -499,14 +499,18 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num,
     if (allocated) {
         bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded);
     } else {
-        bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk);
+        if (nb_cls_shrunk > 0) {
+            bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk);
+        }
     }
 
     if (iscsilun->allocmap_valid == NULL) {
         return;
     }
     if (valid) {
-        bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk);
+        if (nb_cls_shrunk > 0) {
+            bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk);
+        }
     } else {
         bitmap_clear(iscsilun->allocmap_valid, cl_num_expanded,
                      nb_cls_expanded);
-- 
1.9.1

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

* Re: [Qemu-devel] [Qemu-stable] [PATCH] block/iscsi: avoid data corruption with cache=writeback
  2017-01-16 15:17 [Qemu-devel] [PATCH] block/iscsi: avoid data corruption with cache=writeback Peter Lieven
@ 2017-01-17 11:28 ` Fam Zheng
  2017-01-17 11:31   ` Peter Lieven
  2017-01-20 16:45 ` [Qemu-devel] " Paolo Bonzini
  1 sibling, 1 reply; 4+ messages in thread
From: Fam Zheng @ 2017-01-17 11:28 UTC (permalink / raw)
  To: Peter Lieven; +Cc: qemu-devel, pbonzini, qemu-stable, qemu-block

On Mon, 01/16 16:17, Peter Lieven wrote:
> nb_cls_shrunk in iscsi_allocmap_update can become -1 if the
> request starts and ends within the same cluster. This results
> in passing -1 to bitmap_set and bitmap_clear and they don't
> handle negative values properly. In the end this leads to data
> corruption.
> 
> Fixes: e1123a3b40a1a9a625a29c8ed4debb7e206ea690
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  block/iscsi.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/block/iscsi.c b/block/iscsi.c
> index 6aeeb9e..1860f1b 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -499,14 +499,18 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num,
>      if (allocated) {
>          bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded);
>      } else {
> -        bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk);
> +        if (nb_cls_shrunk > 0) {
> +            bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk);
> +        }
>      }
>  
>      if (iscsilun->allocmap_valid == NULL) {
>          return;
>      }
>      if (valid) {
> -        bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk);
> +        if (nb_cls_shrunk > 0) {
> +            bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk);
> +        }
>      } else {
>          bitmap_clear(iscsilun->allocmap_valid, cl_num_expanded,
>                       nb_cls_expanded);
> -- 
> 1.9.1
> 
> 

It's probably a good idea to add assertions parameter in bitmap_*.

Reviewed-by: Fam Zheng <famz@redhat.com>

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

* Re: [Qemu-devel] [Qemu-stable] [PATCH] block/iscsi: avoid data corruption with cache=writeback
  2017-01-17 11:28 ` [Qemu-devel] [Qemu-stable] " Fam Zheng
@ 2017-01-17 11:31   ` Peter Lieven
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Lieven @ 2017-01-17 11:31 UTC (permalink / raw)
  To: Fam Zheng; +Cc: qemu-devel, pbonzini, qemu-stable, qemu-block

Am 17.01.2017 um 12:28 schrieb Fam Zheng:
> On Mon, 01/16 16:17, Peter Lieven wrote:
>> nb_cls_shrunk in iscsi_allocmap_update can become -1 if the
>> request starts and ends within the same cluster. This results
>> in passing -1 to bitmap_set and bitmap_clear and they don't
>> handle negative values properly. In the end this leads to data
>> corruption.
>>
>> Fixes: e1123a3b40a1a9a625a29c8ed4debb7e206ea690
>> Cc: qemu-stable@nongnu.org
>> Signed-off-by: Peter Lieven <pl@kamp.de>
>> ---
>>   block/iscsi.c | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/block/iscsi.c b/block/iscsi.c
>> index 6aeeb9e..1860f1b 100644
>> --- a/block/iscsi.c
>> +++ b/block/iscsi.c
>> @@ -499,14 +499,18 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num,
>>       if (allocated) {
>>           bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded);
>>       } else {
>> -        bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk);
>> +        if (nb_cls_shrunk > 0) {
>> +            bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk);
>> +        }
>>       }
>>   
>>       if (iscsilun->allocmap_valid == NULL) {
>>           return;
>>       }
>>       if (valid) {
>> -        bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk);
>> +        if (nb_cls_shrunk > 0) {
>> +            bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk);
>> +        }
>>       } else {
>>           bitmap_clear(iscsilun->allocmap_valid, cl_num_expanded,
>>                        nb_cls_expanded);
>> -- 
>> 1.9.1
>>
>>
> It's probably a good idea to add assertions parameter in bitmap_*.

yes, i will send a follow-up patch.

Peter

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

* Re: [Qemu-devel] [PATCH] block/iscsi: avoid data corruption with cache=writeback
  2017-01-16 15:17 [Qemu-devel] [PATCH] block/iscsi: avoid data corruption with cache=writeback Peter Lieven
  2017-01-17 11:28 ` [Qemu-devel] [Qemu-stable] " Fam Zheng
@ 2017-01-20 16:45 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2017-01-20 16:45 UTC (permalink / raw)
  To: Peter Lieven, qemu-devel; +Cc: qemu-stable, qemu-block



On 16/01/2017 16:17, Peter Lieven wrote:
> nb_cls_shrunk in iscsi_allocmap_update can become -1 if the
> request starts and ends within the same cluster. This results
> in passing -1 to bitmap_set and bitmap_clear and they don't
> handle negative values properly. In the end this leads to data
> corruption.
> 
> Fixes: e1123a3b40a1a9a625a29c8ed4debb7e206ea690
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  block/iscsi.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

Queued, thanks.

Paolo

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

end of thread, other threads:[~2017-01-20 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-16 15:17 [Qemu-devel] [PATCH] block/iscsi: avoid data corruption with cache=writeback Peter Lieven
2017-01-17 11:28 ` [Qemu-devel] [Qemu-stable] " Fam Zheng
2017-01-17 11:31   ` Peter Lieven
2017-01-20 16:45 ` [Qemu-devel] " Paolo Bonzini

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