Lorenz Brun | 50d3937 | 2023-03-27 22:20:15 +0200 | [diff] [blame^] | 1 | From c2b13908b9d655bf9a2baab256a8aaffa6e11565 Mon Sep 17 00:00:00 2001 |
Lorenz Brun | 942f5e2 | 2022-01-27 15:03:10 +0100 | [diff] [blame] | 2 | From: "H.J. Lu" <hjl.tools@gmail.com> |
| 3 | Date: Mon, 27 Apr 2020 18:49:00 -0700 |
| 4 | Subject: [PATCH] Discard .note.gnu.property sections in generic NOTES |
| 5 | |
| 6 | With the command-line option, -mx86-used-note=yes, the x86 assembler |
| 7 | in binutils 2.32 and above generates a program property note in a note |
| 8 | section, .note.gnu.property, to encode used x86 ISAs and features. But |
| 9 | kernel linker script only contains a single NOTE segment: |
| 10 | |
| 11 | PHDRS { |
| 12 | text PT_LOAD FLAGS(5); |
| 13 | data PT_LOAD FLAGS(6); |
| 14 | percpu PT_LOAD FLAGS(6); |
| 15 | init PT_LOAD FLAGS(7); |
| 16 | note PT_NOTE FLAGS(0); |
| 17 | } |
| 18 | SECTIONS |
| 19 | { |
| 20 | ... |
| 21 | .notes : AT(ADDR(.notes) - 0xffffffff80000000) { __start_notes = .; KEEP(*(.not |
| 22 | e.*)) __stop_notes = .; } :text :note |
| 23 | ... |
| 24 | } |
| 25 | |
| 26 | The NOTE segment generated by kernel linker script is aligned to 4 bytes. |
| 27 | But .note.gnu.property section must be aligned to 8 bytes on x86-64 and |
| 28 | we get |
| 29 | |
| 30 | [hjl@gnu-skx-1 linux]$ readelf -n vmlinux |
| 31 | |
| 32 | Displaying notes found in: .notes |
| 33 | Owner Data size Description |
| 34 | Xen 0x00000006 Unknown note type: (0x00000006) |
| 35 | description data: 6c 69 6e 75 78 00 |
| 36 | Xen 0x00000004 Unknown note type: (0x00000007) |
| 37 | description data: 32 2e 36 00 |
| 38 | xen-3.0 0x00000005 Unknown note type: (0x006e6558) |
| 39 | description data: 08 00 00 00 03 |
| 40 | readelf: Warning: note with invalid namesz and/or descsz found at offset 0x50 |
| 41 | readelf: Warning: type: 0xffffffff, namesize: 0x006e6558, descsize: |
| 42 | 0x80000000, alignment: 8 |
| 43 | [hjl@gnu-skx-1 linux]$ |
| 44 | |
| 45 | Since note.gnu.property section in kernel image is never used, this patch |
| 46 | discards .note.gnu.property sections in kernel linker script by adding |
| 47 | |
| 48 | /DISCARD/ : { |
| 49 | *(.note.gnu.property) |
| 50 | } |
| 51 | |
| 52 | before kernel NOTE segment in generic NOTES. |
| 53 | |
| 54 | Signed-off-by: H.J. Lu <hjl.tools@gmail.com> |
| 55 | Reviewed-by: Kees Cook <keescook@chromium.org> |
| 56 | Rebased-by: Lorenz Brun <lorenz@monogon.tech> |
| 57 | --- |
Lorenz Brun | 50d3937 | 2023-03-27 22:20:15 +0200 | [diff] [blame^] | 58 | include/asm-generic/vmlinux.lds.h | 7 ++++++- |
| 59 | 1 file changed, 6 insertions(+), 1 deletion(-) |
Lorenz Brun | 942f5e2 | 2022-01-27 15:03:10 +0100 | [diff] [blame] | 60 | |
| 61 | diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h |
Lorenz Brun | 50d3937 | 2023-03-27 22:20:15 +0200 | [diff] [blame^] | 62 | index 8471717c5085..15c74f9a2999 100644 |
Lorenz Brun | 942f5e2 | 2022-01-27 15:03:10 +0100 | [diff] [blame] | 63 | --- a/include/asm-generic/vmlinux.lds.h |
| 64 | +++ b/include/asm-generic/vmlinux.lds.h |
Lorenz Brun | 50d3937 | 2023-03-27 22:20:15 +0200 | [diff] [blame^] | 65 | @@ -906,9 +906,14 @@ |
| 66 | /* |
| 67 | * Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler. |
| 68 | * Otherwise, the type of .notes section would become PROGBITS instead of NOTES. |
Lorenz Brun | 942f5e2 | 2022-01-27 15:03:10 +0100 | [diff] [blame] | 69 | + * Discard .note.gnu.property sections which are unused and have |
| 70 | + * different alignment requirement from kernel note sections. |
Lorenz Brun | 50d3937 | 2023-03-27 22:20:15 +0200 | [diff] [blame^] | 71 | */ |
Lorenz Brun | 942f5e2 | 2022-01-27 15:03:10 +0100 | [diff] [blame] | 72 | #define NOTES \ |
Lorenz Brun | 50d3937 | 2023-03-27 22:20:15 +0200 | [diff] [blame^] | 73 | - /DISCARD/ : { *(.note.GNU-stack) } \ |
| 74 | + /DISCARD/ : { \ |
| 75 | + *(.note.GNU-stack) \ |
Lorenz Brun | 942f5e2 | 2022-01-27 15:03:10 +0100 | [diff] [blame] | 76 | + *(.note.gnu.property) \ |
Lorenz Brun | 50d3937 | 2023-03-27 22:20:15 +0200 | [diff] [blame^] | 77 | + } \ |
Lorenz Brun | 942f5e2 | 2022-01-27 15:03:10 +0100 | [diff] [blame] | 78 | .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \ |
| 79 | __start_notes = .; \ |
| 80 | KEEP(*(.note.*)) \ |
| 81 | -- |
Lorenz Brun | 50d3937 | 2023-03-27 22:20:15 +0200 | [diff] [blame^] | 82 | 2.39.2 |
Lorenz Brun | 942f5e2 | 2022-01-27 15:03:10 +0100 | [diff] [blame] | 83 | |