[iso] attempt to fix the clusterfuck of GRUB 2.06 incompatible versions

* As was *ENTIRELY PREDICTIBLE*, the lack of timely releases from the GRUB
  project has resulted in distro maintainers (Ubuntu, Fedora, etc.) taking
  matters in their own hand and applying patches on top of their 2.06 version.
  However, these patches result in 2.06 bootloaders that are incompatible
  with 2.06 modules that don't have the same patches applied. Especially this
  now results in the infamous "452: out of range pointer" error message when
  using patched modules with unpatched bootloader or unpatched modules with
  patched bootloaders.
* Making this issue worse, we also have distro maintainers who won't add a
  suffix to their GRUB version, AS ONE SHOULD DO WHEN ONE APPLIES TONS OF
  PATCHES ON TOP OF A PROJECT'S SOURCE, and MISreport their non 2.06 GRUB as
  "2.06", and, because we can't detect what patches are needed from modules
  themselves (unlike what is the case for grub_debug_is_enabled), we have no
  way of telling incompatible GRUB 2.06 binaries from one another.
* As a result, we have no choice but to append a sanitized version of the ISO
  label to the GRUB version, as a means to differentiate between incompatible
  versions, and tweak our existing bootloader download mechanism to *ATTEMPT*
  to download a compatible 'core.img' from our server... where we will have
  to waste a lot of time adding new binaries and symlinks to try to make all
  these GRUB "2.06" based images work, and will probably miss quite few with
  the end results that users who are just trying to install Linux will be left
  stranded.
* Again, I have to point out how the end result of regular users wanting to
  try Linux and being unable to do so is the *DIRECT* result of the GRUB project
  maintainers having sat on a 2-year influx of CONTINUOUS patches, and thinking
  that "Release Early, Release Often" is only a gimmick, and not something that
  should apply to their project, even as they have been warned before, by yours
  truly, that *NOT* releasing on a timely basis is causing actual grievances...
  That's because, had the GRUB maintainers released on a timely basis (at least
  once a year) Fedora and Ubuntu would be using vanilla GRUB 2.07 with the memory
  patches, and we wouldn't be trying to mix that with old GRUB 2.06 binaries.
* For more on this, see #2233, noting that we will need to apply a compatibility
  breaking change during the 4.1 release, to revert the patches we applied to
  the default 2.06 'core.img' in pbatard/rufus-web@320b800592.
This commit is contained in:
Pete Batard 2023-05-16 14:03:03 +01:00
parent 23d89d9764
commit 3a0f7d3813
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
5 changed files with 131 additions and 44 deletions

View file

@ -887,7 +887,6 @@ void GetGrubVersion(char* buf, size_t buf_size)
const char* grub_version_str[] = { "GRUB version %s", "GRUB version %s" };
const char* grub_debug_is_enabled_str = "grub_debug_is_enabled";
const size_t max_string_size = 32; // The strings above *MUST* be no longer than this value
char *p, unauthorized[] = {'<', '>', ':', '|', '*', '?', '\\', '/'};
size_t i, j;
BOOL has_grub_debug_is_enabled = FALSE;
@ -902,13 +901,9 @@ void GetGrubVersion(char* buf, size_t buf_size)
has_grub_debug_is_enabled = TRUE;
}
}
// Sanitize the string
for (p = &img_report.grub2_version[0]; *p; p++) {
for (i = 0; i < sizeof(unauthorized); i++) {
if (*p == unauthorized[i])
*p = '_';
}
}
uprintf(" Reported Grub version: %s", img_report.grub2_version);
// <Shakes fist angrily> "KASPERSKYYYYYY!!!..." (https://github.com/pbatard/rufus/issues/467)
// But seriously, these guys should know better than "security" through obscurity...
if (img_report.grub2_version[0] == '0')
@ -931,16 +926,33 @@ void GetGrubVersion(char* buf, size_t buf_size)
// if [ -e /boot/grub2/i386-pc/normal.mod ]; then set prefix = ...
// you still must embed 'configfile.mod' and 'normal.mod' in 'core.img' in order
// to do that, which ends up tripling the file size...
// Also, as mentioned above, Fedora have started applying *BREAKING* patches
// willy-nilly, without bothering to alter the GRUB version string.
// Soooo, since the universe is conspiring against us and since we already have
// a facility for it, we'll use it to dowload the relevant 'core.img' by
// appending a missing version suffix as needed...
// Also, as mentioned above, Fedora, Ubuntu and others have started applying
// *BREAKING* patches willy-nilly, without bothering to alter the GRUB version
// string. And it gets worse with 2.06 since there are patches we can't detect
// that will produce "452: out of range pointer" whether they are applied OR NOT
// (meaning that if you use a patched GRUB 2.06 with unpatched GRUB 2.06 modules
// you will get the error, and if you use unpatched with patched modules, you
// will also get the error).
// Soooo, since the universe, and project maintainers who do not REALISE that
// NOT RELEASING IN A TIMELY MANNER *DOES* HAVE VERY NEGATIVE CONSEQUENCES FOR
// END USERS, are conspiring against us, and since we already have a facility
// for it, we'll use it to dowload the relevant 'core.img' by appending a missing
// version suffix as needed. Especially, if GRUB only identifies itself as '2.06'
// we'll append a sanitized version of the ISO label to try to differentiate
// between GRUB 2.06 incompatible versions...
if (img_report.grub2_version[0] != 0) {
if (has_grub_debug_is_enabled)
strcat(img_report.grub2_version, "-fedora");
// Make sure we append '-nonstandard' and '-gdie' before the sanitized label.
BOOL append_label = (safe_strcmp(img_report.grub2_version, "2.06") == 0);
// Must be in the same order as we have on the server
if (img_report.has_grub2 > 1)
strcat(img_report.grub2_version, "-nonstandard");
safe_strcat(img_report.grub2_version, sizeof(img_report.grub2_version), "-nonstandard");
if (has_grub_debug_is_enabled)
safe_strcat(img_report.grub2_version, sizeof(img_report.grub2_version), "-gdie");
if (append_label) {
safe_strcat(img_report.grub2_version, sizeof(img_report.grub2_version), "-");
safe_strcat(img_report.grub2_version, sizeof(img_report.grub2_version), img_report.label);
}
sanitize_label(img_report.grub2_version);
}
}
@ -1188,9 +1200,7 @@ out:
free(buf);
DeleteFileU(path);
}
if (img_report.grub2_version[0] != 0) {
uprintf(" Detected Grub version: %s", img_report.grub2_version);
} else {
if (img_report.grub2_version[0] == 0) {
uprintf(" Could not detect Grub version");
img_report.has_grub2 = 0;
}