Skip to contentSkip to conversation

mdadm: Fix Segmentation fault.

PATCH In review majianpeng 2 participants 2 messages May 25, 2012 – May 28, 2012 MD RAID

lore
Share & tools
lore

majianpeng

author
#0 lore raw

PATCH 1/1 mdadm: Fix Segmentation fault.

In function write_init_super1():
If "rv = store_super1(st, di->fd)" return error and the di is the last. Then the di = NULL && rv > 0, so exec:
if (rv)
fprintf(stderr, Name ": Failed to write metadata to%s\n",
di->devname);
will be segmentation fault.

---
 super1.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
super1.c +2 -0
index 4f20cc3..37b7a90 100644
@@ -1242,6 +1242,8 @@ static int write_init_super1(struct supertype *st)
 			rv = st->ss->write_bitmap(st, di->fd);
 		close(di->fd);
 		di->fd = -1;
+		if (rv)
+			goto error_out;
 	}
 error_out:
 	if (rv)
Signature · 6 lines
1.7.5.4

 				
--------------
majianpeng
2012-05-25
#1 lore raw
Quoted 18 lines · On Fri, 25 May 2012 19:49:40 +0800 "majianpeng" <[email protected]> wrote:

In function write_init_super1():
If "rv = store_super1(st, di->fd)" return error and the di is the last. Then the di = NULL && rv > 0, so exec:
if (rv)
fprintf(stderr, Name ": Failed to write metadata to%s\n",
di->devname);
will be segmentation fault.

---
 super1.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
super1.c +0 -0
index 4f20cc3..37b7a90 100644

super1.c static int write_init_super1(struct supertype *st) · line 1249

Quoted 8 lines
super1.c +2 -0
@@ -1242,6 +1242,8 @@ static int write_init_super1(struct supertype *st)
 			rv = st->ss->write_bitmap(st, di->fd);
 		close(di->fd);
 		di->fd = -1;
+		if (rv)
+			goto error_out;
 	}
 error_out:
 	if (rv)

Thanks.
This doesn't only go wrong when di is the last. If di is not the last it will not crash, but it will report an error for the wrong device.

So thanks for finding this - I've applied you patch and also remove the '&& ! rv' test from the 'for' loop as it is now pointless.

NeilBrown