From fbafa98a94cc7f4f30d71003c230d1b5d4c5960b Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Fri, 18 Mar 2022 13:56:32 -0400 Subject: [PATCH] Disallow invalid PT_GNU_STACK Stack must be at least readable and writable. PR: 242570 Reviewed by: kib, markj MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35867 --- sys/kern/imgact_elf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 38be7d100ae9..6c36c880a2c0 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1221,9 +1221,16 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) goto ret; break; case PT_GNU_STACK: - if (__elfN(nxstack)) + if (__elfN(nxstack)) { imgp->stack_prot = __elfN(trans_prot)(phdr[i].p_flags); + if ((imgp->stack_prot & VM_PROT_RW) != + VM_PROT_RW) { + uprintf("Invalid PT_GNU_STACK\n"); + error = ENOEXEC; + goto ret; + } + } imgp->stack_sz = phdr[i].p_memsz; break; case PT_PHDR: /* Program header table info */