Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 281246 - sys-boot/grub-0.97-r9 with hardened i686 gcc 3.4.6 won't boot
Summary: sys-boot/grub-0.97-r9 with hardened i686 gcc 3.4.6 won't boot
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Hardened (show other bugs)
Hardware: x86 Linux
: High critical with 1 vote (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard: done:0.97-r10
Keywords: EBUILD
: 139277 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-08-12 20:20 UTC by mephinet
Modified: 2017-10-26 19:32 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (emerge_info.out,3.27 KB, text/plain)
2009-08-12 20:35 UTC, mephinet
Details
emerge --info with hardened gcc profile (emerge_info_hardened.out,3.26 KB, text/plain)
2009-08-12 20:39 UTC, mephinet
Details
Ported the Grub2 -fPIE Check (grub-0.97-fpie_check.patch,1.39 KB, patch)
2009-09-05 16:16 UTC, Magnus Granberg
Details | Diff
Old gcc 3.4.6 hardened defined __PIC__ instead of __PIE__ (fpie_check.patch,1.16 KB, patch)
2009-10-01 16:03 UTC, Magnus Granberg
Details | Diff
ebuild that applies the patch (grub-0.97-r10.ebuild,8.80 KB, text/plain)
2009-10-02 20:13 UTC, mephinet
Details
Clean -fPIE check patch (grub-0.97-fpie_check.patch,745 bytes, patch)
2010-03-09 12:29 UTC, Magnus Granberg
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mephinet 2009-08-12 20:20:33 UTC
Dear gentoo hardened team,

I did a stage3 2008.0 installation of my new Via Epia SN, which worked without problems. I then switched to the hardened profile and ran emerge -e world.
After that, the machine no longer booted, but immediately reboots before any grub output shows up.

When switching back to gcc vanilla 3.4.6, the problem goes away.
Comment 1 mephinet 2009-08-12 20:25:32 UTC
switched back and forth twice to double-check, always with the same result.
this is a Via Esther processor.

output of emerge --info comes in a few minues.
Comment 2 mephinet 2009-08-12 20:35:02 UTC
Created attachment 201075 [details]
emerge --info
Comment 3 mephinet 2009-08-12 20:39:30 UTC
Created attachment 201076 [details]
emerge --info with hardened gcc profile
Comment 4 Magnus Granberg gentoo-dev 2009-08-12 23:49:23 UTC
Hi can you try -hardenednopie or -hardenednossp gcc profile and see what profile
make it not boot and are grub working from the command line?
Comment 5 mephinet 2009-08-13 08:04:30 UTC
(In reply to comment #4)
> Hi can you try -hardenednopie or -hardenednossp gcc profile and see what
> profile
> make it not boot and are grub working from the command line?

I will try this in the evening.
At least the commandline tool grub-install always worked fine.

For completeness sake: the Via Esther is also called Via C7.
Comment 6 mephinet 2009-08-13 08:13:16 UTC
My profile is hardened/linux/x86/2008.0/server/
Comment 7 mephinet 2009-08-13 20:38:13 UTC
nopie: boots
nossp: does not boot.

so pie is the one to blame here.
Comment 8 Magnus Granberg gentoo-dev 2009-08-18 13:50:50 UTC
Can't test the error but will look at it more and hope get a working patch.
Some way the ebuild do not disable PIE/PIC for grub on your platform.
Comment 9 Magnus Granberg gentoo-dev 2009-08-18 14:54:30 UTC
Check the size of the boot/grub dir
Size of stage1 and stage2?
Comment 10 Xake 2009-08-18 15:08:43 UTC
More accurate, please do:

du -hs /lib/grub
Comment 11 mephinet 2009-08-18 15:33:43 UTC
 * Switching native-compiler to i686-pc-linux-gnu-3.4.6 ...
... emerging grub ...
$ du -hs /lib/grub
368K	/lib/grub

 * Switching native-compiler to i686-pc-linux-gnu-3.4.6-hardenednopie ...
... emerging grub ...
$ du -hs /lib/grub
368K	/lib/grub
Comment 12 mephinet 2009-08-18 16:46:56 UTC
Sorry, I messed up!
please ignore comment #11.

Once again:

 * Switching native-compiler to i686-pc-linux-gnu-3.4.6 ...
... source /etc/profile, emerge grub ...
$ du -hs /lib/grub
368K	/lib/grub

 * Switching native-compiler to i686-pc-linux-gnu-3.4.6-hardenednopie ...
$ du -hs /lib/grub
336K	/lib/grub
Comment 13 Magnus Granberg gentoo-dev 2009-09-05 13:58:43 UTC
Some way do not the filter-flags -fPIE in the ebuild work as it should.
Comment 14 Magnus Granberg gentoo-dev 2009-09-05 16:16:00 UTC
Created attachment 203206 [details, diff]
Ported the Grub2 -fPIE Check

Try this patch and see if it works.
Comment 15 mephinet 2009-09-20 21:40:15 UTC
(In reply to comment #14)
> Ported the Grub2 -fPIE Check
> 
> Try this patch and see if it works.

Dear Magnus,

sorry it took so long for me to find an opportunity to make this test!
I stored your patch in the files subdirectory, added the following line to the ebuild:
        epatch "${FILESDIR}"/grub-0.97-fpie_check.patch

Now, with gcc-config set to i686-pc-linux-gnu-3.4.6, when I run configure, I see:

$ ebuild grub-0.97-r9.ebuild compile
...
 * Applying grub-0.97-fpie_check.patch ... ok
...
checking whether `i686-pc-linux-gnu-gcc' has `-fPIE' as default... no

which is not what I expected...
Comment 16 Magnus Granberg gentoo-dev 2009-09-20 22:14:39 UTC
(In reply to comment #15)
> (In reply to comment #14)
> > Ported the Grub2 -fPIE Check
> > 
> > Try this patch and see if it works.
> 
> Dear Magnus,
> 
> sorry it took so long for me to find an opportunity to make this test!
> I stored your patch in the files subdirectory, added the following line to the
> ebuild:
>         epatch "${FILESDIR}"/grub-0.97-fpie_check.patch
> 
> Now, with gcc-config set to i686-pc-linux-gnu-3.4.6, when I run configure, I
> see:
> 
> $ ebuild grub-0.97-r9.ebuild compile
> ...
>  * Applying grub-0.97-fpie_check.patch ... ok
> ...
> checking whether `i686-pc-linux-gnu-gcc' has `-fPIE' as default... no
> 
> which is not what I expected...
> 
Remove the filter-flags -fPIE line in the ebuild.
Comment 17 Gordon Malm (RETIRED) gentoo-dev 2009-09-25 18:47:26 UTC
Hi base-system, another grub+PIE fail.  Re-assigning like bug 139277.  Curious, what is the resistance to patching configure/make/whatever to filter pic/pie?  thanks.
Comment 18 mephinet 2009-09-30 20:09:45 UTC
(In reply to comment #16)
> Remove the filter-flags -fPIE line in the ebuild.

No matter whether I filter-flag, remove-flag, add-flag PIE or no-PIE in the ebuild, the size of the /lib/grub directory stays constant the the non-booting value...
Comment 19 Magnus Granberg gentoo-dev 2009-10-01 16:03:25 UTC
Created attachment 205767 [details, diff]
Old gcc 3.4.6 hardened defined __PIC__ instead of __PIE__

Can you check with this patch.
Comment 20 mephinet 2009-10-01 21:24:22 UTC
oh yes, this looks good - the PIE detection returns "yes" now and the /lib/grub size is as expected. I'll reboot tomorrow evening...
Comment 21 mephinet 2009-10-02 20:12:20 UTC
Magnus, thanks a log for your support, the reboot was successful - so your fpie_check.patch fixes the issue.
I don't know whether you want to add your patch to the grub patch collection tarball - in case you don't, here's the ebuild that applies your patch successfully...
(I don't mark the bug as resolved, as it's not in the official tree yet - I hope that's the correct workflow...)
Comment 22 mephinet 2009-10-02 20:13:07 UTC
Created attachment 205872 [details]
ebuild that applies the patch
Comment 23 Magnus Granberg gentoo-dev 2009-10-02 23:11:09 UTC
http://git.overlays.gentoo.org/gitweb/?p=proj/hardened-dev.git;a=commit;h=b7b83daed781b58a0532d5d9c19f98d091a3b164

Thanks for finding the bug and testing the patch.
@base-system this patch fix bug 139277 to.
Comment 24 Kai Dietrich 2009-11-23 09:31:28 UTC
whohoo, this just saved my day...

just for the records: i'm setting up a hardened amd64 box at the moment and when it came to installing grub 0.97-r9, after rebooting, grub came up with just a console and was just reporting "Error 28: Selected item cannot fit into memory" on every command you would type, it also detected 0K upper memory.

now 0.97-r11 from hardened-dev overlay works fine
Comment 25 Magnus Granberg gentoo-dev 2010-03-09 12:29:17 UTC
Created attachment 222823 [details, diff]
Clean -fPIE check patch

Have clean the patch up
If i try to check for -nopie instead of -fPIE it allways true, if
i use the code from the -fno-stack-protector check.
Comment 26 SpanKY gentoo-dev 2010-03-10 00:43:39 UTC
that looks fine.  the PIC stuff is odd, but not much we can do about it i guess.
Comment 28 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-25 00:33:28 UTC
*** Bug 139277 has been marked as a duplicate of this bug. ***
Comment 29 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-25 00:34:04 UTC
reopening to spin patchset tarball
Comment 30 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-25 06:21:24 UTC
Now committed and published as new patchset: grub-0.97-patches-1.10.tar.bz2
Ebuild sys-boot/grub-0.97-r10 committed.
Comment 31 Ian Stakenvicius (RETIRED) gentoo-dev 2017-10-26 19:32:54 UTC
gcc-6 (at least 6.4, didn't check others) drops the gentoo pie patches, and with it the 'nopie' option; the patch now needs to use '-no-pie' instead it seems.

As this is contingent on the gcc version (and grub-0.97 likely has a limited lifespan) i'm going to sed -nopie to -no-pie on the patch on new-enough gcc rather than trying to conditionally apply different patches.