Skip to content

Commit 9b2f72c

Browse files
Chen Jingwentorvalds
authored andcommitted
elf: don't use MAP_FIXED_NOREPLACE for elf interpreter mappings
In commit b212921 ("elf: don't use MAP_FIXED_NOREPLACE for elf executable mappings") we still leave MAP_FIXED_NOREPLACE in place for load_elf_interp. Unfortunately, this will cause kernel to fail to start with: 1 (init): Uhuuh, elf segment at 00003ffff7ffd000 requested but the memory is mapped already Failed to execute /init (error -17) The reason is that the elf interpreter (ld.so) has overlapping segments. readelf -l ld-2.31.so Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x000000000002c94c 0x000000000002c94c R E 0x10000 LOAD 0x000000000002dae0 0x000000000003dae0 0x000000000003dae0 0x00000000000021e8 0x0000000000002320 RW 0x10000 LOAD 0x000000000002fe00 0x000000000003fe00 0x000000000003fe00 0x00000000000011ac 0x0000000000001328 RW 0x10000 The reason for this problem is the same as described in commit ad55eac ("elf: enforce MAP_FIXED on overlaying elf segments"). Not only executable binaries, elf interpreters (e.g. ld.so) can have overlapping elf segments, so we better drop MAP_FIXED_NOREPLACE and go back to MAP_FIXED in load_elf_interp. Fixes: 4ed2863 ("fs, elf: drop MAP_FIXED usage from elf_map") Cc: <[email protected]> # v4.19 Cc: Andrew Morton <[email protected]> Cc: Michal Hocko <[email protected]> Signed-off-by: Chen Jingwen <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ca3cef4 commit 9b2f72c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/binfmt_elf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
630630

631631
vaddr = eppnt->p_vaddr;
632632
if (interp_elf_ex->e_type == ET_EXEC || load_addr_set)
633-
elf_type |= MAP_FIXED_NOREPLACE;
633+
elf_type |= MAP_FIXED;
634634
else if (no_base && interp_elf_ex->e_type == ET_DYN)
635635
load_addr = -vaddr;
636636

0 commit comments

Comments
 (0)