Skip to contentSkip to conversation

fs: binfmt_elf_efpic: don't use missing interpreter's properties

PATCH Applied Max Filippov 2 participants 3 messages Jan 18, 2024 – Feb 5, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: binfmt_elf_efpic: don't use missing interpreter's properties

Static FDPIC executable may get an executable stack even when it has non-executable GNU_STACK segment. This happens when STACK segment has rw permissions, but does not specify stack size. In that case FDPIC loader uses permissions of the interpreter's stack, and for static executables with no interpreter it results in choosing the arch-default permissions for the stack.

Fix that by using the interpreter's properties only when the interpreter is actually used.

---
 fs/binfmt_elf_fdpic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/binfmt_elf_fdpic.c +1 -1
index be4e7ac3efbc..f6d72fe3998c 100644
@@ -322,7 +322,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
 	else
 		executable_stack = EXSTACK_DEFAULT;
 
-	if (stack_size == 0) {
+	if (stack_size == 0 && interp_params.flags & ELF_FDPIC_FLAG_PRESENT) {
 		stack_size = interp_params.stack_size;
 		if (interp_params.flags & ELF_FDPIC_FLAG_EXEC_STACK)
 			executable_stack = EXSTACK_ENABLE_X;
Signature · 1 line
2.39.2
#1 lore raw

Ping?

Quoted 32 lines · Max Filippov

Static FDPIC executable may get an executable stack even when it has non-executable GNU_STACK segment. This happens when STACK segment has rw permissions, but does not specify stack size. In that case FDPIC loader uses permissions of the interpreter's stack, and for static executables with no interpreter it results in choosing the arch-default permissions for the stack.

Fix that by using the interpreter's properties only when the interpreter is actually used.

---
 fs/binfmt_elf_fdpic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/binfmt_elf_fdpic.c +1 -2
index be4e7ac3efbc..f6d72fe3998c 100644
@@ -322,7 +322,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
        else
                executable_stack = EXSTACK_DEFAULT;
 
-       if (stack_size == 0) {
+       if (stack_size == 0 && interp_params.flags & ELF_FDPIC_FLAG_PRESENT) {
                stack_size = interp_params.stack_size;
                if (interp_params.flags & ELF_FDPIC_FLAG_EXEC_STACK)
                        executable_stack = EXSTACK_ENABLE_X;
--

2.39.2

Signature · 2 lines
Thanks.
-- Max
Applied
#2 lore raw
In reply to Max Filippov
Quoted 8 lines · Max Filippov

Static FDPIC executable may get an executable stack even when it has non-executable GNU_STACK segment. This happens when STACK segment has rw permissions, but does not specify stack size. In that case FDPIC loader uses permissions of the interpreter's stack, and for static executables with no interpreter it results in choosing the arch-default permissions for the stack.

[...]

Applied to for-next/execve, thanks!

[1/1] fs: binfmt_elf_efpic: don't use missing interpreter's properties

      https://git.kernel.org/kees/c/15fd1dc3dadb

Take care,

Signature · 1 line
Kees Cook