From d6309f618cffae0368916092bd760a0275ed22ae6d76557d9daced22d69a63fa Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Fri, 22 Nov 2013 16:39:40 +0000 Subject: [PATCH] Accepting request 207913 from Base:System - add grub2-fix-x86_64-efi-startup-stack-alignment.patch and grub2-fix-x86_64-efi-callwrap-stack-alignment.patch: fix the stack alignment of x86_64 efi. (bnc#841426) (forwarded request 207910 from gary_lin) OBS-URL: https://build.opensuse.org/request/show/207913 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/grub2?expand=0&rev=75 --- ...-x86_64-efi-callwrap-stack-alignment.patch | 146 ++++++++++++++++++ ...x-x86_64-efi-startup-stack-alignment.patch | 33 ++++ grub2.changes | 7 + grub2.spec | 4 + 4 files changed, 190 insertions(+) create mode 100644 grub2-fix-x86_64-efi-callwrap-stack-alignment.patch create mode 100644 grub2-fix-x86_64-efi-startup-stack-alignment.patch diff --git a/grub2-fix-x86_64-efi-callwrap-stack-alignment.patch b/grub2-fix-x86_64-efi-callwrap-stack-alignment.patch new file mode 100644 index 0000000..ba9b2e2 --- /dev/null +++ b/grub2-fix-x86_64-efi-callwrap-stack-alignment.patch @@ -0,0 +1,146 @@ +From 4e42521d8c9232b6ee9eac7d8b4945a7479de781 Mon Sep 17 00:00:00 2001 +From: Vladimir Serbinenko +Date: Fri, 22 Nov 2013 05:40:32 +0100 +Subject: * grub-core/kern/x86_64/efi/callwrap.S: Fix stack + alignment. Previously we misaligned stack by 8 in startup.S and compensated + for it in callwrap.S. According to ABI docs (EFI and sysv amd64) right + behaviour is to align stack in startup.S and keep it aligned in callwrap.S. + startup.S part was committed few commits before. This takes care of + callwrap.S. Reported by: Gary Lin. + +References: bnc#841426 +Patch-Mainline: yes + +Signed-off-by: Gary Ching-Pang Lin +--- + grub-core/kern/x86_64/efi/callwrap.S | 52 ++++++++++++++++++------------------ + 1 file changed, 26 insertions(+), 26 deletions(-) + +diff --git a/grub-core/kern/x86_64/efi/callwrap.S b/grub-core/kern/x86_64/efi/callwrap.S +index 2df95dd..1337fd9 100644 +--- a/grub-core/kern/x86_64/efi/callwrap.S ++++ b/grub-core/kern/x86_64/efi/callwrap.S +@@ -36,94 +36,94 @@ + .text + + FUNCTION(efi_wrap_0) +- subq $48, %rsp ++ subq $40, %rsp + call *%rdi +- addq $48, %rsp ++ addq $40, %rsp + ret + + FUNCTION(efi_wrap_1) +- subq $48, %rsp ++ subq $40, %rsp + mov %rsi, %rcx + call *%rdi +- addq $48, %rsp ++ addq $40, %rsp + ret + + FUNCTION(efi_wrap_2) +- subq $48, %rsp ++ subq $40, %rsp + mov %rsi, %rcx + call *%rdi +- addq $48, %rsp ++ addq $40, %rsp + ret + + FUNCTION(efi_wrap_3) +- subq $48, %rsp ++ subq $40, %rsp + mov %rcx, %r8 + mov %rsi, %rcx + call *%rdi +- addq $48, %rsp ++ addq $40, %rsp + ret + + FUNCTION(efi_wrap_4) +- subq $48, %rsp ++ subq $40, %rsp + mov %r8, %r9 + mov %rcx, %r8 + mov %rsi, %rcx + call *%rdi +- addq $48, %rsp ++ addq $40, %rsp + ret + + FUNCTION(efi_wrap_5) +- subq $48, %rsp ++ subq $40, %rsp + mov %r9, 32(%rsp) + mov %r8, %r9 + mov %rcx, %r8 + mov %rsi, %rcx + call *%rdi +- addq $48, %rsp ++ addq $40, %rsp + ret + + FUNCTION(efi_wrap_6) +- subq $64, %rsp +- mov 64+8(%rsp), %rax ++ subq $56, %rsp ++ mov 56+8(%rsp), %rax + mov %rax, 40(%rsp) + mov %r9, 32(%rsp) + mov %r8, %r9 + mov %rcx, %r8 + mov %rsi, %rcx + call *%rdi +- addq $64, %rsp ++ addq $56, %rsp + ret + + FUNCTION(efi_wrap_7) +- subq $96, %rsp +- mov 96+16(%rsp), %rax ++ subq $88, %rsp ++ mov 88+16(%rsp), %rax + mov %rax, 48(%rsp) +- mov 96+8(%rsp), %rax ++ mov 88+8(%rsp), %rax + mov %rax, 40(%rsp) + mov %r9, 32(%rsp) + mov %r8, %r9 + mov %rcx, %r8 + mov %rsi, %rcx + call *%rdi +- addq $96, %rsp ++ addq $88, %rsp + ret + + FUNCTION(efi_wrap_10) +- subq $96, %rsp +- mov 96+40(%rsp), %rax ++ subq $88, %rsp ++ mov 88+40(%rsp), %rax + mov %rax, 72(%rsp) +- mov 96+32(%rsp), %rax ++ mov 88+32(%rsp), %rax + mov %rax, 64(%rsp) +- mov 96+24(%rsp), %rax ++ mov 88+24(%rsp), %rax + mov %rax, 56(%rsp) +- mov 96+16(%rsp), %rax ++ mov 88+16(%rsp), %rax + mov %rax, 48(%rsp) +- mov 96+8(%rsp), %rax ++ mov 88+8(%rsp), %rax + mov %rax, 40(%rsp) + mov %r9, 32(%rsp) + mov %r8, %r9 + mov %rcx, %r8 + mov %rsi, %rcx + call *%rdi +- addq $96, %rsp ++ addq $88, %rsp + ret +-- +1.8.1.4 + diff --git a/grub2-fix-x86_64-efi-startup-stack-alignment.patch b/grub2-fix-x86_64-efi-startup-stack-alignment.patch new file mode 100644 index 0000000..b9cd317 --- /dev/null +++ b/grub2-fix-x86_64-efi-startup-stack-alignment.patch @@ -0,0 +1,33 @@ +From 7960d3e1823bd3ea569109dcfe269447c3589fac Mon Sep 17 00:00:00 2001 +From: Josh Triplett +Date: Tue, 19 Nov 2013 14:31:40 +0100 +Subject: * grub-core/kern/x86_64/efi/startup.S (_start): Align the + stack to a 16-byte boundary, as required by the x86-64 ABI, before calling + grub_main. In some cases, GCC emits code that assumes this alignment, which + crashes if not aligned. The EFI firmware is also entitled to assume that + stack alignment without checking. + +References: bnc#841426 +Patch-Mainline: yes + +Signed-off-by: Gary Ching-Pang Lin +--- + grub-core/kern/x86_64/efi/startup.S | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/kern/x86_64/efi/startup.S b/grub-core/kern/x86_64/efi/startup.S +index f86f019..9357e5c 100644 +--- a/grub-core/kern/x86_64/efi/startup.S ++++ b/grub-core/kern/x86_64/efi/startup.S +@@ -30,6 +30,6 @@ _start: + movq %rcx, EXT_C(grub_efi_image_handle)(%rip) + movq %rdx, EXT_C(grub_efi_system_table)(%rip) + ++ andq $~0xf, %rsp + call EXT_C(grub_main) +- ret +- ++ /* Doesn't return. */ +-- +1.8.1.4 + diff --git a/grub2.changes b/grub2.changes index 7a93635..840fbca 100644 --- a/grub2.changes +++ b/grub2.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri Nov 22 07:12:16 UTC 2013 - glin@suse.com + +- add grub2-fix-x86_64-efi-startup-stack-alignment.patch and + grub2-fix-x86_64-efi-callwrap-stack-alignment.patch: fix the + stack alignment of x86_64 efi. (bnc#841426) + ------------------------------------------------------------------- Wed Sep 11 07:17:07 UTC 2013 - mchang@suse.com diff --git a/grub2.spec b/grub2.spec index adf0f20..35ea7cd 100644 --- a/grub2.spec +++ b/grub2.spec @@ -132,6 +132,8 @@ Patch34: grub2-secureboot-use-linuxefi-on-uefi-in-os-prober.patch Patch35: grub2-linguas.sh-no-rsync.patch Patch36: grub2-fix-parsing-of-short-LVM-PV-names.patch Patch37: grub2-fix-descriptor-leak-in-grub_util_is_imsm.patch +Patch38: grub2-fix-x86_64-efi-startup-stack-alignment.patch +Patch39: grub2-fix-x86_64-efi-callwrap-stack-alignment.patch Requires: gettext-runtime %if 0%{?suse_version} >= 1140 Requires: os-prober @@ -248,6 +250,8 @@ mv po/grub.pot po/%{name}.pot %patch35 -p1 %patch36 -p1 %patch37 -p1 +%patch38 -p1 +%patch39 -p1 # Generate po/LINGUAS for message catalogs ... ./linguas.sh