Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:sys_execve() executes a new program.

Proto:static int __do_execve_file(int fd, struct filename *filename, struct user_arg_ptr argv, struct user_arg_ptr envp, int flags, struct file *file)

Type:int

Parameter:

TypeParameterName
intfd
struct filename *filename
struct user_arg_ptrargv
struct user_arg_ptrenvp
intflags
struct file *file
1720  char * pathbuf = NULL
1725  If IS_ERR(filename) Then Return PTR_ERR(filename)
1734  If flags & set_user() noticed that RLIMIT_NPROC was exceeded && atomic_read( & processes) > rlimit(RLIMIT_NPROC) Then
1736  retval = -EAGAIN
1737  Go to out_ret
1742  flags &= ~set_user() noticed that RLIMIT_NPROC was exceeded
1744  retval = Helper to unshare the files of the current task.* We don't want to expose copy_files internals to* the exec layer of the kernel.
1745  If retval Then Go to out_ret
1748  retval = -ENOMEM
1749  bprm = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
1750  If Not bprm Then Go to out_files
1753  retval = Prepare credentials and lock ->cred_guard_mutex.* install_exec_creds() commits the new creds and drops the lock.* Or, if exec fails before, free_bprm() should release ->cred and* and unlock.
1754  If retval Then Go to out_free
1757  determine how safe it is to execute the proposed program* - the caller must hold ->cred_guard_mutex to protect against* PTRACE_ATTACH or seccomp thread-sync
1758  in_execve = 1
1760  If Not file Then file = do_open_execat(fd, filename, flags)
1762  retval = PTR_ERR(file)
1763  If IS_ERR(file) Then Go to out_unmark
1768  file = file
1769  If Not filename Then
1770  filename = "none"
1771  Else if fd == Special value used to indicateopenat should use the currentworking directory. || pointer to actual string [0] == '/' Then
1772  filename = pointer to actual string
1773  Else
1774  If pointer to actual string [0] == '\0' Then pathbuf = kasprintf(GFP_KERNEL, "/dev/fd/%d", fd)
1776  Else pathbuf = kasprintf(GFP_KERNEL, "/dev/fd/%d/%s", fd, pointer to actual string )
1779  If Not pathbuf Then
1780  retval = -ENOMEM
1781  Go to out_unmark
1788  If close_on_exec(fd, Dependency order vs. p above. (fdt)) Then interp_flags |= BINPRM_FLAGS_PATH_INACCESSIBLE
1790  filename = pathbuf
1792  interp = filename
1794  retval = Create a new mm_struct and populate it with a temporary stack* vm_area_struct. We don't have enough context at this point to set the stack* flags, permissions, and offset, so we use temporary values. We'll update* them later in setup_arg_pages().
1795  If retval Then Go to out_unmark
1798  retval = prepare_arg_pages(bprm, argv, envp)
1799  If retval < 0 Then Go to out
1802  retval = Fill the binprm structure from the inode.* Check permissions, then read the first BINPRM_BUF_SIZE bytes* This may be called multiple times for binary chains (scripts for example).
1803  If retval < 0 Then Go to out
1806  retval = Like copy_strings, but get argv and its values from kernel memory.
1807  If retval < 0 Then Go to out
1810  exec = p
1811  retval = 'copy_strings()' copies argument/environment strings from the old* processes's memory to the new process's stack. The call to get_user_pages()* ensures the destination page is created and not swapped out.
1812  If retval < 0 Then Go to out
1815  retval = 'copy_strings()' copies argument/environment strings from the old* processes's memory to the new process's stack. The call to get_user_pages()* ensures the destination page is created and not swapped out.
1816  If retval < 0 Then Go to out
1819  would_dump(bprm, file)
1821  retval = exec_binprm(bprm)
1822  If retval < 0 Then Go to out
1826  in_exec = 0
1827  in_execve = 0
1828  rseq_execve(current process)
1829  acct_update_integrals(current process)
1830  task_numa_free(current process, false)
1831  free_bprm(bprm)
1832  kfree(pathbuf)
1833  If filename Then putname(filename)
1835  If displaced Then put_files_struct(displaced)
1837  Return retval
1839  out :
1840  If mm Then
1841  The nascent bprm->mm is not visible until exec_mmap() but it can* use a lot of memory, account these pages in current->mm temporary* for oom_badness()->get_mm_rss(). Once exec succeeds or fails, we* change the counter back via acct_arg_size(0).
1842  Decrement the use count and release all resources for an mm.
1845  out_unmark :
1846  in_exec = 0
1847  in_execve = 0
1849  out_free :
1850  free_bprm(bprm)
1851  kfree(pathbuf)
1853  out_files :
1854  If displaced Then reset_files_struct(displaced)
1856  out_ret :
1857  If filename Then putname(filename)
1859  Return retval
Caller
NameDescribe
do_execveat_common
do_execve_file