]> git.baikalelectronics.ru Git - kernel.git/commit
elf: don't use MAP_FIXED_NOREPLACE for elf interpreter mappings
authorChen Jingwen <chenjingwen6@huawei.com>
Tue, 28 Sep 2021 12:56:57 +0000 (20:56 +0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 3 Oct 2021 21:02:58 +0000 (14:02 -0700)
commit4cdccdee73812719edbc5e55b3da0e23e6fb3715
tree9e30efdd8e3aad3ca9fc8dad90ba79f8630a6241
parentc3948859f81e7b85d7b7261e80e4b3c6df0caa63
elf: don't use MAP_FIXED_NOREPLACE for elf interpreter mappings

In commit 9dd7ec872d62 ("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
f6d1f92c6b06 ("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: 551923430331 ("fs, elf: drop MAP_FIXED usage from elf_map")
Cc: <stable@vger.kernel.org> # v4.19
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: Chen Jingwen <chenjingwen6@huawei.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/binfmt_elf.c