[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 34/35] bitmap: assert that start and nr are non negat
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 34/35] bitmap: assert that start and nr are non negative |
Date: |
Fri, 20 Jan 2017 14:31:38 +0100 |
From: Peter Lieven <address@hidden>
commit e1123a3b introduced a data corruption regression
in the iscsi driver because it passed -1 as nr to bitmap_set
and bitmap_clear. Add an assertion to catch such flaws earlier.
Suggested-by: Fam Zheng <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Signed-off-by: Peter Lieven <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
util/bitmap.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/util/bitmap.c b/util/bitmap.c
index 43ed011..c1a84ca 100644
--- a/util/bitmap.c
+++ b/util/bitmap.c
@@ -164,6 +164,8 @@ void bitmap_set(unsigned long *map, long start, long nr)
int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
+ assert(start >= 0 && nr >= 0);
+
while (nr - bits_to_set >= 0) {
*p |= mask_to_set;
nr -= bits_to_set;
@@ -184,6 +186,8 @@ void bitmap_set_atomic(unsigned long *map, long start, long
nr)
int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
+ assert(start >= 0 && nr >= 0);
+
/* First word */
if (nr - bits_to_set > 0) {
atomic_or(p, mask_to_set);
@@ -221,6 +225,8 @@ void bitmap_clear(unsigned long *map, long start, long nr)
int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
+ assert(start >= 0 && nr >= 0);
+
while (nr - bits_to_clear >= 0) {
*p &= ~mask_to_clear;
nr -= bits_to_clear;
@@ -243,6 +249,8 @@ bool bitmap_test_and_clear_atomic(unsigned long *map, long
start, long nr)
unsigned long dirty = 0;
unsigned long old_bits;
+ assert(start >= 0 && nr >= 0);
+
/* First word */
if (nr - bits_to_clear > 0) {
old_bits = atomic_fetch_and(p, ~mask_to_clear);
--
2.9.3
- [Qemu-devel] [PULL 24/35] x86: ioapic: fix fail migration when irqchip=split, (continued)
- [Qemu-devel] [PULL 24/35] x86: ioapic: fix fail migration when irqchip=split, Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 23/35] x86: ioapic: dump version for "info ioapic", Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 26/35] char: fix ctrl-a b not working, Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 27/35] ramblock-notifier: new, Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 28/35] KVM: PPC: eliminate unnecessary duplicate constants, Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 29/35] kvm: move cpu synchronization code, Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 32/35] hax: add Darwin support, Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 31/35] Plumb the HAXM-based hardware acceleration support, Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 33/35] Revert "win32: don't run subprocess tests on Mingw32 platform", Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 35/35] pc.h: move x-mach-use-reliable-get-clock compat entry to PC_COMPAT_2_8, Paolo Bonzini, 2017/01/20
- [Qemu-devel] [PULL 34/35] bitmap: assert that start and nr are non negative,
Paolo Bonzini <=
- [Qemu-devel] [PULL 30/35] target/i386: Add Intel HAX files, Paolo Bonzini, 2017/01/20
- Re: [Qemu-devel] [PULL v3 00/32] Misc patches for 2017-01-11, no-reply, 2017/01/20
- Re: [Qemu-devel] [PULL v3 00/32] Misc patches for 2017-01-11, Paolo Bonzini, 2017/01/20
- Re: [Qemu-devel] [PULL v3 00/32] Misc patches for 2017-01-11, Peter Maydell, 2017/01/23