Skip to contentSkip to conversation

MD: allow analyze_sbs to fail

PATCH New Jonathan Brassow 1 participant 1 message May 24, 2011 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MD: allow analyze_sbs to fail

Patch name: md-allow-analyze_sbs-to-fail.patch

Catch the case that md_run is called requiring non-existant super_types fns.

Other modules may call md_run (like device-mapper's, dm-raid.c), we mustn't assume they will always set a valid MD major_version. This is especially true in the case of device-mapper, which will use a new superblock type. If patches don't land in the kernel in the proper order, access will be attempted beyond the end of the super_types array.

drivers/md/md.c +7 -2
Index: linux-2.6/drivers/md/md.c
===================================================================
@@ -2864,12 +2864,15 @@ abort_free:
  */
 
 
-static void analyze_sbs(mddev_t * mddev)
+static int analyze_sbs(mddev_t *mddev)
 {
 	int i;
 	mdk_rdev_t *rdev, *freshest, *tmp;
 	char b[BDEVNAME_SIZE];
 
+	if (mddev->major_version >= ARRAY_SIZE(super_types))
+		return -EINVAL;
+
 	freshest = NULL;
 	rdev_for_each(rdev, tmp, mddev)
 		switch (super_types[mddev->major_version].
@@ -2921,6 +2924,7 @@ static void analyze_sbs(mddev_t * mddev)
 			clear_bit(In_sync, &rdev->flags);
 		}
 	}
+	return 0;
 }
 
 /* Read a fixed-point number.
@@ -4459,7 +4463,8 @@ int md_run(mddev_t *mddev)
 	if (should_read_super(mddev)) {
 		if (!mddev->persistent)
 			return -EINVAL;
-		analyze_sbs(mddev);
+		if (analyze_sbs(mddev))
+			return -EINVAL;
 	}
 
 	if (mddev->level != LEVEL_NONE)