From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2992895AbXCICfh (ORCPT ); Thu, 8 Mar 2007 21:35:37 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S2992897AbXCICfh (ORCPT ); Thu, 8 Mar 2007 21:35:37 -0500 Received: from mail.tmr.com ([64.65.253.246]:33273 "EHLO gaimboi.tmr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2992895AbXCICff (ORCPT ); Thu, 8 Mar 2007 21:35:35 -0500 Message-ID: <45F0C87A.9000400@tmr.com> Date: Thu, 08 Mar 2007 21:37:46 -0500 From: Bill Davidsen Organization: TMR Associates Inc, Schenectady NY User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.8) Gecko/20061105 SeaMonkey/1.0.6 MIME-Version: 1.0 To: Andy Isaacson CC: linux-kernel@vger.kernel.org, Andrew Morton , Neil Brown , linux-raid@vger.kernel.org Subject: Re: [PATCH] fix read past end of array in md/linear.c References: <20070308205204.GA12152@hexapodia.org> In-Reply-To: <20070308205204.GA12152@hexapodia.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org 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 + for (j=i; j sz += conf->disks[j].size; > if (sz >= min_spacing && sz < conf->hash_spacing) > conf->hash_spacing = sz; After looking at that code, I have to wonder how this ever worked, or if in fact anyone ever took this path. I assume that the value of sz caused the loop exit in all cases, since this has been in the code at least since 2.6.15, oldest thing I have handy. -- bill davidsen CTO TMR Associates, Inc Doing interesting things with small computers since 1979