[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH] Fix reading of released memory



Bugfix patch attached

Zdenek
lvseg_segtype_dup currently duplicates memory from seg->lv->vg->vgmem
poll. This one gets released before reporting happens so command like:

pvs -o segtype

prints data from already released memory pool. Thanks to the fact there
is not much allocation happing after the VG is released, the memory
stays unmodified and correct result is printed.

Fix adds support for mempool passed parameter (like other similar
query commands) and uses dm_report memory pool.
---
 lib/metadata/lv.c       |    4 ++--
 lib/metadata/lv.h       |    2 +-
 lib/report/properties.c |    2 +-
 lib/report/report.c     |    8 ++++++--
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index 4e7d9dc..1c027e8 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -26,13 +26,13 @@ char *lvseg_tags_dup(const struct lv_segment *seg)
 	return tags_format_and_copy(seg->lv->vg->vgmem, &seg->tags);
 }
 
-char *lvseg_segtype_dup(const struct lv_segment *seg)
+char *lvseg_segtype_dup(struct dm_pool *mem, const struct lv_segment *seg)
 {
 	if (seg->area_count == 1) {
 		return (char *)"linear";
 	}
 
-	return dm_pool_strdup(seg->lv->vg->vgmem, seg->segtype->ops->name(seg));
+	return dm_pool_strdup(mem, seg->segtype->ops->name(seg));
 }
 
 uint64_t lvseg_chunksize(const struct lv_segment *seg)
diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h
index 50afa28..1c3640b 100644
--- a/lib/metadata/lv.h
+++ b/lib/metadata/lv.h
@@ -66,7 +66,7 @@ uint32_t lv_kernel_read_ahead(const struct logical_volume *lv);
 uint64_t lvseg_start(const struct lv_segment *seg);
 uint64_t lvseg_size(const struct lv_segment *seg);
 uint64_t lvseg_chunksize(const struct lv_segment *seg);
-char *lvseg_segtype_dup(const struct lv_segment *seg);
+char *lvseg_segtype_dup(struct dm_pool *mem, const struct lv_segment *seg);
 char *lvseg_tags_dup(const struct lv_segment *seg);
 
 #endif /* _LVM_LV_H */
diff --git a/lib/report/properties.c b/lib/report/properties.c
index a08470c..9cafbcc 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -225,7 +225,7 @@ GET_VG_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg)))
 SET_VG_NUM_PROPERTY_FN(vg_mda_copies, vg_set_mda_copies)
 
 /* LVSEG */
-GET_LVSEG_STR_PROPERTY_FN(segtype, lvseg_segtype_dup(lvseg))
+GET_LVSEG_STR_PROPERTY_FN(segtype, lvseg_segtype_dup(lvseg->lv->vg->vgmem, lvseg))
 #define _segtype_set _not_implemented_set
 GET_LVSEG_NUM_PROPERTY_FN(stripes, lvseg->area_count)
 #define _stripes_set _not_implemented_set
diff --git a/lib/report/report.c b/lib/report/report.c
index 0b1523f..88489a6 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -278,9 +278,13 @@ static int _segtype_disp(struct dm_report *rh __attribute__((unused)),
 			 const void *data, void *private __attribute__((unused)))
 {
 	const struct lv_segment *seg = (const struct lv_segment *) data;
-
 	char *name;
-	name = lvseg_segtype_dup(seg);
+
+	if (!(name = lvseg_segtype_dup(mem, seg))) {
+		log_error("Failed to get segtype.");
+		return 0;
+	}
+
 	dm_report_field_set_value(field, name, NULL);
 	return 1;
 }
-- 
1.7.4.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]