Page MenuHomeFreeBSD

D22379.id64363.diff
No OneTemporary

D22379.id64363.diff

Index: sys/kern/kern_exec.c
===================================================================
--- sys/kern/kern_exec.c
+++ sys/kern/kern_exec.c
@@ -361,7 +361,6 @@
struct ucred *oldcred;
struct uidinfo *euip = NULL;
register_t *stack_base;
- int error, i;
struct image_params image_params, *imgp;
struct vattr attr;
int (*img_first)(struct image_params *);
@@ -380,6 +379,8 @@
#ifdef HWPMC_HOOKS
struct pmckern_procexec pe;
#endif
+ int error, i, orig_osrel;
+ uint32_t orig_fctl0;
static const char fexecv_proc_title[] = "(fexecv)";
imgp = &image_params;
@@ -397,6 +398,9 @@
p->p_flag |= P_INEXEC;
PROC_UNLOCK(p);
+ orig_osrel = imgp->proc->p_osrel;
+ orig_fctl0 = imgp->proc->p_fctl0;
+
/*
* Initialize part of the common data
*/
@@ -868,6 +872,11 @@
SDT_PROBE1(proc, , , exec__success, args->fname);
exec_fail_dealloc:
+ if (error != 0) {
+ imgp->proc->p_osrel = orig_osrel;
+ imgp->proc->p_fctl0 = orig_fctl0;
+ }
+
if (imgp->firstpage != NULL)
exec_unmap_first_page(imgp);
Index: sys/sys/elf_common.h
===================================================================
--- sys/sys/elf_common.h
+++ sys/sys/elf_common.h
@@ -784,6 +784,7 @@
/* NT_FREEBSD_FEATURE_CTL desc[0] bits */
#define NT_FREEBSD_FCTL_ASLR_DISABLE 0x00000001
#define NT_FREEBSD_FCTL_PROTMAX_DISABLE 0x00000002
+#define NT_FREEBSD_FCTL_STKGAP_DISABLE 0x00000004
/* Values for n_type. Used in core files. */
#define NT_PRSTATUS 1 /* Process status. */
Index: sys/vm/vm_map.c
===================================================================
--- sys/vm/vm_map.c
+++ sys/vm/vm_map.c
@@ -69,6 +69,7 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/elf.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
@@ -4137,7 +4138,8 @@
addrbos + max_ssize > vm_map_max(map) ||
addrbos + max_ssize <= addrbos)
return (KERN_INVALID_ADDRESS);
- sgp = (curproc->p_flag2 & P2_STKGAP_DISABLE) != 0 ? 0 :
+ sgp = ((curproc->p_flag2 & P2_STKGAP_DISABLE) != 0 ||
+ (curproc->p_fctl0 & NT_FREEBSD_FCTL_STKGAP_DISABLE) != 0) ? 0 :
(vm_size_t)stack_guard_page * PAGE_SIZE;
if (sgp >= max_ssize)
return (KERN_INVALID_ARGUMENT);
@@ -4274,7 +4276,8 @@
} else {
return (KERN_FAILURE);
}
- guard = (curproc->p_flag2 & P2_STKGAP_DISABLE) != 0 ? 0 :
+ guard = ((curproc->p_flag2 & P2_STKGAP_DISABLE) != 0 ||
+ (curproc->p_fctl0 & NT_FREEBSD_FCTL_STKGAP_DISABLE) != 0) ? 0 :
gap_entry->next_read;
max_grow = gap_entry->end - gap_entry->start;
if (guard > max_grow)
Index: tools/tools/controlelf/controlelf.c
===================================================================
--- tools/tools/controlelf/controlelf.c
+++ tools/tools/controlelf/controlelf.c
@@ -63,7 +63,9 @@
static struct ControlFeatures featurelist[] = {
{ "aslr", NT_FREEBSD_FCTL_ASLR_DISABLE, "Disable ASLR" },
- { "protmax", NT_FREEBSD_FCTL_PROTMAX_DISABLE,"Disable implicit PROT_MAX" },
+ { "protmax", NT_FREEBSD_FCTL_PROTMAX_DISABLE,
+ "Disable implicit PROT_MAX" },
+ { "stackgap", NT_FREEBSD_FCTL_STKGAP_DISABLE, "Disable stack gap" },
};
static struct option long_opts[] = {

File Metadata

Mime Type
text/plain
Expires
Wed, Apr 29, 7:16 PM (14 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32380365
Default Alt Text
D22379.id64363.diff (3 KB)

Event Timeline