From: Andy Isaacson <adi@hexapodia.org>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] fix read past end of array in md/linear.c
Date: Thu, 8 Mar 2007 12:53:41 -0800 [thread overview]
Message-ID: <20070308205341.GA13663@hexapodia.org> (raw)
In-Reply-To: <20070308205204.GA12152@hexapodia.org>
On Thu, Mar 08, 2007 at 12:52:04PM -0800, Andy Isaacson wrote:
> 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
>
> Index: linus/drivers/md/linear.c
> ===================================================================
> --- linus.orig/drivers/md/linear.c 2007-03-02 11:35:55.000000000 -0800
> +++ linus/drivers/md/linear.c 2007-03-07 13:10:30.000000000 -0800
> @@ -188,7 +188,7 @@
> for (i=0; i < cnt-1 ; i++) {
> sector_t sz = 0;
> int j;
> - for (j=i; i<cnt-1 && sz < min_spacing ; j++)
> + for (j=i; j<cnt-1 && sz < min_spacing ; j++)
> sz += conf->disks[j].size;
> if (sz >= min_spacing && sz < conf->hash_spacing)
> conf->hash_spacing = sz;
Forgot to add:
Signed-off-by: Andrew Isaacson <adi@hexapodia.org>
-andy
next prev parent reply other threads:[~2007-03-08 21:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-08 20:52 Andy Isaacson
2007-03-08 20:53 ` Andy Isaacson [this message]
2007-03-11 23:05 ` Neil Brown
2007-03-09 2:37 ` Bill Davidsen
2007-03-09 6:33 ` Andy Isaacson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070308205341.GA13663@hexapodia.org \
--to=adi@hexapodia.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®