1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-25 07:49:18 +00:00

exec: Remove the stack gap implementation

ASLR stack randomization will reappear in a forthcoming commit.  Rather
than inserting a random gap into the stack mapping, the entire stack
mapping itself will be randomized in the same way that other mappings
are when ASLR is enabled.

No functional change intended, as the stack gap implementation is
currently disabled by default.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
This commit is contained in:
Mark Johnston 2022-01-17 11:42:46 -05:00
parent 706f4a81a8
commit 758d98debe
12 changed files with 1 additions and 53 deletions

View File

@ -3755,7 +3755,6 @@ static struct flag_desc note_feature_ctl_flags[] = {
{ NT_FREEBSD_FCTL_STKGAP_DISABLE, "STKGAP_DISABLE" },
{ NT_FREEBSD_FCTL_WXNEEDED, "WXNEEDED" },
{ NT_FREEBSD_FCTL_LA48, "LA48" },
{ NT_FREEBSD_FCTL_ASG_DISABLE, "ASG_DISABLE" },
{ 0, NULL }
};

View File

@ -92,7 +92,6 @@ struct sysentvec elf64_freebsd_sysvec_la48 = {
.sv_schedtail = NULL,
.sv_thread_detach = NULL,
.sv_trap = NULL,
.sv_stackgap = elf64_stackgap,
.sv_onexec_old = exec_onexec_old,
.sv_onexit = exit_onexit,
.sv_set_fork_retval = x86_set_fork_retval,
@ -135,7 +134,6 @@ struct sysentvec elf64_freebsd_sysvec_la57 = {
.sv_schedtail = NULL,
.sv_thread_detach = NULL,
.sv_trap = NULL,
.sv_stackgap = elf64_stackgap,
.sv_onexec_old = exec_onexec_old,
.sv_onexit = exit_onexit,
.sv_set_fork_retval= x86_set_fork_retval,

View File

@ -94,7 +94,6 @@ static struct sysentvec elf64_freebsd_sysvec = {
.sv_schedtail = NULL,
.sv_thread_detach = NULL,
.sv_trap = NULL,
.sv_stackgap = elf64_stackgap,
.sv_hwcap = &elf_hwcap,
.sv_hwcap2 = &elf_hwcap2,
.sv_onexec_old = exec_onexec_old,

View File

@ -3464,8 +3464,6 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
destp = rounddown2(destp, sizeof(uint32_t));
ustringp = destp;
exec_stackgap(imgp, &destp);
if (imgp->auxargs) {
/*
* Allocate room on the stack for the ELF auxargs

View File

@ -138,7 +138,6 @@ struct sysentvec ia32_freebsd_sysvec = {
.sv_schedtail = NULL,
.sv_thread_detach = NULL,
.sv_trap = NULL,
.sv_stackgap = elf32_stackgap,
.sv_onexec_old = exec_onexec_old,
.sv_onexit = exit_onexit,
.sv_set_fork_retval = x86_set_fork_retval,

View File

@ -2757,22 +2757,3 @@ __elfN(untrans_prot)(vm_prot_t prot)
flags |= PF_W;
return (flags);
}
vm_size_t
__elfN(stackgap)(struct image_params *imgp, uintptr_t *stack_base)
{
uintptr_t range, rbase, gap;
int pct;
pct = __elfN(aslr_stack_gap);
if (pct == 0)
return (0);
if (pct > 50)
pct = 50;
range = imgp->eff_stack_sz * pct / 100;
arc4rand(&rbase, sizeof(rbase), 0);
gap = rbase % range;
gap &= ~(sizeof(u_long) - 1);
*stack_base -= gap;
return (gap);
}

View File

@ -1200,9 +1200,6 @@ exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv)
} else {
ssiz = maxssiz;
}
imgp->eff_stack_sz = lim_cur(curthread, RLIMIT_STACK);
if (ssiz < imgp->eff_stack_sz)
imgp->eff_stack_sz = ssiz;
stack_addr = sv->sv_usrstack - ssiz;
stack_prot = obj != NULL && imgp->stack_prot != 0 ?
imgp->stack_prot : sv->sv_stackprot;
@ -1557,21 +1554,6 @@ exec_args_get_begin_envv(struct image_args *args)
return (args->endp);
}
void
exec_stackgap(struct image_params *imgp, uintptr_t *dp)
{
struct proc *p = imgp->proc;
if (imgp->sysent->sv_stackgap == NULL ||
(p->p_fctl0 & (NT_FREEBSD_FCTL_ASLR_DISABLE |
NT_FREEBSD_FCTL_ASG_DISABLE)) != 0 ||
(imgp->map_flags & MAP_ASLR) == 0) {
p->p_vmspace->vm_stkgap = 0;
return;
}
p->p_vmspace->vm_stkgap = imgp->sysent->sv_stackgap(imgp, dp);
}
/*
* Copy strings out to the new process address space, constructing new arg
* and env vector tables. Return a pointer to the base so that it can be used
@ -1651,8 +1633,6 @@ exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
destp = rounddown2(destp, sizeof(void *));
ustringp = destp;
exec_stackgap(imgp, &destp);
if (imgp->auxargs) {
/*
* Allocate room on the stack for the ELF auxargs

View File

@ -804,7 +804,7 @@ typedef struct {
#define NT_FREEBSD_FCTL_STKGAP_DISABLE 0x00000004
#define NT_FREEBSD_FCTL_WXNEEDED 0x00000008
#define NT_FREEBSD_FCTL_LA48 0x00000010
#define NT_FREEBSD_FCTL_ASG_DISABLE 0x00000020 /* ASLR STACK GAP Disable */
/* was ASG_DISABLE, do not reuse 0x00000020 */
/* Values for n_type. Used in core files. */
#define NT_PRSTATUS 1 /* Process status. */

View File

@ -83,7 +83,6 @@ struct image_params {
int pagesizeslen;
vm_prot_t stack_prot;
u_long stack_sz;
u_long eff_stack_sz;
struct ucred *newcred; /* new credentials if changing */
#define IMGACT_SHELL 0x1
#define IMGACT_BINMISC 0x2
@ -119,7 +118,6 @@ void exec_setregs(struct thread *, struct image_params *, uintptr_t);
int exec_shell_imgact(struct image_params *);
int exec_copyin_args(struct image_args *, const char *, enum uio_seg,
char **, char **);
void exec_stackgap(struct image_params *imgp, uintptr_t *dp);
int pre_execve(struct thread *td, struct vmspace **oldvmspace);
void post_execve(struct thread *td, int error, struct vmspace *oldvmspace);
#endif

View File

@ -118,7 +118,6 @@ int __elfN(remove_brand_entry)(Elf_Brandinfo *entry);
int __elfN(freebsd_fixup)(uintptr_t *, struct image_params *);
int __elfN(coredump)(struct thread *, struct vnode *, off_t, int);
size_t __elfN(populate_note)(int, void *, void *, size_t, void **);
vm_size_t __elfN(stackgap)(struct image_params *, uintptr_t *);
int __elfN(freebsd_copyout_auxargs)(struct image_params *, uintptr_t);
void __elfN(puthdr)(struct thread *, void *, size_t, int, size_t, int);
void __elfN(prepare_notes)(struct thread *, struct note_info_list *,

View File

@ -120,7 +120,6 @@ struct sysentvec {
void (*sv_elf_core_prepare_notes)(struct thread *,
struct note_info_list *, size_t *);
int (*sv_imgact_try)(struct image_params *);
vm_size_t (*sv_stackgap)(struct image_params *, uintptr_t *);
int (*sv_copyout_auxargs)(struct image_params *,
uintptr_t);
int sv_minsigstksz; /* minimum signal stack size */

View File

@ -71,8 +71,6 @@ static struct ControlFeatures featurelist[] = {
{ "nostackgap", NT_FREEBSD_FCTL_STKGAP_DISABLE, "Disable stack gap" },
{ "wxneeded", NT_FREEBSD_FCTL_WXNEEDED, "Requires W+X mappings" },
{ "la48", NT_FREEBSD_FCTL_LA48, "amd64: Limit user VA to 48bit" },
{ "noaslrstkgap", NT_FREEBSD_FCTL_ASG_DISABLE,
"Disable ASLR stack gap" },
};
static struct option long_opts[] = {