int do_execve(char * filename, char _user *_user *argv,
17There are other exec variants with different names in the C standard library, but ultimately all are based on execve. As in the above sections, exec is often used to refer to any of these variants.
Not only the register set with the arguments and the name of the executable file (filename) but also pointers to the arguments and the environment of the program are passed as in system programming.18 The notation is slightly clumsy because argv and envp are arrays of pointers, and both the pointer to the array itself as well as all pointers in the array are located in the userspace portion of the virtual address space. Recall from the Introduction that some precautions are required when userspace memory is accessed from the kernel, and that the_user annotations allow automated tools to check if everything is handled properly.
Figure 2-11 shows the code flow diagram for do_execve.
First, the file to be executed is opened; in other words — as described in Chapter 8 — the kernel finds the associated inode and generates a file descriptor that is used to address the file.
bprm_init then handles several administrative tasks: mm_alloc generates a new instance of mm_struct to manage the process address space (see Chapter 4). init_new_context is an architecture-specific function that initializes the instance, and_bprm_mm_init sets up an initial stack.
Various parameters of the new process (e.g., euid, egid, argument list, environment, filename, etc.) that are subsequently passed to other functions are, for the sake of simplicity, combined into a structure of type linux_binprm. prepare_binprm is used to supply a number of parent process values (above all, the effective UID and GID); the remaining data — the argument list — are then copied manually into the structure. Note that prepare_binprm also takes care of handling the SUID and SGID bits:
18argv includes all arguments passed to the program in the command line (for ls -l /usr/bin these are, e.g., -l and /usr/bin). The environment encompasses all environment variables defined at program execution time. In most shells, a list of these variables can be output using set.
Continue reading here: Fsexecc
Was this article helpful?