From: Vladimir 'phcoder' Serbinenko Date: Tue, 1 May 2012 13:02:34 +0000 (+0200) Subject: * grub-core/kern/emu/hostdisk.c (read_device_map): Reject non-standard X-Git-Tag: 2.00~290 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3282399ada70d109ea2c67b5441886cf9cc213f;p=thirdparty%2Fgrub.git * grub-core/kern/emu/hostdisk.c (read_device_map): Reject non-standard disk names. * docs/grub.texi: Update device.map parts. --- diff --git a/ChangeLog b/ChangeLog index 5aa4b9ac7..0de79413d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-05-01 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (read_device_map): Reject non-standard + disk names. + * docs/grub.texi: Update device.map parts. + 2012-05-01 Vladimir Serbinenko Don't scan into non-diskfilter devices having diskfilter names. diff --git a/docs/grub.texi b/docs/grub.texi index 530984cb1..55ae7e816 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -679,17 +679,12 @@ storage devices. @node Device map @section The map between BIOS drives and OS devices -The @command{grub-mkdevicemap} program can be used to create the @dfn{device -map file}. It is often run automatically by tools such as -@command{grub-install} if the device map file does not already exist. The -file name @file{/boot/grub/device.map} is preferred. - If the device map file exists, the GRUB utilities (@command{grub-probe}, @command{grub-setup}, etc.) read it to map BIOS drives to OS devices. This file consists of lines like this: @example -@var{device} @var{file} +(@var{device}) @var{file} @end example @var{device} is a drive specified in the GRUB syntax (@pxref{Device @@ -713,11 +708,12 @@ custom menu entries you write. If the device map file does not exist, then the GRUB utilities will assume a temporary device map on the fly. This is often good enough, particularly in the common case of single-disk systems. -However, the device map file is not entirely obsolete yet, and there are -still some situations that require it to exist. If necessary, you may edit -the file if @command{grub-mkdevicemap} makes a mistake. You can put any -comments in the file if needed, as the GRUB utilities assume that a line is -just a comment if the first character is @samp{#}. +However, the device map file is not entirely obsolete yet, and it is +used for overriding when current environment is different from the one on boot. +Most common case is if you use a partition or logical volume as a disk for +virtual machine. You can put any comments in the file if needed, +as the GRUB utilities assume that a line is just a comment if +the first character is @samp{#}. @node BIOS installation @@ -2253,13 +2249,14 @@ by a digit, like @samp{fd0}, or @samp{cd}. AHCI, PATA (ata), crypto, USB use the name of driver followed by a number. Memdisk and host are limited to one disk and so it's refered just by driver name. -RAID (md), ofdisk (ieee1275 and nand), LVM (lv) and arcdisk (arc) use +RAID (md), ofdisk (ieee1275 and nand), LVM (lv), LDM and arcdisk (arc) use intrinsic name of disk prefixed by driver name. Additionally just ``nand'' refers to the disk aliased as ``nand''. Conflicts are solved by suffixing a number if necessarry. Commas need to be escaped. Loopback uses whatever name specified to @command{loopback} command. -Hostdisk uses names specified in device.map or hostdisk/. +Hostdisk uses names specified in device.map as long as it's of the form +[fhc]d[0-9]* or hostdisk/. For crypto and RAID (md) additionally you can use the syntax uuid/. diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index b338717de..ccd7f579f 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1200,6 +1200,7 @@ read_device_map (const char *dev_map) { char *p = buf; char *e; + char *drive_e, *drive_p; int drive; lineno++; @@ -1234,9 +1235,22 @@ read_device_map (const char *dev_map) show_error (tmp); } - map[drive].drive = xmalloc (p - e + sizeof ('\0')); - strncpy (map[drive].drive, e, p - e + sizeof ('\0')); - map[drive].drive[p - e] = '\0'; + map[drive].drive = 0; + if ((e[0] == 'f' || e[0] == 'h' || e[0] == 'c') && e[1] == 'd') + { + char *ptr; + for (ptr = e + 2; ptr < p; ptr++) + if (!grub_isdigit (*ptr)) + break; + if (ptr == p) + { + map[drive].drive = xmalloc (p - e + sizeof ('\0')); + strncpy (map[drive].drive, e, p - e + sizeof ('\0')); + map[drive].drive[p - e] = '\0'; + } + } + drive_e = e; + drive_p = p; map[drive].device_map = 1; p++; @@ -1279,6 +1293,21 @@ read_device_map (const char *dev_map) else #endif map[drive].device = xstrdup (p); + if (!map[drive].drive) + { + char c; + map[drive].drive = xmalloc (sizeof ("hostdisk/") + strlen (p)); + memcpy (map[drive].drive, "hostdisk/", sizeof ("hostdisk/") - 1); + strcpy (map[drive].drive + sizeof ("hostdisk/") - 1, p); + c = *drive_p; + *drive_p = 0; + grub_util_warn (_("the drive name %s in device.map is incorrect. " + "Using %s instead. " + "Please use the form [hfc]d[0-9]* " + "(E.g. `hd0' or `cd')"), + drive_e, map[drive].drive); + *drive_p = c; + } } fclose (fp);