Bug#567618: Analysis/fix for grub-probe failing to identify filesystem

Paul "TBBle" Hampson Paul.Hampson at Pobox.com
Thu Feb 4 01:04:49 UTC 2010


This is a bug in upstream grub2 code, as follows:

In short, it's failing to read the start of a partition that begins on
a sector that is not a multiple of 8,
and the fallback code is buggy.

In kern/disk.c's grub_disk_read function, an attempt is made to pull
the requested sector out of the
cache. For any partition type (eg. ext2) which wants a sector within
the first 8 of the partition, but
not the first, a disk->dev->read call is made below the comment "/*
Otherwise read data from the disk actually.  */"
for the relevant grub-cache-block-sized block (4096 bytes, 8 sectors).

This fails under Linux for partitions that do not start on multiples
of 8 for the first sectors of the
partition because grub (in util/hostdisk.c's open_device) want to read
from the partition device,
not the disk device, when reading a partition's data (for caching
reasons according to the comment)

The fallback code (if the if-test of the above-mentioned read call)
then attempts to read just the desired sector
or sectors, but when it then attempts to grub_memcpy the result into
the input buffer (directly before the
comment "/* Call the read hook, if any.  */" it copies from too far
into the resulting buffer.

The fix is to remove "+ pos" from this grub_memcpy, and the previous
setting of num (between
grub_errno = GRUB_ERR_NONE; and p = grub_realloc). (The num setting
causes it to read more sectors than
necessary, but is otherwise harmless.)

That's lines 444 and 461 of
http://bzr.debian.org/loggerhead/pkg-grub/trunk/grub/annotate/head:/kern/disk.c
revision 1967.

pos is the byte offset of the desired sector within the cache-block,
and at this point in the
code path we are no longer within a cache-block, so adding pos is incorrect.

http://bzr.debian.org/loggerhead/pkg-grub/trunk/grub/revision/1855.8.227
is the change that I think introduced
this bug, although presumably it was trying to fix another bug...

I can't see a bug in the upstream tracker for this.

This doesn't affect grub during boot, only when running under Linux
(as this fallback path should only be taken
in those circumstances)

-- 
Paul "TBBle" Hampson, Paul.Hampson at Pobox.com





More information about the Pkg-grub-devel mailing list