Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 428726 - sys-kernel/hardened-sources-3.4.6-r1: PAX_KERNEXEC makes the kernel unbootable with sys-boot/grub-2.00[efi-32,efi-64]
Summary: sys-kernel/hardened-sources-3.4.6-r1: PAX_KERNEXEC makes the kernel unbootabl...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Hardened (show other bugs)
Hardware: x86 Linux
: Normal major (vote)
Assignee: The Gentoo Linux Hardened Kernel Team (OBSOLETE)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-30 23:47 UTC by Maxim Kammerer
Modified: 2012-12-13 22:00 UTC (History)
3 users (show)

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


Attachments
minimal hardened-sources-3.4.6-r1 configuration, with KERNEXEC (linux-3.4.6-hardened-clean-kernexec-efi-bad.config,22.25 KB, text/plain)
2012-07-30 23:51 UTC, Maxim Kammerer
Details
minimal hardened-sources-3.4.6-r1 configuration, without KERNEXEC (linux-3.4.6-hardened-clean-kernexec-efi-good.config,22.31 KB, text/plain)
2012-07-30 23:55 UTC, Maxim Kammerer
Details
output from non-KERNEXEC kernel with IA32 OVMF firmware (serial-ia32.log,6.32 KB, text/plain)
2012-07-30 23:57 UTC, Maxim Kammerer
Details
output from non-KERNEXEC kernel with x64 OVMF firmware (serial-x64.log,6.32 KB, text/plain)
2012-07-30 23:59 UTC, Maxim Kammerer
Details
output from full-blown kernel with IA32 OVMF firmware (serial-ia32-full-blown.log,91.90 KB, text/plain)
2012-07-31 13:59 UTC, Maxim Kammerer
Details
full-blown x86 3.4.2-hardened kernel config (linux-3.4.2-hardened.config,103.29 KB, text/plain)
2012-07-31 14:14 UTC, Maxim Kammerer
Details
hardened-sources-3.4.6-r1 config that works with kernexec and sys-boot/grub-2.00[grub_platforms_efi-64] (.config,77.76 KB, text/plain)
2012-08-03 06:48 UTC, Matthew Thode ( prometheanfire )
Details
pax patch for hardened-sources-3.4.7 (misses another grsecurity patch) (pax-linux-3.4.7-test27-28-diff.patch,678 bytes, patch)
2012-08-05 23:31 UTC, Maxim Kammerer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maxim Kammerer 2012-07-30 23:47:53 UTC
As a followup to bug #428576, PAX_KERNEXEC, in full-blown or minimal kernels makes GRUB-EFI fail to load the kernel with:

    error: couldn't find suitable memory target.

Minimal "bad" and "good" kernel configs will be attached in the following comments.


Here is a simple mini-HOWTO for setting up a QEMU UEFI environment and an ISO that will have GRUB-EFI automatically boot the kernel (start in an empty directory, nothing will be written outside the directory). The commands assume that a bzImage is ready.


Required packages:
  + app-cdr/cdrtools-3.01_alpha07 (unstable, for -eltorito-platform efi)
  + sys-fs/dosfstools, sys-fs/mtools
  + sys-boot/grub-2.00[GRUB_PLATFORMS="efi-32 efi-64"]
  + app-emulation/qemu-kvm-1.0.1[QEMU_SOFTMMU_TARGETS="x86_64"]


Prepare TianoCore OVMF firmware:

----------
wget -O ovmf-ia32.zip http://sourceforge.net/projects/edk2/files/OVMF/OVMF-IA32-r11337-alpha.zip/download
wget -O ovmf-x64.zip http://sourceforge.net/projects/edk2/files/OVMF/OVMF-X64-r11337-alpha.zip/download

mkdir -p ovmf/ia32 ovmf/x64
unzip -od ovmf/ia32 ovmf-ia32.zip
unzip -od ovmf/x64 ovmf-x64.zip

ln -sf OVMF.fd ovmf/ia32/bios.bin
ln -sf CirrusLogic5446.rom ovmf/ia32/vgabios-cirrus.bin
ln -sf /usr/share/qemu/vapic.bin ovmf/ia32/

ln -sf OVMF.fd ovmf/x64/bios.bin
ln -sf CirrusLogic5446.rom ovmf/x64/vgabios-cirrus.bin
ln -sf /usr/share/qemu/vapic.bin ovmf/x64/
----------


Generate GRUB-EFI images (32- and 64-bit), embed them in an EFI El-Torito boot section, and create an ISO with the kernel:

----------
mkdir -p boot/grub EFI/BOOT
cat > boot/grub/grub.cfg <<EOF
set timeout=1
menuentry "Linux" {
linux (cd0)/bzImage earlyprintk=serial,keep debug
}
EOF

grub2-mkstandalone -O i386-efi   -o EFI/BOOT/BOOTIA32.EFI boot/grub/grub.cfg
grub2-mkstandalone -O x86_64-efi -o EFI/BOOT/BOOTx64.EFI  boot/grub/grub.cfg

truncate -s 5M efiboot.img
mkdosfs efiboot.img
MTOOLS_SKIP_CHECK=1 mcopy -i efiboot.img -sQ EFI ::

mkisofs -o efi.iso -R -no-emul-boot -eltorito-platform efi -b efiboot.img efiboot.img /usr/src/linux-3.4.6-hardened-r1/arch/x86/boot/bzImage
----------


Run QEMU-KVM with OVMF firmware and logged kernel output:

----------
qemu-system-x86_64 -cpu kvm64 -L ovmf/ia32 -nodefaults -sdl -monitor vc -m 64M -vga cirrus -cdrom efi.iso -serial file:serial.log

qemu-system-x86_64 -cpu kvm64 -L ovmf/x64 -nodefaults -sdl -monitor vc -m 64M -vga cirrus -cdrom efi.iso -serial file:serial.log
----------

To cleanly exit QEMU, press Ctrl-Alt-2 and type "stop", "exit".
Comment 1 Maxim Kammerer 2012-07-30 23:51:47 UTC
Created attachment 319792 [details]
minimal hardened-sources-3.4.6-r1 configuration, with KERNEXEC

Minimal configuration for a kernel that GRUB fails to load.
Comment 2 Maxim Kammerer 2012-07-30 23:55:20 UTC
Created attachment 319794 [details]
minimal hardened-sources-3.4.6-r1 configuration, without KERNEXEC

Minimal configuration for a kernel that GRUB successfully loads. PAX_KERNEXEC has been replaced with PAX_SEGMEXEC (since some memory execution protection must be compiled in when PAX is enabled).

The configuration files are for x86 kernels.
Comment 3 Maxim Kammerer 2012-07-30 23:57:58 UTC
Created attachment 319796 [details]
output from non-KERNEXEC kernel with IA32 OVMF firmware

This is the expected output -- GRUB loads the kernel, and it proceeds up to "init" launch failure.
Comment 4 Maxim Kammerer 2012-07-30 23:59:25 UTC
Created attachment 319798 [details]
output from non-KERNEXEC kernel with x64 OVMF firmware

Similar output for x64 OVMF firmware.
Comment 5 Maxim Kammerer 2012-07-31 13:44:07 UTC
Reducing QEMU's RAM size results in the same message for kernels that GRUB otherwise succeeds to load. However, with PAX_KERNEXEC increasing available RAM has no effect.

I suspect KERNEXEC results in some build-time kernel image corruption that manifests during EFI boot, will attach a full-blown kernel output with NULL derefs soon.
Comment 6 Maxim Kammerer 2012-07-31 13:59:27 UTC
Created attachment 319874 [details]
output from full-blown kernel with IA32 OVMF firmware

PAX_KERNEXEC is not configured, so GRUB succeeds in loading the kernel. However, there is a stream of NULL derefs, and a reboot afterwards. So my previous comment was not exact -- the image and/or memory corruption (if it is indeed the case) is apparently caused by GRKERNSEC/PAX in general, not just PAX_KERNEXEC.

Kernel config to be attached in next comment.
Comment 7 Maxim Kammerer 2012-07-31 14:14:07 UTC
Created attachment 319880 [details]
full-blown x86 3.4.2-hardened kernel config

This is the configuration that results in a stream of NULL derefs. It is for kernel 3.4.2, but the same issue is present in 3.4.6-hardened-r1 as well (just make oldconfig).

Note that PHYSICAL_START==PHYSICAL_ALIGN as a (BIOS boot) workaround for bug #428576.
Comment 8 Maxim Kammerer 2012-08-02 15:56:34 UTC
(In reply to comment #5)
> I suspect KERNEXEC results in some build-time kernel image corruption that
> manifests during EFI boot, will attach a full-blown kernel output with NULL
> derefs soon.

The stream of NULL derefs was apparently caused by bug #428576, and is not present anymore in hardened-sources-3.4.7.

However, the original problem (PAX_KERNEXEC causing GRUB-EFI to fail with: "error: couldn't find suitable memory target.") is still present.

By the way, it is possible that the problem is not only with EFI, but I don't have a setup for GRUB BIOS boot.
Comment 9 Maxim Kammerer 2012-08-02 16:00:53 UTC
Comment on attachment 319874 [details]
output from full-blown kernel with IA32 OVMF firmware

Stream of NULL derefs is an unrelated problem that was apparently fixed in bug #428576.
Comment 10 Maxim Kammerer 2012-08-02 16:01:46 UTC
Comment on attachment 319880 [details]
full-blown x86 3.4.2-hardened kernel config

Stream of NULL derefs is an unrelated problem that was apparently fixed in bug #428576.
Comment 11 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2012-08-03 06:48:37 UTC
Created attachment 320136 [details]
hardened-sources-3.4.6-r1 config that works with kernexec and sys-boot/grub-2.00[grub_platforms_efi-64]
Comment 12 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2012-08-03 06:49:45 UTC
I just built to test on my laptop and grub2 uefi-64 is running with the kenrnel running kernexec just fine so far.
Comment 13 Anthony Basile gentoo-dev 2012-08-03 10:16:24 UTC
(In reply to comment #11)
> Created attachment 320136 [details]
> hardened-sources-3.4.6-r1 config that works with kernexec and
> sys-boot/grub-2.00[grub_platforms_efi-64]

Matt, I didn't look through this, but is there any subtle point that needs to be documented so others don't hit the same?
Comment 14 Maxim Kammerer 2012-08-03 12:53:19 UTC
(In reply to comment #12)
> I just built to test on my laptop and grub2 uefi-64 is running with the
> kenrnel running kernexec just fine so far.

Hi, I understand that you tested an x86_64 kernel on real hardware? This bug is about x86 in QEMU OVMF. I suspect that it's some elusive image corruption, and KERNEXEC only happens to trigger it. E.g., I have a (full-blown) kernel (without KERNEXEC) panicking, or entering an infinite loop during memtest on IA32 OVMF firmware, but not on x64 firmware. Will try to narrow that down and submit a separate bug.
Comment 15 PaX Team 2012-08-03 22:06:04 UTC
the latest patches should fix the problem, although 64M is still too low but 96M worked here, i didn't bother to figure out the exact limit ;).
Comment 16 Maxim Kammerer 2012-08-03 23:21:43 UTC
(In reply to comment #15)
> the latest patches should fix the problem, although 64M is still too low but
> 96M worked here, i didn't bother to figure out the exact limit ;).

Great, will test as soon as it's released on grsecurity.net (I assume it's not the change in net/netfilter/nf_conntrack_core.c wrt. hardened-sources-3.4.7 in currently available patches, since this file is not compiled into the minimal kernel in comment #1).
Comment 17 Maxim Kammerer 2012-08-05 18:00:40 UTC
(In reply to comment #15)
> the latest patches should fix the problem, although 64M is still too low but
> 96M worked here, i didn't bother to figure out the exact limit ;).

Did you forget to update grsecurity patches? I see pax-linux-3.4.7-test28.patch from Aug 3, but grsecurity-2.9.1-3.4.7-201208021520.patch (which a I understand includes pax-linux patches) is from Aug 2.

pax-linux patches are difficult to test, because hardened-sources used grsecurity patches.
Comment 18 PaX Team 2012-08-05 18:06:06 UTC
(In reply to comment #17)
> (In reply to comment #15)
> > the latest patches should fix the problem, although 64M is still too low but
> > 96M worked here, i didn't bother to figure out the exact limit ;).
> 
> Did you forget to update grsecurity patches?

i did not :). i maintain PaX, not grsecurity and spender has been away for the weekend, he'll update his patches soon. in the meantime you can just apply the interdiff to grsec, it'll work as well.
Comment 19 Anthony Basile gentoo-dev 2012-08-05 20:39:44 UTC
(In reply to comment #18)
> (In reply to comment #17)
> > (In reply to comment #15)
> > > the latest patches should fix the problem, although 64M is still too low but
> > > 96M worked here, i didn't bother to figure out the exact limit ;).
> > 
> > Did you forget to update grsecurity patches?
> 
> i did not :). i maintain PaX, not grsecurity and spender has been away for
> the weekend, he'll update his patches soon. in the meantime you can just
> apply the interdiff to grsec, it'll work as well.

Maxim, as pipacs said, I need to wait for everything to migrate forward.  I'm very much on top of things, maybe too much so!  ie Have patience :)
Comment 20 Maxim Kammerer 2012-08-05 21:33:51 UTC
(In reply to comment #19)
> Maxim, as pipacs said, I need to wait for everything to migrate forward. 
> I'm very much on top of things, maybe too much so!  ie Have patience :)

No problem, I just thought that I am missing something obvious that no one mentions explicitly (like, e.g., some pre-release repository of patches). Now that everything is clear, I will apply an interdiff like @pageexec suggested, and test.
Comment 21 Maxim Kammerer 2012-08-05 23:31:50 UTC
Created attachment 320528 [details, diff]
pax patch for hardened-sources-3.4.7 (misses another grsecurity patch)

I tested the interdiff with 128M RAM on both IA32 and x64 OVMF, and it fixes the bug, thanks! Less memory is apparently simply not enough for both OVMF and GRUB, e.g. -- GRUB is unable to load graphics mode in x64 (latest OVMF).

The issue I mentioned in comment #14 wrt. IA32 OVMF is not gone, so will report it in a separate bug.
Comment 22 Maxim Kammerer 2012-08-06 04:03:37 UTC
(In reply to comment #21)
> The issue I mentioned in comment #14 wrt. IA32 OVMF is not gone, so will
> report it in a separate bug.

Created bug #430122.
Comment 23 PaX Team 2012-09-18 09:24:57 UTC
this can be closed now.