]> git.baikalelectronics.ru Git - kernel.git/commit
elf: don't use MAP_FIXED_NOREPLACE for elf executable mappings
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 6 Oct 2019 20:53:27 +0000 (13:53 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 6 Oct 2019 20:53:27 +0000 (13:53 -0700)
commite5e9f70945f4a8e9b58c9702065834e657a9b0f8
tree8f937df8b01f1ea7e13bf8bb87d6ca26190e5b56
parentb8a31b17c7c9d03803f542e7d1f06b92ecabdbf4
elf: don't use MAP_FIXED_NOREPLACE for elf executable mappings

In commit d03c58df02c8 ("fs, elf: drop MAP_FIXED usage from elf_map") we
changed elf to use MAP_FIXED_NOREPLACE instead of MAP_FIXED for the
executable mappings.

Then, people reported that it broke some binaries that had overlapping
segments from the same file, and commit c15489ee1c9c ("elf: enforce
MAP_FIXED on overlaying elf segments") re-instated MAP_FIXED for some
overlaying elf segment cases.  But only some - despite the summary line
of that commit, it only did it when it also does a temporary brk vma for
one obvious overlapping case.

Now Russell King reports another overlapping case with old 32-bit x86
binaries, which doesn't trigger that limited case.  End result: we had
better just drop MAP_FIXED_NOREPLACE entirely, and go back to MAP_FIXED.

Yes, it's a sign of old binaries generated with old tool-chains, but we
do pride ourselves on not breaking existing setups.

This still leaves MAP_FIXED_NOREPLACE in place for the load_elf_interp()
and the old load_elf_library() use-cases, because nobody has reported
breakage for those. Yet.

Note that in all the cases seen so far, the overlapping elf sections
seem to be just re-mapping of the same executable with different section
attributes.  We could possibly introduce a new MAP_FIXED_NOFILECHANGE
flag or similar, which acts like NOREPLACE, but allows just remapping
the same executable file using different protection flags.

It's not clear that would make a huge difference to anything, but if
people really hate that "elf remaps over previous maps" behavior, maybe
at least a more limited form of remapping would alleviate some concerns.

Alternatively, we should take a look at our elf_map() logic to see if we
end up not mapping things properly the first time.

In the meantime, this is the minimal "don't do that then" patch while
people hopefully think about it more.

Reported-by: Russell King <linux@armlinux.org.uk>
Fixes: d03c58df02c8 ("fs, elf: drop MAP_FIXED usage from elf_map")
Fixes: c15489ee1c9c ("elf: enforce MAP_FIXED on overlaying elf segments")
Cc: Michal Hocko <mhocko@suse.com>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/binfmt_elf.c