Project

General

Profile

Submit #2854 » pie2.patch

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

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