函数逻辑报告

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:fs\binfmt_elf.c Create Date:2022-07-29 11:03:06
Last Modify:2020-03-12 14:18:49 Copyright©Brick
首页 函数Tree
注解内核,赢得工具下载SCCTEnglish

函数名称:load_elf_binary

函数原型:static int load_elf_binary(struct linux_binprm *bprm)

返回类型:int

参数:

类型参数名称
struct linux_binprm *bprm
683  struct file * interpreter = NULL
684  load_addr等于0, load_bias等于0
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
695  executable_stack等于Whatever the arch defaults to
696  struct{struct elf64_hdr elf_ex;struct elf64_hdr interp_elf_ex;} * loc
700  arch_state等于INIT_ARCH_ELF_STATE
703  loc等于开辟内存
704  如果非loc
705  retval等于负ENOMEM
706  转到:out_ret
710  elf_ex等于*buf
712  retval等于负ENOEXEC
714  如果内存比较不等于0则转到:out
717  如果e_type不等于ET_EXECe_type不等于ET_DYN则转到:out
719  如果非elf_check_arch( & elf_ex)则转到:out
721  如果That's for binfmt_elf_fdpic to deal with ( & elf_ex)则转到:out
723  如果非mmap则转到:out
726  elf_phdata等于load_elf_phdrs() - load ELF program headers*@elf_ex: ELF header of the binary whose program headers should be loaded*@elf_file: the opened ELF binary file* Loads ELF program headers from the binary file elf_file, which has the ELF
727  如果非elf_phdata则转到:out
730  elf_ppnt等于elf_phdata
731 i小于e_phnum循环
734  如果p_type不等于PT_INTERP则继续下一循环
741  retval等于负ENOEXEC
742  如果 Segment size in file 大于# chars in a path name including nul Segment size in file 小于2则转到:out_free_ph
745  retval等于负ENOMEM
746  elf_interpreter等于开辟内存
747  如果非elf_interpreter则转到:out_free_ph
750  retval等于elf_read(file, elf_interpreter, Segment size in file , Segment file offset )
752  如果retval小于0则转到:out_free_interp
755  retval等于负ENOEXEC
756  如果elf_interpreter[ Segment size in file - 1]不等于'\0'则转到:out_free_interp
759  interpreter等于open_exec(elf_interpreter)
760  释放内存
761  retval等于错误
762  如果是错误则转到:out_free_ph
769  would_dump(bprm, interpreter)
772  retval等于elf_read(interpreter, & interp_elf_ex, interp_elf_ex的长度, 0)
774  如果retval小于0则转到:out_free_dentry
777  退出
779  out_free_interp :
780  释放内存
781  转到:out_free_ph
784  elf_ppnt等于elf_phdata
785 i小于e_phnum循环switch p_type
787  :p_type恒等于PT_GNU_STACK
788  如果p_flags按位与PF_Xexecutable_stack等于Enable executable stacks
790  否则executable_stack等于Disable executable stacks
792  退出
794  :p_type == PT_LOPROC...PT_HIPROC
795  retval等于arch_elf_pt_proc() - check a PT_LOPROC
798  如果retval则转到:out_free_dentry
800  退出
804  如果interpreter
805  retval等于负ELIBBAD
807  如果内存比较不等于0则转到:out_free_dentry
810  如果非elf_check_arch( & interp_elf_ex)或That's for binfmt_elf_fdpic to deal with ( & interp_elf_ex)则转到:out_free_dentry
815  interp_elf_phdata等于load_elf_phdrs() - load ELF program headers*@elf_ex: ELF header of the binary whose program headers should be loaded*@elf_file: the opened ELF binary file* Loads ELF program headers from the binary file elf_file, which has the ELF
817  如果非interp_elf_phdata则转到:out_free_dentry
821  elf_ppnt等于interp_elf_phdata
822 i小于e_phnum循环switch p_type
828  如果retval则转到:out_free_dentry
830  退出
839  retval等于arch_check_elf() - check an ELF executable*@ehdr: The main ELF header*@has_interp: True if the ELF has an interpreter, else false.*@interp_ehdr: The interpreter's ELF header*@state: Architecture-specific state preserved throughout the process
842  如果retval则转到:out_free_dentry
846  retval等于Calling this is the point of no return. None of the failures will be* seen by userspace since either the process is already taking a fatal* signal (via de_thread() or coredump), or will have SEGV raised
847  如果retval则转到:out_free_dentry
852  SET_PERSONALITY2(elf_ex, & arch_state)
853  如果An executable for which elf_read_implies_exec() returns TRUE will* have the READ_IMPLIES_EXEC personality flag set automatically.(elf_ex, executable_stack)则personality或等于READ_IMPLIES_EXEC
856  如果非personality按位与ADDR_NO_RANDOMIZE的值且Randomize the address space (stacks, mmaps, brk, etc.).* ( When CONFIG_COMPAT_BRK=y we exclude brk from randomization,* as ancient (libc5 based) binaries can segfault. )flags或等于Randomize virtual address space
859  setup_new_exec(bprm)
860  stall the new credentials for this executable
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  如果retval小于0则转到: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
879 i小于e_phnum循环
883  total_size等于0
885  如果p_type不等于PT_LOAD则继续下一循环
897  如果retval则转到:out_free_dentry
900  如果nbyte
901  nbyte等于ELF_MIN_ALIGNnbyte
902  如果nbyte大于elf_brkelf_bssnbyte等于elf_brkelf_bss
904  如果用户内存块清零
915  elf_prot等于make_prot(p_flags)
917  elf_flags等于Changes are private 按位或ETXTBSY 按位或mark it as an executable
919  vaddr等于 Segment virtual address
924  如果e_type恒等于ET_EXECload_addr_set
926  否则如果e_type恒等于ET_DYN
957  如果interpreter
962  否则load_bias等于0
976  如果非total_size
977  retval等于负EINVAL
978  转到:out_free_dentry
982  error等于elf_map(file, load_bias + vaddr, elf_ppnt, elf_prot, elf_flags, total_size)
984  如果BAD_ADDR(error)则
985  retval等于如果是错误错误否则负EINVAL
987  转到:out_free_dentry
990  如果非load_addr_set
991  load_addr_set等于1
993  如果e_type恒等于ET_DYN
1000  k等于 Segment virtual address
1001  如果k小于start_codestart_code等于k
1003  如果start_data小于kstart_data等于k
1015  retval等于负EINVAL
1016  转到:out_free_dentry
1019  k等于 Segment virtual address Segment size in file
1021  如果k大于elf_bsself_bss等于k
1023  如果p_flags按位与PF_Xend_code小于kend_code等于k
1025  如果end_data小于kend_data等于k
1027  k等于 Segment virtual address Segment size in memory
1028  如果k大于elf_brk
1029  bss_prot等于elf_prot
1030  elf_brk等于k
1034  Entry point virtual address 加等于load_bias
1035  elf_bss加等于load_bias
1036  elf_brk加等于load_bias
1037  start_code加等于load_bias
1038  end_code加等于load_bias
1039  start_data加等于load_bias
1040  end_data加等于load_bias
1047  retval等于set_brk(elf_bss, elf_brk, bss_prot)
1048  如果retval则转到:out_free_dentry
1050  如果此条件成立可能性大(为编译器优化)(elf_bss != elf_brk)且此条件成立可能性小(为编译器优化)(We need to explicitly zero any fractional pagesafter the data section (i.e. bss). This wouldcontain the junk from the file that should notbe in memory)则
1051  retval等于负EFAULT
1052  转到:out_free_dentry
1055  如果interpreter
1056  elf_entry等于This is much more generalized than the library routine read function,so we keep this separate. Technically the library read functionis only provided so that we can read a.out libraries that havean ELF header
1059  如果非是错误
1067  如果BAD_ADDR(elf_entry)则
1068  retval等于如果是错误elf_entry否则负EINVAL
1070  转到:out_free_dentry
1072  reloc_func_desc等于interp_load_addr
1074  allow_write_access(interpreter)
1075  fput(interpreter)
1076  否则
1077  elf_entry等于 Entry point virtual address
1078  如果BAD_ADDR(elf_entry)则
1079  retval等于负EINVAL
1080  转到:out_free_dentry
1084  释放内存
1085  释放内存
1087  set_binfmt( & elf_format)
1090  retval等于arch_setup_additional_pages(bprm, !!interpreter)
1091  如果retval小于0则转到:out
1095  retval等于create_elf_tables(bprm, & elf_ex, load_addr, interp_load_addr)
1097  如果retval小于0则转到:out
1099  end_code等于end_code
1100  start_code等于start_code
1101  start_data等于start_data
1102  end_data等于end_data
1103  start_stack等于p
1105  如果flags按位与Randomize virtual address space Randomize the address space (stacks, mmaps, brk, etc.).* ( When CONFIG_COMPAT_BRK=y we exclude brk from randomization,* as ancient (libc5 based) binaries can segfault. )大于1则
1113  如果IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',* 0 otherwise.(CONFIG_ARCH_HAS_ELF_RANDOMIZE)且e_type恒等于ET_DYN且非interpreterbrk等于start_brk等于This is the base location for PIE (ET_DYN with INTERP) loads. On* 64-bit, this is above 4GB to leave the entire 32-bit address* space open for things that want to use the area for 32-bit pointers.
1118  brk等于start_brk等于arch_randomize_brk(mm)
1125  如果personality按位与MMAP_PAGE_ZERO
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()
1146  SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts %edxcontains a pointer to a function which might be registered using `atexit'.This provides a mean for the dynamic linker to call DT_FINI functions for(regs, reloc_func_desc)
1149  Runs immediately before start_thread() takes over.
1150  start_thread(regs, elf_entry, p)
1151  retval等于0
1152  out :
1153  释放内存
1154  out_ret :
1155  返回:retval
1158  out_free_dentry :
1159  释放内存
1160  allow_write_access(interpreter)
1161  如果interpreterfput(interpreter)
1163  out_free_ph :
1164  释放内存
1165  转到:out