~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to debian/patches/ubuntu_embed_signatures.patch

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 sectors matching any of the signatures in embed_signatures.
4
4
Author: Colin Watson <cjwatson@ubuntu.com>
5
5
Forwarded: http://lists.gnu.org/archive/html/grub-devel/2010-08/msg00137.html
6
 
Last-Update: 2010-09-17
 
6
Last-Update: 2010-11-22
7
7
 
8
 
Index: b/util/i386/pc/grub-setup.c
9
 
===================================================================
10
 
--- a/util/i386/pc/grub-setup.c
11
 
+++ b/util/i386/pc/grub-setup.c
12
 
@@ -66,6 +66,46 @@
13
 
 #define grub_host_to_target32(x)       grub_cpu_to_le32(x)
14
 
 #define grub_host_to_target64(x)       grub_cpu_to_le64(x)
 
8
Index: b/ChangeLog.embed-sectors
 
9
===================================================================
 
10
--- /dev/null
 
11
+++ b/ChangeLog.embed-sectors
 
12
@@ -0,0 +1,7 @@
 
13
+2010-11-22  Colin Watson  <cjwatson@ubuntu.com>
 
14
+
 
15
+       * partmap/msdos.c (embed_signatures): New array.
 
16
+       (pc_partition_map_embed): Check for and avoid sectors matching any
 
17
+       of the signatures in embed_signatures.
 
18
+       * util/grub-setup.c (setup): Allow for the embedding area being
 
19
+       split into multiple blocklists.
 
20
Index: b/grub-core/partmap/msdos.c
 
21
===================================================================
 
22
--- a/grub-core/partmap/msdos.c
 
23
+++ b/grub-core/partmap/msdos.c
 
24
@@ -27,6 +27,45 @@
 
25
 static struct grub_partition_map grub_msdos_partition_map;
 
26
 
15
27
 
 
28
+#ifdef GRUB_UTIL
 
29
+#include <grub/emu/misc.h>
 
30
+
16
31
+struct embed_signature
17
32
+{
18
33
+  const char *name;
45
60
+      .signature = "\x70\x8a\x5d\x46\x35\xc5\x1b\x93"
46
61
+                  "\xae\x3d\x86\xfd\xb1\x55\x3e\xe0",
47
62
+      .signature_len = 16
48
 
+    },
49
 
+    {
50
 
+      .name = "Dell DataSafe Local Backup",
51
 
+      .signature = "\xf6\x14\x84\xb4\xc1\x13\x01\xf5",
52
 
+      .signature_len = 8
53
63
+    }
54
64
+  };
 
65
+#endif
55
66
+
56
 
 void 
57
 
 grub_xputs_real (const char *str)
58
 
 {
59
 
@@ -108,7 +148,7 @@
60
 
   char *prefix = NULL;
61
 
   char *tmp_img;
62
 
   int i;
63
 
-  grub_disk_addr_t first_sector;
64
 
+  grub_disk_addr_t first_sector, es;
65
 
   grub_uint16_t current_segment
66
 
     = GRUB_BOOT_MACHINE_KERNEL_SEG + (GRUB_DISK_SECTOR_SIZE >> 4);
67
 
   grub_uint16_t last_length = GRUB_DISK_SECTOR_SIZE;
68
 
@@ -423,15 +463,96 @@
69
 
   assert (first_block->segment == grub_host_to_target16 (GRUB_BOOT_MACHINE_KERNEL_SEG
70
 
                                                    + (GRUB_DISK_SECTOR_SIZE >> 4)));
 
67
 grub_err_t
 
68
 grub_partition_msdos_iterate (grub_disk_t disk,
 
69
                              int (*hook) (grub_disk_t disk,
 
70
@@ -234,13 +273,56 @@
71
71
 
72
 
-  /* Make sure that the second blocklist is a terminator.  */
73
 
   block = first_block - 1;
74
 
+
75
 
+  if (strcmp (dest_partmap, "msdos") == 0)
76
 
+    {
77
 
+      /* Check for software that is already using parts of the MBR gap.  */
78
 
+      char *embed_signature_check = xmalloc (GRUB_DISK_SECTOR_SIZE);
79
 
+      grub_uint16_t extra_sectors = 0;
80
 
+
81
 
+      for (es = embed_region.start + 1; es < embed_region.start + core_sectors;
82
 
+          es++)
 
72
   if (end >= *nsectors + 1)
 
73
     {
 
74
-      int i;
 
75
+      int i, j;
 
76
+      char *embed_signature_check;
 
77
+      unsigned int orig_nsectors, extra_sectors = 0;
 
78
+
 
79
+      orig_nsectors = *nsectors;
 
80
       *nsectors = end - 1;
 
81
       *sectors = grub_malloc (*nsectors * sizeof (**sectors));
 
82
       if (!*sectors)
 
83
        return grub_errno;
 
84
       for (i = 0; i < *nsectors; i++)
 
85
        (*sectors)[i] = 1 + i;
 
86
+
 
87
+      /* Check for software that is already using parts of the embedding
 
88
+       * area.
 
89
+       */
 
90
+      embed_signature_check = grub_malloc (GRUB_DISK_SECTOR_SIZE);
 
91
+      for (i = 0; i < *nsectors; i++)
83
92
+       {
84
 
+         struct grub_boot_blocklist *prev_block;
85
 
+         grub_uint64_t prev_start;
86
 
+         grub_uint16_t prev_len;
87
 
+         grub_uint16_t prev_segment;
88
 
+
89
 
+         if (grub_disk_read (dest_dev->disk, es, 0, GRUB_DISK_SECTOR_SIZE,
 
93
+         if (grub_disk_read (disk, (*sectors)[i], 0, GRUB_DISK_SECTOR_SIZE,
90
94
+                             embed_signature_check))
91
95
+           continue;
92
96
+
93
 
+         for (i = 0; i < ARRAY_SIZE (embed_signatures); i++)
94
 
+           if (! memcmp (embed_signatures[i].signature, embed_signature_check,
95
 
+                         embed_signatures[i].signature_len))
 
97
+         for (j = 0; j < ARRAY_SIZE (embed_signatures); j++)
 
98
+           if (! grub_memcmp (embed_signatures[j].signature,
 
99
+                              embed_signature_check,
 
100
+                              embed_signatures[j].signature_len))
96
101
+             break;
97
 
+         if (i == ARRAY_SIZE (embed_signatures))
 
102
+         if (j == ARRAY_SIZE (embed_signatures))
98
103
+           continue;
99
 
+         grub_util_warn ("Sector %llu is already in use by %s; avoiding it.  This software may cause boot or other problems in future.  Please ask its authors not to store data in the boot track.",
100
 
+                         es, embed_signatures[i].name);
 
104
+         grub_util_warn ("Sector %llu is already in use by %s; avoiding it.  "
 
105
+                         "This software may cause boot or other problems in "
 
106
+                         "future.  Please ask its authors not to store data "
 
107
+                         "in the boot track",
 
108
+                         (*sectors)[i], embed_signatures[j].name);
101
109
+         extra_sectors++;
102
110
+
103
 
+         /* Adjust the last blocklist, splitting it in two if necessary, to
104
 
+            avoid this sector.  */
105
 
+         prev_block = block + 1;
106
 
+         prev_start = grub_target_to_host64 (prev_block->start);
107
 
+         prev_len = grub_target_to_host16 (prev_block->len);
108
 
+         prev_segment = grub_target_to_host16 (prev_block->segment);
109
 
+
110
 
+         if (es == prev_start)
111
 
+           prev_block->start = grub_host_to_target64 (prev_start + 1);
112
 
+         else
113
 
+           {
114
 
+             prev_block->len = grub_host_to_target16 (es - prev_start);
115
 
+
116
 
+             block->start = grub_host_to_target64 (es + 1);
117
 
+             block->len = grub_host_to_target16
118
 
+               (prev_len - (es - prev_start));
119
 
+             block->segment = grub_host_to_target16
120
 
+               (prev_segment +
121
 
+                (GRUB_DISK_SECTOR_SIZE >> 4) * (es - prev_start));
122
 
+
123
 
+             block--;
124
 
+             if (block->len)
125
 
+               grub_util_error (_("the post-MBR gap is too fragmented by sectors used by other software"));
126
 
+           }
127
 
+       }
128
 
+      free (embed_signature_check);
129
 
+
130
 
+      if ((unsigned long) (core_sectors + extra_sectors)
131
 
+         > embed_region.end - embed_region.start)
132
 
+       {
133
 
+         grub_util_warn (_("Other software is using the embedding area, and there is not enough room for core.img.  Such software is often trying to store data in a way that avoids detection.  We recommend you investigate."));
134
 
+         goto unable_to_embed;
135
 
+       }
136
 
+    }
137
 
+
138
 
+  /* Make sure that the last blocklist is a terminator.  */
139
 
   block->start = 0;
140
 
   block->len = 0;
141
 
   block->segment = 0;
142
 
 
143
 
   /* Write the core image onto the disk.  */
144
 
-  if (grub_disk_write (dest_dev->disk, embed_region.start, 0, core_size, core_img))
145
 
+  if (grub_disk_write (dest_dev->disk, embed_region.start, 0,
146
 
+                      GRUB_DISK_SECTOR_SIZE, core_img))
147
 
     grub_util_error ("%s", grub_errmsg);
148
 
+  tmp_img = core_img + GRUB_DISK_SECTOR_SIZE;
149
 
+  for (block = first_block; block->start; block--)
150
 
+    {
151
 
+      grub_uint64_t start;
152
 
+      size_t size;
153
 
+
154
 
+      start = grub_target_to_host64 (block->start);
155
 
+      size = grub_target_to_host16 (block->len) << GRUB_DISK_SECTOR_BITS;
156
 
+      /* The last sector may be incomplete.  */
157
 
+      if (! (block + 1)->start && (core_size % GRUB_DISK_SECTOR_SIZE))
158
 
+       size -= GRUB_DISK_SECTOR_SIZE - (core_size % GRUB_DISK_SECTOR_SIZE);
159
 
+
160
 
+      if (grub_disk_write (dest_dev->disk, start, 0, size, tmp_img))
161
 
+       grub_util_error ("%s", grub_errmsg);
162
 
+      tmp_img += size;
163
 
+    }
164
 
 
165
 
   /* FIXME: can this be skipped?  */
166
 
   *boot_drive = 0xFF;
 
111
+         /* Avoid this sector.  */
 
112
+         for (j = i; j < *nsectors; j++)
 
113
+           (*sectors)[j]++;
 
114
+       }
 
115
+      grub_free (embed_signature_check);
 
116
+
 
117
+      if (end + extra_sectors < orig_nsectors + 1)
 
118
+       return grub_error (GRUB_ERR_OUT_OF_RANGE,
 
119
+                          "Other software is using the embedding area, and "
 
120
+                          "there is not enough room for core.img.  Such "
 
121
+                          "software is often trying to store data in a way "
 
122
+                          "that avoids detection.  We recommend you "
 
123
+                          "investigate.");
 
124
+
 
125
       return GRUB_ERR_NONE;
 
126
     }
 
127
 
 
128
Index: b/util/grub-setup.c
 
129
===================================================================
 
130
--- a/util/grub-setup.c
 
131
+++ b/util/grub-setup.c
 
132
@@ -444,6 +444,13 @@
 
133
       save_blocklists (sectors[i] + grub_partition_get_start (container),
 
134
                       0, GRUB_DISK_SECTOR_SIZE);
 
135
 
 
136
+    /* Make sure that the last blocklist is a terminator.  */
 
137
+    if (block == first_block)
 
138
+      block--;
 
139
+    block->start = 0;
 
140
+    block->len = 0;
 
141
+    block->segment = 0;
 
142
+
 
143
     write_rootdev (core_img, root_dev, boot_img, first_sector);
 
144
 
 
145
     core_img = realloc (core_img, nsec * GRUB_DISK_SECTOR_SIZE);
 
146
@@ -460,12 +467,6 @@
 
147
                                      nsec * GRUB_DISK_SECTOR_SIZE
 
148
                                      - core_size);
 
149
 
 
150
-    /* Make sure that the second blocklist is a terminator.  */
 
151
-    block = first_block - 1;
 
152
-    block->start = 0;
 
153
-    block->len = 0;
 
154
-    block->segment = 0;
 
155
-
 
156
     /* Write the core image onto the disk.  */
 
157
     for (i = 0; i < nsec; i++)
 
158
       grub_disk_write (dest_dev->disk, sectors[i], 0,