Project

General

Profile

Submit #2854 » pie.patch

shamaz, 11/25/2015 11:03 AM

View differences:

sys/cpu/i386/include/elf.h
160 160
#define ELF_TARG_MACH	EM_386
161 161
#define ELF_TARG_VER	1
162 162

  
163
 /*
164
  * i386 load base for PIE binaries
165
  */
166
#define	ET_DYN_LOAD_ADDR	0x01001000
167

  
168 163
#ifdef _KERNEL
169 164

  
170 165
/*
sys/cpu/x86_64/include/elf.h
155 155
#define	ELF_TARG_MACH	EM_X86_64
156 156
#define	ELF_TARG_VER	1
157 157

  
158
 /*
159
  * x86_64 load base for PIE binaries
160
  */
161
#define	ET_DYN_LOAD_ADDR	0x01021000
162

  
163 158
#ifdef _KERNEL
164 159
/*
165 160
 * On the i386 we load the dynamic linker where a userland call
sys/kern/imgact_elf.c
610 610
	u_long text_size = 0, data_size = 0, total_size = 0;
611 611
	u_long text_addr = 0, data_addr = 0;
612 612
	u_long seg_size, seg_addr;
613
	u_long addr, baddr, et_dyn_addr, entry = 0, proghdr = 0;
613
	u_long addr, baddr, et_dyn_addr = 0, entry = 0, proghdr = 0;
614 614
	int32_t osrel = 0;
615 615
	int error = 0, i, n;
616 616
	boolean_t failure;
......
694 694
		 * non-zero for some reason.
695 695
		 */
696 696
		if (baddr == 0)
697
			et_dyn_addr = ET_DYN_LOAD_ADDR;
698
		else
699
			et_dyn_addr = 0;
700
	} else
701
		et_dyn_addr = 0;
697
			et_dyn_addr = 1;
698
	}
702 699

  
703 700
	if (interp != NULL && brand_info->interp_newpath != NULL)
704 701
		newinterp = brand_info->interp_newpath;
......
714 711
	vsetflags(imgp->vp, VTEXT);
715 712

  
716 713
	vmspace = imgp->proc->p_vmspace;
714
	if (et_dyn_addr)
715
		et_dyn_addr = vm_map_hint (imgp->proc, 0, VM_PROT_READ | VM_PROT_EXECUTE);
717 716

  
718 717
	for (i = 0; i < hdr->e_phnum; i++) {
719 718
		switch (phdr[i].p_type) {
(1-1/4)