Function report |
Source Code:fs\binfmt_elf.c |
Create Date:2022-07-28 20:28:24 |
| Last Modify:2020-03-12 14:18:49 | Copyright©Brick |
| home page | Tree |
| Annotation kernel can get tool activity | Download SCCT | Chinese |
Name:load_elf_binary
Proto:static int load_elf_binary(struct linux_binprm *bprm)
Type:int
Parameter:
| Type | Parameter | Name |
|---|---|---|
| struct linux_binprm * | bprm |
| 683 | struct file * interpreter = NULL |
| 685 | load_addr_set = 0 |
| 687 | struct elf64_phdr * elf_ppnt, * elf_phdata, * interp_elf_phdata = NULL |
| 689 | bss_prot = 0 |
| 692 | interp_load_addr = 0 |
| 694 | reloc_func_desc((__unused__)) = 0 |
| 696 | struct{struct elf64_hdr elf_ex;struct elf64_hdr interp_elf_ex;} * loc |
| 703 | loc = Allocation memory |
| 704 | If Not loc Then |
| 714 | If memcmp( ELF "magic number" , ELFMAG, SELFMAG) != 0 Then Go to out |
| 719 | If Not elf_check_arch( & elf_ex) Then Go to out |
| 721 | If That's for binfmt_elf_fdpic to deal with ( & elf_ex) Then Go to out |
| 727 | If Not elf_phdata Then Go to out |
| 730 | elf_ppnt = elf_phdata |
| 742 | If Segment size in file > # chars in a path name including nul || Segment size in file < 2 Then Go to out_free_ph |
| 747 | If Not elf_interpreter Then Go to out_free_ph |
| 752 | If retval < 0 Then Go to out_free_interp |
| 756 | If elf_interpreter[ Segment size in file - 1] != '\0' Then Go to out_free_interp |
| 759 | interpreter = open_exec(elf_interpreter) |
| 760 | kfree(elf_interpreter) |
| 761 | retval = PTR_ERR(interpreter) |
| 762 | If IS_ERR(interpreter) Then Go to out_free_ph |
| 769 | would_dump(bprm, interpreter) |
| 772 | retval = elf_read(interpreter, & interp_elf_ex, size of interp_elf_ex , 0) |
| 774 | If retval < 0 Then Go to out_free_dentry |
| 777 | Break |
| 779 | out_free_interp : |
| 780 | kfree(elf_interpreter) |
| 781 | Go to out_free_ph |
| 784 | elf_ppnt = elf_phdata |
| 787 | Case p_type == PT_GNU_STACK |
| 788 | If p_flags & PF_X Then executable_stack = Enable executable stacks |
| 790 | Else executable_stack = Disable executable stacks |
| 792 | Break |
| 798 | If retval Then Go to out_free_dentry |
| 800 | Break |
| 804 | If interpreter Then |
| 807 | If memcmp( ELF "magic number" , ELFMAG, SELFMAG) != 0 Then Go to out_free_dentry |
| 810 | If Not elf_check_arch( & interp_elf_ex) || That's for binfmt_elf_fdpic to deal with ( & interp_elf_ex) Then Go to out_free_dentry |
| 817 | If Not interp_elf_phdata Then Go to out_free_dentry |
| 821 | elf_ppnt = interp_elf_phdata |
| 828 | If retval Then Go to out_free_dentry |
| 830 | Break |
| 842 | If retval Then Go to out_free_dentry |
| 847 | If retval Then Go to out_free_dentry |
| 852 | SET_PERSONALITY2(elf_ex, & arch_state) |
| 859 | setup_new_exec(bprm) |
| 864 | retval = Finalizes the stack vm_area_struct. The flags and permissions are updated,* the stack is optionally relocated, and some extra space is added. |
| 866 | If retval < 0 Then Go to out_free_dentry |
| 869 | elf_bss = 0 |
| 870 | elf_brk = 0 |
| 872 | start_code = ~0UL |
| 873 | end_code = 0 |
| 874 | start_data = 0 |
| 875 | end_data = 0 |
| 883 | total_size = 0 |
| 897 | If retval Then Go to out_free_dentry |
| 899 | nbyte = ELF_PAGEOFFSET(elf_bss) |
| 900 | If nbyte Then |
| 901 | nbyte = ELF_MIN_ALIGN - nbyte |
| 919 | vaddr = Segment virtual address |
| 924 | If e_type == ET_EXEC || load_addr_set Then |
| 925 | elf_flags |= Interpret addr exactly |
| 957 | If interpreter Then |
| 959 | If flags & Randomize virtual address space Then load_bias += arch_mmap_rnd() |
| 961 | elf_flags |= Interpret addr exactly |
| 962 | Else load_bias = 0 |
| 972 | load_bias = ELF_PAGESTART(load_bias - vaddr) |
| 976 | If Not total_size Then |
| 978 | Go to out_free_dentry |
| 987 | Go to out_free_dentry |
| 990 | If Not load_addr_set Then |
| 991 | load_addr_set = 1 |
| 994 | load_bias += error - ELF_PAGESTART(load_bias + vaddr) |
| 997 | reloc_func_desc = load_bias |
| 1000 | k = Segment virtual address |
| 1001 | If k < start_code Then start_code = k |
| 1003 | If start_data < k Then start_data = k |
| 1011 | If BAD_ADDR(k) || Segment size in file > Segment size in memory || Segment size in memory > TASK_SIZE || TASK_SIZE - Segment size in memory < k Then |
| 1016 | Go to out_free_dentry |
| 1019 | k = Segment virtual address + Segment size in file |
| 1034 | Entry point virtual address += load_bias |
| 1037 | start_code += load_bias |
| 1039 | start_data += load_bias |
| 1048 | If retval Then Go to out_free_dentry |
| 1052 | Go to out_free_dentry |
| 1055 | If interpreter Then |
| 1064 | interp_load_addr = elf_entry |
| 1065 | elf_entry += Entry point virtual address |
| 1072 | reloc_func_desc = interp_load_addr |
| 1075 | fput(interpreter) |
| 1076 | Else |
| 1080 | Go to out_free_dentry |
| 1084 | kfree(interp_elf_phdata) |
| 1085 | kfree(elf_phdata) |
| 1087 | set_binfmt( & elf_format) |
| 1090 | retval = arch_setup_additional_pages(bprm, !!interpreter) |
| 1095 | retval = create_elf_tables(bprm, & elf_ex, load_addr, interp_load_addr) |
| 1100 | start_code = start_code |
| 1101 | start_data = start_data |
| 1103 | start_stack = p |
| 1118 | brk = start_brk = arch_randomize_brk(mm) |
| 1125 | If personality & MMAP_PAGE_ZERO Then |
| 1130 | error = vm_mmap(NULL, 0, PAGE_SIZE, page can be read | page can be executed , Interpret addr exactly | Changes are private , 0) |
| 1134 | regs = current_pt_regs() |
| 1150 | start_thread(regs, elf_entry, p) |
| 1151 | retval = 0 |
| 1152 | out : |
| 1154 | out_ret : |
| 1155 | Return retval |
| 1158 | out_free_dentry : |
| 1159 | kfree(interp_elf_phdata) |
| 1161 | If interpreter Then fput(interpreter) |
| 1163 | out_free_ph : |
| 1164 | kfree(elf_phdata) |
| 1165 | Go to out |
| Source code conversion tool public plug-in interface | X |
|---|---|
| Support c/c++/esqlc/java Oracle/Informix/Mysql Plug-in can realize: logical Report Code generation and batch code conversion |