Thread (5 messages) 5 messages, 2 authors, 2012-01-05

[PATCH] imsm: fix: correct calculation of UUID

STALE5387d

From: Lukasz Dorau <hidden>
Date: 2012-01-04 09:40:35
Subsystem: the rest · Maintainer: Linus Torvalds

The UUID is calculated from two numbers and two strings stored in arrays.
Whole arrays of chars are taken to calculation (not only the used part).
This is wrong, because the unused part of arrays can be changed accidentally.
For example it can sometimes happen when degraded raid is being rebuilt in OROM.
Such accidental change of UUID causes that system installed on raid
does not boot due to not recognized booting device (raid with changed UUID).

Signed-off-by: Lukasz Dorau <redacted>
---
 super-intel.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/super-intel.c b/super-intel.c
index 0e9269f..7f34542 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -1820,6 +1820,7 @@ static void uuid_from_super_imsm(struct supertype *st, int uuid[4])
 	struct sha1_ctx ctx;
 	struct imsm_dev *dev = NULL;
 	__u32 family_num;
+	size_t len;
 
 	/* some mdadm versions failed to set ->orig_family_num, in which
 	 * case fall back to ->family_num.  orig_family_num will be
@@ -1829,14 +1830,16 @@ static void uuid_from_super_imsm(struct supertype *st, int uuid[4])
 	if (family_num == 0)
 		family_num = super->anchor->family_num;
 	sha1_init_ctx(&ctx);
-	sha1_process_bytes(super->anchor->sig, MPB_SIG_LEN, &ctx);
+	len = strnlen((const char *)super->anchor->sig, MPB_SIG_LEN);
+	sha1_process_bytes(super->anchor->sig, len, &ctx);
 	sha1_process_bytes(&family_num, sizeof(__u32), &ctx);
 	if (super->current_vol >= 0)
 		dev = get_imsm_dev(super, super->current_vol);
 	if (dev) {
 		__u32 vol = super->current_vol;
 		sha1_process_bytes(&vol, sizeof(vol), &ctx);
-		sha1_process_bytes(dev->volume, MAX_RAID_SERIAL_LEN, &ctx);
+		len = strnlen((const char *)dev->volume, MAX_RAID_SERIAL_LEN);
+		sha1_process_bytes(dev->volume, len, &ctx);
 	}
 	sha1_finish_ctx(&ctx, buf);
 	memcpy(uuid, buf, 4*4);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help