Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:fs\binfmt_elf_fdpic.c Create Date:2022-07-28 20:29:03
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:load an fdpic binary into various bits of memory

Proto:static int load_elf_fdpic_binary(struct linux_binprm *bprm)

Type:int

Parameter:

TypeParameterName
struct linux_binprm *bprm
185  regs = current_pt_regs()
194  struct file * interpreter = NULL
195  char * interpreter_name = NULL
200  kdebug("____ LOAD %d ____", pid)
202  memset( & exec_params, 0, size of exec_params )
203  memset( & interp_params, 0, size of interp_params )
205  copy of ELF header = buf
206  flags = T if this object is present | T if this object is the executable
209  retval = -ENOEXEC
210  If Not is_elf( & copy of ELF header , file) Then Go to error
212  If Not That's for binfmt_elf_fdpic to deal with ( & copy of ELF header ) Then
215  Go to error
224  retval = ad the program headers table into memory
225  If retval < 0 Then Go to error
229  phdr = copy of PT_PHDR table
231  When i < e_phnum cycle
233  Case p_type == PT_INTERP
234  retval = -ENOMEM
237  retval = -ENOENT
238  If p_filesz < 2 Then Go to error
243  If Not interpreter_name Then Go to error
246  pos = p_offset
250  If retval >= 0 Then retval = -ENOEXEC
252  Go to error
255  retval = -ENOENT
256  If interpreter_name[p_filesz - 1] != '\0' Then Go to error
259  kdebug("Using ELF interpreter %s", interpreter_name)
264  If IS_ERR(interpreter) Then
265  interpreter = NULL
266  Go to error
276  pos = 0
280  If retval >= 0 Then retval = -ENOEXEC
282  Go to error
286  Break
288  Case p_type == PT_LOAD
293  Break
298  If is_constdisp( & copy of ELF header ) Then flags |= PT_LOADs require constant* displacement
302  If interpreter_name Then
303  retval = -ELIBBAD
304  If Not is_elf( & copy of ELF header , interpreter) Then Go to error
307  flags = T if this object is present
310  retval = ad the program headers table into memory
311  If retval < 0 Then Go to error
315  stack_size = stack size requested (PT_GNU_STACK)
316  If flags & T if stack to be executable Then executable_stack = Enable executable stacks
318  Else if flags & T if stack not to be executable Then executable_stack = Disable executable stacks
320  Else executable_stack = Whatever the arch defaults to
323  If stack_size == 0 Then
324  stack_size = stack size requested (PT_GNU_STACK)
325  If flags & T if stack to be executable Then executable_stack = Enable executable stacks
327  Else if flags & T if stack not to be executable Then executable_stack = Disable executable stacks
329  Else executable_stack = Whatever the arch defaults to
333  retval = -ENOEXEC
334  If stack_size == 0 Then stack_size = 131072UL
337  If is_constdisp( & copy of ELF header ) Then flags |= PT_LOADs require constant* displacement
341  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
342  If retval Then Go to error
348  If That's for binfmt_elf_fdpic to deal with ( & copy of ELF header ) Then Change personality of the currently running process.(PER_LINUX_FDPIC)
350  Else Change personality of the currently running process.(PER_LINUX)
352  If An executable for which elf_read_implies_exec() returns TRUE will* have the READ_IMPLIES_EXEC personality flag set automatically.( & copy of ELF header , executable_stack) Then personality |= READ_IMPLIES_EXEC
355  setup_new_exec(bprm)
357  set_binfmt( & elf_fdpic_format)
359  start_code = 0
360  end_code = 0
361  start_stack = 0
362  start_data = 0
363  end_data = 0
364  exec_fdpic_loadmap = 0
365  interp_fdpic_loadmap = 0
368  elf_fdpic_arch_lay_out_mm( & exec_params, & interp_params, & start_stack, & start_brk)
373  retval = Finalizes the stack vm_area_struct. The flags and permissions are updated,* the stack is optionally relocated, and some extra space is added.
375  If retval < 0 Then Go to error
378  retval = arch_setup_additional_pages(bprm, !!interpreter_name)
379  If retval < 0 Then Go to error
385  retval = load the appropriate binary image (executable or interpreter) into memory* - we assume no MMU is available* - if no other PIC bits are set in params->hdr->e_flags* - we assume that the LOADable segments in the binary are independently relocatable* - we
387  If retval < 0 Then Go to error
390  If interpreter_name Then
391  retval = load the appropriate binary image (executable or interpreter) into memory* - we assume no MMU is available* - if no other PIC bits are set in params->hdr->e_flags* - we assume that the LOADable segments in the binary are independently relocatable* - we
393  If retval < 0 Then
395  Go to error
398  allow_write_access(interpreter)
399  fput(interpreter)
400  interpreter = NULL
404  If Not start_brk Then start_brk = end_data
407  brk = start_brk = align the pointer to the (next) page boundary (start_brk)
437  stall the new credentials for this executable
438  If present useful information to the program by shovelling it onto the new* process's stack < 0 Then Go to error
442  kdebug("- start_code %lx", start_code)
443  kdebug("- end_code %lx", end_code)
444  kdebug("- start_data %lx", start_data)
445  kdebug("- end_data %lx", end_data)
446  kdebug("- start_brk %lx", start_brk)
447  kdebug("- brk %lx", brk)
448  kdebug("- start_stack %lx", start_stack)
462  Runs immediately before start_thread() takes over.
464  entryaddr = If mapped entry user address Else mapped entry user address
465  start_thread(regs, entryaddr, start_stack)
467  retval = 0
469  error :
470  If interpreter Then
471  allow_write_access(interpreter)
472  fput(interpreter)
474  kfree(interpreter_name)
475  kfree( copy of PT_PHDR table )
476  kfree(loadmap to be passed to userspace )
477  kfree( copy of PT_PHDR table )
478  kfree(loadmap to be passed to userspace )
479  Return retval