Project

General

Profile

Bug #1945

Import GRUB 0.9.7 patches from Gentoo

Added by Richard Yao almost 9 years ago. Updated almost 6 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2015-01-26
Due date:
% Done:

100%

Estimated time:
(Total: 0.00 h)
Difficulty:
Bite-size
Tags:
needs-triage
Gerrit CR:

Description

I wanted to merge ZFS support into Gentoo's GRUB, so I took the sources from the Illumos-Gate repository and then proceeded to see which patches from Gentoo Linux apply to Illumos' GRUB and which did not. Here is an url to a Gentoo mirror from which you can download the Gentoo patches:

http://mirrors.rit.edu/gentoo/distfiles/grub-0.97-patches-1.11.tar.bz2

The following patches apply with -p1:

003_all_grub-0.97-example-rescue-shell.patch
010_all_grub-0.96-bounced-checks.patch
011_all_grub-0.97-varargs.patch
012_all_grub-0.97-gcc46.patch
016_all_grub-0.97-multiboot-memory-amount.patch
070_all_grub-0.97-initrd_max_address.patch
110_all_grub-0.97-ptable-fix.patch
420_all_grub-0.97-chainload-logical.patch
550_all_grub-0.97-long-commandline.patch
700_all_grub-0.97-grub-install_addsyncs.patch
710_all_grub-0.97-grub-install_regexp.patch
720_all_grub-0.97-grub-install_aoe_support.patch
800_all_grub-0.97-crossreference_manpages.patch
830_all_grub-0.97-raid_cciss.patch
840_all_grub-0.97_kvm_vda.patch
860_all_grub-0.97-pie.patch

The following patch applies with -p0:

100_all_grub-0.97-splashimage-example.patch

The following patches do not apply, although a few probably could be manually merged into Illumos GRUB without any issues:

001_all_grub-0.95.20040823-splash.patch
002_all_grub-0.97-splashimage-safety.patch
005_all_grub-0.96-PIC.patch
008_all_grub-0.97-AM_PROG_AS.patch
015_all_grub-0.96-unsigned-addresses.patch
040_all_grub-0.96-nxstack.patch
060_all_grub-0.96-netboot-pic.patch
090_all_grub-0.97-intelmac.patch
100_all_grub-0.97-splashimage-example.patch
300_all_grub-0.97-pie-safety.patch
410_all_grub-0.97-dhcp-vendorclass.patch
600_all_grub-0.97-gpt-partition-table.patch
810_all_grub-0.97-ext3_256byte_inode.patch
820_all_grub-0.97-cvs-sync.patch
821_all_grub-0.97-grub-special_device_names.patch
822_all_grub-0.97-geometry-26kernel.patch
850_all_grub-0.97_ext4.patch

Note that all of the patches that apply cleanly to Illumos' GRUB apply independently of one another, with the exception of 840_all_grub-0.97_kvm_vda.patch, which depends upon a change made in a previous patch.

I spoke to matsim in #openindiana about this. He found the gcc-4.6 and cciss patches to be interesting and suggested that I file a bug report. He cited the following blog post as an example of the cciss patch being useful:

http://www.greenviolet.net/articles/2011/09/21/openindiana-151a-and-hp-smart-array-controllers.gv

I imagine that the kvm_vda patch would also be useful to Illumos because KVM work being probably will eventually be followed by a virtio-net driver.

I will probably do some more work in merging the two GRUB 0.9.7 packages because I am experimenting with OpenIndiana in KVM, but I make no promises.


Files

grub-0.97-illumos-fix-gmake-whitespace.patch (2.19 KB) grub-0.97-illumos-fix-gmake-whitespace.patch Fix whitespace that breaks build with gmake Richard Yao, 2012-01-08 11:30 PM
grub-0.97-illumos-fix-gcc-undefined-uint.patch (1.33 KB) grub-0.97-illumos-fix-gcc-undefined-uint.patch Fix missing typedefs for uint32_t and uint64_t that breaks compilation with GCC Richard Yao, 2012-01-08 11:30 PM
grub-0.97-illumos-fix-device-buffer-length-mismatch.patch (1.04 KB) grub-0.97-illumos-fix-device-buffer-length-mismatch.patch Fix buffer length misatch that breaks GRUB installation Richard Yao, 2012-01-08 11:33 PM
grub-0.97-illumos-fix-gcc-undefined-uint-v2.patch (7.27 KB) grub-0.97-illumos-fix-gcc-undefined-uint-v2.patch Better solution to undefined uint32_t and uint64_t problem Richard Yao, 2012-01-15 09:48 PM
grub-0.97-illumos-fix-gmake-whitespace-v2.patch (2.22 KB) grub-0.97-illumos-fix-gmake-whitespace-v2.patch Fix issue in previous patch that modified Makefile instead of Makefile.in Richard Yao, 2012-01-15 09:48 PM

Subtasks

Feature #5560: grub should support EFI/GPT partitioningClosedHans Rosenfeld2015-01-26

Actions
#1

Updated by Richard Yao almost 9 years ago

I discovered three issues in Illumos GRUB 0.97 when I tried porting it to Gentoo Linux. Patches are attached.

One issue is a fairly serious bug where /sbin/grub will write a NULL character outside the bounds of a buffer into another buffer. It likely hasn't caused any problems on Illumos because if it writes the NULL character into a region not being used, things will not break. In my situation, it morphed "(hd0,0)/boot/grub/stage2" into "(hd0,0)/boot/grub/stage" because the '2' was the 256 character offset from the start of another buffer, breaking the installation of GRUB.

Here is a backtrace from GDB taken immediately before the corruption occurred:

(gdb) bt
#0 grub_strncat (s1=0xf350dd18 "(hd0)", s2=<optimized out>, n=256) at char_io.c:1050
#1 0x0805daf4 in sprint_device (drive=<optimized out>, partition=<optimized out>) at builtins.c:4861
#2 0x0805fe43 in setup_func (arg=<optimized out>) at builtins.c:5037
#3 0x08061f2f in enter_cmdline (heap=0xf34bcc90 "setup (hd0)", forever=1) at cmdline.c:174
#4 0x0805aa6d in cmain () at stage2.c:1106
#5 0x0804c514 in init_bios_info () at common.c:356
#6 0x080499ef in doit () at asmstub.c:132
#7 0x08049ae0 in grub_stage2 () at asmstub.c:189
#8 0x0804967f in main (argc=2, argv=0xffe70084) at main.c:264

My solution for this issue was to change the buffer size from 16 to 32 to match another buffer, while replacing 256 with sizeof device to reference the buffer. The code in question makes use of a GNUism that permits nested functions with the buffer declared in an outer function. I assume that the Sun Studio compiler supports nested functions in C, but someone should verify that the use of the sizeof operator in conjunction with nested functions is also supported by the Sun Studio compiler. Since I don't have a copy of Sun Studio, I cannot test this, but someone should verify that this works.

The second patch addresses a build failure that is caused by the absence of tabs on a few lines in ./grub-0.97/stage2/Makefile when building with gmake. I modified those lines to use tabs, which fixed this issue. The patch for this should be safe to merge into Illumos without any concern for regressions.

The third patch addresses a compilation failure that is caused by the use of uint32_t and uint64_t without a typedef, which GCC does not understand. I borrowed some t ypdefs from the /usr/include/stdint.h header file provided by glibc on Gentoo Linux and introduced ./grub-0.97/stage2/uint.h to be a home for them. I examined /usr/include/sys/int_types.h on OpenIndiana 151a and there is a possibility that doing this introduces a portability issue, so this should be tested to ensure that it works on Illumos.

#2

Updated by Richard Yao almost 9 years ago

The mismatch patch wasn't uploaded for some reason. I am trying again.

#3

Updated by Richard Yao almost 9 years ago

I was informed in IRC that there was an issue with one of my patches. It seems that I accidentally uploaded an old version of the gmake patch that modified Makefile instead of Makefile.in. I have attached a new patch to correct that.

Also, I took another look at the GRUB code and I discovered the presence of grub_uint32_t and grub_uint64_t in the ufs.h and ufs2.h files, so I factored those and some related type definitions into a separate types.h file and modified the ZFS code and UFS headers to rely on that. This is a much better solution than the previous approach I had taken.

Also available in: Atom PDF