[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 02/10] exec: Fix creating executable stacks
From: |
Sergey Bugaev |
Subject: |
[PATCH 02/10] exec: Fix creating executable stacks |
Date: |
Sat, 23 Mar 2024 14:53:14 +0300 |
The previous logic had two independent issues:
* We need to make the stack executable if either the program or its ELF
interpreter requires executable stack. In practice, it's common for
the program itself to not require executable stack, but ld.so (glibc)
needs it.
* mach_setup_thread () allocates stacks with a simple vm_allocate (),
which creates non-executable memory. So if an executable stack is
required, the stack has to be vm_protect'ed to enable execution, not
the other way around. As the comment suggest, it would've been better
to use vm_map () with the desired protection directly.
---
exec/exec.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/exec/exec.c b/exec/exec.c
index 639564cb..f6788520 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -1335,11 +1335,12 @@ do_exec (file_t file,
if (e.error)
goto out;
- /* It would probably be better to change mach_setup_thread so
- it does a vm_map with the right permissions to start with. */
- if (!e.info.elf.execstack)
+ /* mach_setup_thread () creates non-executable stacks (with vm_allocate ()).
+ It would probably be better to change mach_setup_thread () so it does
+ a vm_map () with the right permissions to start with. */
+ if (e.info.elf.execstack || (e.interp.section && interp.info.elf.execstack))
e.error = vm_protect (newtask, boot->stack_base, boot->stack_size,
- 0, VM_PROT_READ | VM_PROT_WRITE);
+ 0, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
if (oldtask != newtask && oldtask != MACH_PORT_NULL)
{
--
2.44.0
- [PATCH 01/10] term: Fix function prototype, Sergey Bugaev, 2024/03/23
- [PATCH 02/10] exec: Fix creating executable stacks,
Sergey Bugaev <=
- [PATCH 04/10] proc: Only try host_kernel_version () on i386, Sergey Bugaev, 2024/03/23
- [PATCH 05/10] libshouldbeinlibc: Stop relying on address space size, Sergey Bugaev, 2024/03/23
- [PATCH 03/10] Make long & friends 64-bit on 64-bit platforms, Sergey Bugaev, 2024/03/23
- [PATCH 06/10] exec: Stop relying on address space size, Sergey Bugaev, 2024/03/23
- [PATCH 09/10] proc: Add support for AArch64 in uname, Sergey Bugaev, 2024/03/23
- [PATCH 07/10] exec: Add support for AArch64 executables, Sergey Bugaev, 2024/03/23
- [PATCH 10/10] boot: Add support for AArch64, Sergey Bugaev, 2024/03/23
- [PATCH 08/10] elfcore: Add support for saving AArch64 registers, Sergey Bugaev, 2024/03/23
- Re: [PATCH 01/10] term: Fix function prototype, Samuel Thibault, 2024/03/23