From: Andy Isaacson Date: Mon, 26 Mar 2007 21:42:40 +0000 (+0200) Subject: fix read past end of array in md/linear.c X-Git-Tag: v2.6.16.46-rc1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36c8a3d3ac8b0157ea4ebc54926d40309787a865;p=thirdparty%2Fkernel%2Fstable.git fix read past end of array in md/linear.c When iterating through an array, one must be careful to test one's index variable rather than another similarly-named variable. The loop will read off the end of conf->disks[] in the following (pathological) case: % dd bs=1 seek=840716287 if=/dev/zero of=d1 count=1 % for i in 2 3 4; do dd if=/dev/zero of=d$i bs=1k count=$(($i+150)); done % ./vmlinux ubd0=root ubd1=d1 ubd2=d2 ubd3=d3 ubd4=d4 # mdadm -C /dev/md0 --level=linear --raid-devices=4 /dev/ubd[1234] adding some printks, I saw this: [42949374.960000] hash_spacing = 821120 [42949374.960000] cnt = 4 [42949374.960000] min_spacing = 801 [42949374.960000] j=0 size=820928 sz=820928 [42949374.960000] i=0 sz=820928 hash_spacing=820928 [42949374.960000] j=1 size=64 sz=64 [42949374.960000] j=2 size=64 sz=128 [42949374.960000] j=3 size=64 sz=192 [42949374.960000] j=4 size=1515870810 sz=1515871002 Signed-off-by: Adrian Bunk --- diff --git a/drivers/md/linear.c b/drivers/md/linear.c index 777585458c852..0fa9e685578ca 100644 --- a/drivers/md/linear.c +++ b/drivers/md/linear.c @@ -174,7 +174,7 @@ static int linear_run (mddev_t *mddev) for (i=0; i < cnt-1 ; i++) { sector_t sz = 0; int j; - for (j=i; idisks[j].size; if (sz >= min_spacing && sz < conf->hash_spacing) conf->hash_spacing = sz;