Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NXPcM-0003oI-2K for mharc-grub-devel@gnu.org; Tue, 19 Jan 2010 20:44:22 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXPcK-0003nu-Sj for grub-devel@gnu.org; Tue, 19 Jan 2010 20:44:20 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXPcF-0003jv-FP for grub-devel@gnu.org; Tue, 19 Jan 2010 20:44:19 -0500 Received: from [199.232.76.173] (port=60455 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXPcF-0003jl-4Y for grub-devel@gnu.org; Tue, 19 Jan 2010 20:44:15 -0500 Received: from smarthost02.mail.zen.net.uk ([212.23.3.141]:34428) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXPcE-0006vm-LF for grub-devel@gnu.org; Tue, 19 Jan 2010 20:44:14 -0500 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost02.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1NXPcC-0007rt-U8 for grub-devel@gnu.org; Wed, 20 Jan 2010 01:44:13 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) for grub-devel@gnu.org id 1NXPc8-0004Pi-00; Wed, 20 Jan 2010 01:44:08 +0000 Date: Wed, 20 Jan 2010 01:44:08 +0000 From: Colin Watson To: The development of GNU GRUB Message-ID: <20100120014408.GO5847@riva.ucam.org> References: <4B565B20.9050603@dan.merillat.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4B565B20.9050603@dan.merillat.org> User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost02-IP: [82.69.40.219] 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 01:44:21 -0000 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: > > diff --git a/util/grub-probe.c b/util/grub-probe.c > index 4ba8a98..acb0887 100644 > --- a/util/grub-probe.c > +++ b/util/grub-probe.c > @@ -94,6 +94,8 @@ probe_partmap (grub_disk_t disk) > static int > probe_raid_level (grub_disk_t disk) > { > + if (!disk) > + return -1; > if (disk->dev->id != GRUB_DISK_DEVICE_RAID_ID) > return -1; (Nit: stick to the prevailing whitespace style.) > Someone may want to look into why probe_raid_level can get passed an > invalid disk pointer, but the combo of these two patches makes it work > properly. I don't know if it's possible to have a disk pointer without > a dev pointer, but that's a question for people with some deeper knowledge. probe_raid_level is called in two places: one on dev->disk from grub_device_open, and one on each member list->disk from dev->disk->dev->memberlist (dev->disk). grub_device_open guarantees either !dev or dev->disk, so we must be looking at the latter, and the membership function pointer here is always grub_lvm_memberlist. 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. In the meantime, my gut feel is that grub_lvm_memberlist is reporting the member list accurately, and since grub-probe is the thing that cares whether the disk member is non-NULL, it should also test that. It doesn't much matter whether we do this in probe or in probe_raid_level. Which is all a laborious way of saying that I think your patch is OK, although I'm going to add a comment to explain why. Thanks - I'll apply this and your other patch in just a moment. -- Colin Watson [cjwatson@ubuntu.com]