forked from Minki/linux
Split the old READ_IMPLIES_EXEC workaround from executable PT_GNU_STACK
now that toolchains long support PT_GNU_STACK marking and there's no need anymore to force modern programs into having all its user mappings executable instead of only the stack and the PROT_EXEC ones. Disable that automatic READ_IMPLIES_EXEC forcing on x86-64 and arm64. Add tables documenting how READ_IMPLIES_EXEC is handled on x86-64, arm and arm64. By Kees Cook. -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEzv7L6UO9uDPlPSfHEsHwGGHeVUoFAl7YFDIACgkQEsHwGGHe VUpnzxAAmXdODNOb1gGQvt+KJthkfkWh2A2R+tWxCRmFtjFTcS/eRxFfvGu2KmFY 2b2AcJzuJeGjs7WIvQU0pkR2p6STyzuSBBLj5J/OJR9FonQ4pPah38df4A0fOgI6 GJyJV9Ie7O2Ph1w2iLOeWBdmR90CnYuabxsfipgOL+sjHlEI0RqLSDgARRQsxTEj KM+JVAFD472KcUJnQKBVBOD1I1DOVBGu12r3y6chgsOtwshLNW/cO15cDgYrgnJZ OlR3EIUukCEEc1KQzUCihsypLuGfrmdq1MyPN8CME8gLfmOBsJyGRDhvmdbS+Wxh kAMYQ9BuNP/jMVtN950qV0qUtnZCeIPlj1sDb9STWz5fInLsXDSCS0eYi32yBFi+ 7yviVU95ml6Mda1Qd5axItTHFAjKIn0qfMZszkLOtUszIzNinCgH7t3ThoXeV223 BqrpntRwiGZVpXDdcp0QFYBsWSMchR47yuhL8pB4SWxQzgNzXqAEg2KFQU0XMDKp pdia9IzUozg/BrjG5cnRfZhq2lBra7fy3Dn6fw5+NR5vqhka0Wr8L6dyM1Rj74EU HPk5bRXgt0OIiIFPi4139ApY7k+8j2nbf12qUchue1ZVVKzbvK996FDXbrGgW3zD Wis1wglxB9urSUTmC1bMOeyOd+gebo3i/ACAjgSo+EbDN7qW0Qw= =2L7y -----END PGP SIGNATURE----- Merge tag 'core_core_updates_for_5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull READ_IMPLIES_EXEC changes from Borislav Petkov: "Split the old READ_IMPLIES_EXEC workaround from executable PT_GNU_STACK now that toolchains long support PT_GNU_STACK marking and there's no need anymore to force modern programs into having all its user mappings executable instead of only the stack and the PROT_EXEC ones. Disable that automatic READ_IMPLIES_EXEC forcing on x86-64 and arm64. Add tables documenting how READ_IMPLIES_EXEC is handled on x86-64, arm and arm64. By Kees Cook" * tag 'core_core_updates_for_5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: arm64/elf: Disable automatic READ_IMPLIES_EXEC for 64-bit address spaces arm32/64/elf: Split READ_IMPLIES_EXEC from executable PT_GNU_STACK arm32/64/elf: Add tables to document READ_IMPLIES_EXEC x86/elf: Disable automatic READ_IMPLIES_EXEC on 64-bit x86/elf: Split READ_IMPLIES_EXEC from executable PT_GNU_STACK x86/elf: Add table to document READ_IMPLIES_EXEC
This commit is contained in:
commit
ac7b34218a
@ -78,13 +78,32 @@ void elf_set_personality(const struct elf32_hdr *x)
|
||||
EXPORT_SYMBOL(elf_set_personality);
|
||||
|
||||
/*
|
||||
* Set READ_IMPLIES_EXEC if:
|
||||
* - the binary requires an executable stack
|
||||
* - we're running on a CPU which doesn't support NX.
|
||||
* An executable for which elf_read_implies_exec() returns TRUE will
|
||||
* have the READ_IMPLIES_EXEC personality flag set automatically.
|
||||
*
|
||||
* The decision process for determining the results are:
|
||||
*
|
||||
* CPU: | lacks NX* | has NX |
|
||||
* ELF: | | |
|
||||
* ---------------------|------------|------------|
|
||||
* missing PT_GNU_STACK | exec-all | exec-all |
|
||||
* PT_GNU_STACK == RWX | exec-all | exec-stack |
|
||||
* PT_GNU_STACK == RW | exec-all | exec-none |
|
||||
*
|
||||
* exec-all : all PROT_READ user mappings are executable, except when
|
||||
* backed by files on a noexec-filesystem.
|
||||
* exec-none : only PROT_EXEC user mappings are executable.
|
||||
* exec-stack: only the stack and PROT_EXEC user mappings are executable.
|
||||
*
|
||||
* *this column has no architectural effect: NX markings are ignored by
|
||||
* hardware, but may have behavioral effects when "wants X" collides with
|
||||
* "cannot be X" constraints in memory permission flags, as in
|
||||
* https://lkml.kernel.org/r/20190418055759.GA3155@mellanox.com
|
||||
*
|
||||
*/
|
||||
int arm_elf_read_implies_exec(int executable_stack)
|
||||
{
|
||||
if (executable_stack != EXSTACK_DISABLE_X)
|
||||
if (executable_stack == EXSTACK_DEFAULT)
|
||||
return 1;
|
||||
if (cpu_architecture() < CPU_ARCH_ARMv6)
|
||||
return 1;
|
||||
|
@ -96,7 +96,28 @@
|
||||
*/
|
||||
#define elf_check_arch(x) ((x)->e_machine == EM_AARCH64)
|
||||
|
||||
#define elf_read_implies_exec(ex,stk) (stk != EXSTACK_DISABLE_X)
|
||||
/*
|
||||
* An executable for which elf_read_implies_exec() returns TRUE will
|
||||
* have the READ_IMPLIES_EXEC personality flag set automatically.
|
||||
*
|
||||
* The decision process for determining the results are:
|
||||
*
|
||||
* CPU*: | arm32 | arm64 |
|
||||
* ELF: | | |
|
||||
* ---------------------|------------|------------|
|
||||
* missing PT_GNU_STACK | exec-all | exec-none |
|
||||
* PT_GNU_STACK == RWX | exec-stack | exec-stack |
|
||||
* PT_GNU_STACK == RW | exec-none | exec-none |
|
||||
*
|
||||
* exec-all : all PROT_READ user mappings are executable, except when
|
||||
* backed by files on a noexec-filesystem.
|
||||
* exec-none : only PROT_EXEC user mappings are executable.
|
||||
* exec-stack: only the stack and PROT_EXEC user mappings are executable.
|
||||
*
|
||||
* *all arm64 CPUs support NX, so there is no "lacks NX" column.
|
||||
*
|
||||
*/
|
||||
#define compat_elf_read_implies_exec(ex, stk) (stk == EXSTACK_DEFAULT)
|
||||
|
||||
#define CORE_DUMP_USE_REGSET
|
||||
#define ELF_EXEC_PAGESIZE PAGE_SIZE
|
||||
|
@ -281,9 +281,29 @@ extern u32 elf_hwcap2;
|
||||
/*
|
||||
* An executable for which elf_read_implies_exec() returns TRUE will
|
||||
* have the READ_IMPLIES_EXEC personality flag set automatically.
|
||||
*
|
||||
* The decision process for determining the results are:
|
||||
*
|
||||
* CPU: | lacks NX* | has NX, ia32 | has NX, x86_64 |
|
||||
* ELF: | | | |
|
||||
* ---------------------|------------|------------------|----------------|
|
||||
* missing PT_GNU_STACK | exec-all | exec-all | exec-none |
|
||||
* PT_GNU_STACK == RWX | exec-stack | exec-stack | exec-stack |
|
||||
* PT_GNU_STACK == RW | exec-none | exec-none | exec-none |
|
||||
*
|
||||
* exec-all : all PROT_READ user mappings are executable, except when
|
||||
* backed by files on a noexec-filesystem.
|
||||
* exec-none : only PROT_EXEC user mappings are executable.
|
||||
* exec-stack: only the stack and PROT_EXEC user mappings are executable.
|
||||
*
|
||||
* *this column has no architectural effect: NX markings are ignored by
|
||||
* hardware, but may have behavioral effects when "wants X" collides with
|
||||
* "cannot be X" constraints in memory permission flags, as in
|
||||
* https://lkml.kernel.org/r/20190418055759.GA3155@mellanox.com
|
||||
*
|
||||
*/
|
||||
#define elf_read_implies_exec(ex, executable_stack) \
|
||||
(executable_stack != EXSTACK_DISABLE_X)
|
||||
(mmap_is_ia32() && executable_stack == EXSTACK_DEFAULT)
|
||||
|
||||
struct task_struct;
|
||||
|
||||
|
@ -117,6 +117,11 @@
|
||||
#define arch_setup_additional_pages compat_arch_setup_additional_pages
|
||||
#endif
|
||||
|
||||
#ifdef compat_elf_read_implies_exec
|
||||
#undef elf_read_implies_exec
|
||||
#define elf_read_implies_exec compat_elf_read_implies_exec
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Rename a few of the symbols that binfmt_elf.c will define.
|
||||
* These are all local so the names don't really matter, but it
|
||||
|
Loading…
Reference in New Issue
Block a user