Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Jan 2011 16:30:59 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r217152 - head/sys/kern
Message-ID:  <201101081630.p08GUxOC097391@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Jan  8 16:30:59 2011
New Revision: 217152
URL: http://svn.freebsd.org/changeset/base/217152

Log:
  In elf image activator, read and apply the stack protection mode from
  PT_GNU_STACK program header, if present and enabled. Two new sysctls
  are provided, kern.elf32.nxstack and kern.elf64.nxstack, that allow to
  enable PT_GNU_STACK for ABIs of specified bitsize, if ABI decided to
  support shared page.
  
  Inform rtld about access mode of the stack initial mapping by
  AT_STACKPROT aux vector.
  
  At the moment, the default is disabled, waiting for the usermode
  support bits.

Modified:
  head/sys/kern/imgact_elf.c

Modified: head/sys/kern/imgact_elf.c
==============================================================================
--- head/sys/kern/imgact_elf.c	Sat Jan  8 16:13:44 2011	(r217151)
+++ head/sys/kern/imgact_elf.c	Sat Jan  8 16:30:59 2011	(r217152)
@@ -115,6 +115,11 @@ static int elf_legacy_coredump = 0;
 SYSCTL_INT(_debug, OID_AUTO, __elfN(legacy_coredump), CTLFLAG_RW, 
     &elf_legacy_coredump, 0, "");
 
+static int __elfN(nxstack) = 0;
+SYSCTL_INT(__CONCAT(_kern_elf, __ELF_WORD_SIZE), OID_AUTO,
+    nxstack, CTLFLAG_RW, &__elfN(nxstack), 0,
+    __XSTRING(__CONCAT(ELF, __ELF_WORD_SIZE)) ": enable non-executable stack");
+
 static Elf_Brandinfo *elf_brand_list[MAX_BRANDS];
 
 #define	trunc_page_ps(va, ps)	((va) & ~(ps - 1))
@@ -724,19 +729,24 @@ __CONCAT(exec_, __elfN(imgact))(struct i
 	n = 0;
 	baddr = 0;
 	for (i = 0; i < hdr->e_phnum; i++) {
-		if (phdr[i].p_type == PT_LOAD) {
+		switch (phdr[i].p_type) {
+		case PT_LOAD:
 			if (n == 0)
 				baddr = phdr[i].p_vaddr;
 			n++;
-			continue;
-		}
-		if (phdr[i].p_type == PT_INTERP) {
+			break;
+		case PT_INTERP:
 			/* Path to interpreter */
 			if (phdr[i].p_filesz > MAXPATHLEN ||
 			    phdr[i].p_offset + phdr[i].p_filesz > PAGE_SIZE)
 				return (ENOEXEC);
 			interp = imgp->image_header + phdr[i].p_offset;
-			continue;
+			break;
+		case PT_GNU_STACK:
+			if (__elfN(nxstack))
+				imgp->stack_prot =
+				    __elfN(trans_prot)(phdr[i].p_flags);
+			break;
 		}
 	}
 
@@ -972,6 +982,8 @@ __elfN(freebsd_fixup)(register_t **stack
 		AUXARGS_ENTRY(pos, AT_PAGESIZES, imgp->pagesizes);
 		AUXARGS_ENTRY(pos, AT_PAGESIZESLEN, imgp->pagesizeslen);
 	}
+	AUXARGS_ENTRY(pos, AT_STACKPROT, imgp->stack_prot != 0 ?
+	    imgp->stack_prot : imgp->sysent->sv_stackprot);
 	AUXARGS_ENTRY(pos, AT_NULL, 0);
 
 	free(imgp->auxargs, M_TEMP);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101081630.p08GUxOC097391>