Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NXRCW-0004Jx-QR for mharc-grub-devel@gnu.org; Tue, 19 Jan 2010 22:25:48 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXRCV-0004JH-1W for grub-devel@gnu.org; Tue, 19 Jan 2010 22:25:47 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXRCQ-0004GF-G4 for grub-devel@gnu.org; Tue, 19 Jan 2010 22:25:46 -0500 Received: from [199.232.76.173] (port=41090 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXRCQ-0004G8-3t for grub-devel@gnu.org; Tue, 19 Jan 2010 22:25:42 -0500 Received: from hurricane.eginity.com ([207.218.123.225]:56713 helo=zazu.eginity.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXRCP-0007LT-Ns for grub-devel@gnu.org; Tue, 19 Jan 2010 22:25:41 -0500 Received: from [192.168.1.51] (208.eginity.com [207.218.123.208]) (Authenticated sender: dmerillat@eginity.com) by zazu.eginity.com (Postfix) with ESMTPSA id 297374940 for ; Tue, 19 Jan 2010 22:25:41 -0500 (EST) Message-ID: <4B5677B4.1050000@dan.merillat.org> Date: Tue, 19 Jan 2010 22:25:40 -0500 From: Dan Merillat User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) MIME-Version: 1.0 To: The development of GNU GRUB References: <4B565B20.9050603@dan.merillat.org> <20100120014408.GO5847@riva.ucam.org> In-Reply-To: <20100120014408.GO5847@riva.ucam.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: Re: segfault in grub_device_iterate on 64bit platforms X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jan 2010 03:25:47 -0000 Colin Watson wrote: > On Tue, Jan 19, 2010 at 08:23:44PM -0500, Dan Merillat wrote: >> And here's a freebie to avoid a null pointer deref that -lefence pointed >> out: > (Nit: stick to the prevailing whitespace style.) :) Glad that's the worst problem with my submission. > grub_lvm_memberlist just constructs its return value from lv->vg->pvs, > so we'll need to look at how that's constructed. The only time pv->disk > is assigned a non-NULL value is in grub_lvm_scan_device: > > /* Match the device we are currently reading from with the right > PV. */ > if (vg->pvs) > for (pv = vg->pvs; pv; pv = pv->next) > { > if (! grub_memcmp (pv->id, pv_id, GRUB_LVM_ID_STRLEN)) > { > /* This could happen to LVM on RAID, pv->disk points to the > raid device, we shouldn't change it. */ > if (! pv->disk) > pv->disk = grub_disk_open (name); > break; > } > } > > So it's possible for pv->disk to be NULL if that PV doesn't have an LVM > signature (as I interpret this). That's either an error condition or an > indication that we aren't managing to understand LVM well enough. If > you can reproduce this it would be useful if you could clarify which. Ok, here goes - grub_lvm_scan_device is called once ("md0"), it finds the LVM signature, searches the vg list to see if we've seen this vg before, creates a new vg, pv list (disk = NULL) etc. Then it attaches the disk with this name to the appropriate pv entry in that code snippet you posted. So the only way for a PV->disk to be attached is if it is called by name in grub_lvm_scan_device(). I'm running the following setup: /dev/md0 pv0 contains lv_root /dev/sdb2 pv1 contains lv_test1, lv_test2, etc. invoke as: # grub-probe -t abstraction / Grub discovers / is on /dev/md0, probes md0 for LVM information, never looks at other disks, segfaults on a null pointer dereference because pv1 disk = NULL. So either you can ignore it via my patch, or add a loop to get disks by ID and add their information to the pvs. Does my analysis make sense?