Skip to content

Commit 0fddb79

Browse files
MaskRaywilldeacon
authored andcommitted
arm64: lds: move .got section out of .text
Currently, the .got section is placed within the output section .text. However, when .got is non-empty, the SHF_WRITE flag is set for .text when linked by lld. GNU ld recognizes .text as a special section and ignores the SHF_WRITE flag. By renaming .text, we can also get the SHF_WRITE flag. The kernel has performed R_AARCH64_RELATIVE resolving very early, and can then assume that .got is read-only. Let's move .got to the vmlinux_rodata pseudo-segment. As Ard Biesheuvel notes: "This matters to consumers of the vmlinux ELF representation of the kernel image, such as syzkaller, which disregards writable PT_LOAD segments when resolving code symbols. The kernel itself does not care about this distinction, but given that the GOT contains data and not code, it does not require executable permissions, and therefore does not belong in .text to begin with." Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Fangrui Song <maskray@google.com> Link: https://lore.kernel.org/r/20230502074105.1541926-1-maskray@google.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 4df69e0 commit 0fddb79

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

arch/arm64/kernel/vmlinux.lds.S

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,8 @@ SECTIONS
181181
KPROBES_TEXT
182182
HYPERVISOR_TEXT
183183
*(.gnu.warning)
184-
. = ALIGN(16);
185-
*(.got) /* Global offset table */
186184
}
187185

188-
/*
189-
* Make sure that the .got.plt is either completely empty or it
190-
* contains only the lazy dispatch entries.
191-
*/
192-
.got.plt : { *(.got.plt) }
193-
ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
194-
"Unexpected GOT/PLT entries detected!")
195-
196186
. = ALIGN(SEGMENT_ALIGN);
197187
_etext = .; /* End of text section */
198188

@@ -201,6 +191,15 @@ SECTIONS
201191

202192
HYPERVISOR_DATA_SECTIONS
203193

194+
.got : { *(.got) }
195+
/*
196+
* Make sure that the .got.plt is either completely empty or it
197+
* contains only the lazy dispatch entries.
198+
*/
199+
.got.plt : { *(.got.plt) }
200+
ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
201+
"Unexpected GOT/PLT entries detected!")
202+
204203
/* code sections that are never executed via the kernel mapping */
205204
.rodata.text : {
206205
TRAMP_TEXT

0 commit comments

Comments
 (0)