Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH 3 of 9] MD:  allow analyze_sbs to fail
@ 2011-05-24  3:06 Jonathan Brassow
  0 siblings, 0 replies; only message in thread
From: Jonathan Brassow @ 2011-05-24  3:06 UTC (permalink / raw)
  To: linux-raid

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.

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>

Index: linux-2.6/drivers/md/md.c
===================================================================
--- linux-2.6.orig/drivers/md/md.c
+++ 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)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-24  3:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-24  3:06 [PATCH 3 of 9] MD: allow analyze_sbs to fail Jonathan Brassow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox