Skip to contentSkip to conversation

dm space map: always set ev if sm_ll_mutate() succeeds

PATCH In review Benjamin Marzinski 2 participants 2 messages Dec 5, 2016 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 dm space map: always set ev if sm_ll_mutate() succeeds

If no block was allocated or freed, sm_ll_mutate() wasn't setting *ev, leaving the variable unitialized. sm_ll_insert(), sm_disk_inc_block(), and sm_disk_new_block() all check ev to see if there was an allocation event in sm_ll_mutate(), possibly reading unitialized data.

If no allocation event occured, sm_ll_mutate() should set *ev to SM_NONE.

---
 drivers/md/persistent-data/dm-space-map-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/persistent-data/dm-space-map-common.c +2 -1
index 10978ba..4c28608 100644
@@ -464,7 +464,8 @@ static int sm_ll_mutate(struct ll_disk *ll, dm_block_t b,
 		ll->nr_allocated--;
 		le32_add_cpu(&ie_disk.nr_free, 1);
 		ie_disk.none_free_before = cpu_to_le32(min(le32_to_cpu(ie_disk.none_free_before), bit));
-	}
+	} else
+		*ev = SM_NONE;
 
 	return ll->save_ie(ll, index, &ie_disk);
 }
Signature · 1 line
2.1.0
#1 lore raw

ack

Quoted 31 lines · Benjamin Marzinski

If no block was allocated or freed, sm_ll_mutate() wasn't setting *ev, leaving the variable unitialized. sm_ll_insert(), sm_disk_inc_block(), and sm_disk_new_block() all check ev to see if there was an allocation event in sm_ll_mutate(), possibly reading unitialized data.

If no allocation event occured, sm_ll_mutate() should set *ev to SM_NONE.

---
 drivers/md/persistent-data/dm-space-map-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/persistent-data/dm-space-map-common.c +2 -1
index 10978ba..4c28608 100644
@@ -464,7 +464,8 @@ static int sm_ll_mutate(struct ll_disk *ll, dm_block_t b,
 		ll->nr_allocated--;
 		le32_add_cpu(&ie_disk.nr_free, 1);
 		ie_disk.none_free_before = cpu_to_le32(min(le32_to_cpu(ie_disk.none_free_before), bit));
-	}
+	} else
+		*ev = SM_NONE;
 
 	return ll->save_ie(ll, index, &ie_disk);
 }
Signature · 1 line
2.1.0