This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BACKPORT: 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. This patch is needed to fix softlock up observed during stress test. Backport from: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.8-rc1&id=ac7b34218a0021bafd1d4c11c54217b930f516b0 Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Tuan Phan <[email protected]>
- Loading branch information
1 parent
cb4b1ac
commit d6f5dfc
Showing
4 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected] | ||
* | ||
*/ | ||
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,9 +282,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/[email protected] | ||
* | ||
*/ | ||
#define elf_read_implies_exec(ex, executable_stack) \ | ||
(executable_stack != EXSTACK_DISABLE_X) | ||
(mmap_is_ia32() && executable_stack == EXSTACK_DEFAULT) | ||
|
||
struct task_struct; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters