Project

General

Profile

Submit #2854 » pie3.patch

shamaz, 12/06/2015 01:19 AM

View differences:

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;
......
690 690
			return (ENOEXEC);
691 691
                }
692 692
		/*
693
		 * Honour the base load address from the dso if it is
694
		 * non-zero for some reason.
693
		 * If p_vaddr field of PT_LOAD program header is zero and type of an
694
		 * executale is ET_DYN, then it must be a position independent
695
		 * executable (PIE). In this case the system needs to pick a base
696
		 * address for us. Set et_dyn_addr to non-zero and choose the actual
697
		 * address when we are ready.
695 698
		 */
696 699
		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;
700
			et_dyn_addr = 1;
701
	}
702 702

  
703 703
	if (interp != NULL && brand_info->interp_newpath != NULL)
704 704
		newinterp = brand_info->interp_newpath;
......
715 715

  
716 716
	vmspace = imgp->proc->p_vmspace;
717 717

  
718
	/* Choose the base address for dynamic executables if we need to. */
719
	if (et_dyn_addr)
720
		et_dyn_addr = vm_map_hint(imgp->proc, 0,
721
		    VM_PROT_READ | VM_PROT_EXECUTE);
722

  
718 723
	for (i = 0; i < hdr->e_phnum; i++) {
719 724
		switch (phdr[i].p_type) {
720 725
		case PT_LOAD:	/* Loadable segment */
(3-3/4)