рпм = русскоязычный пакетный менеджер |
Блог Всячепуза
binfmt_misc |
fs/exec.c
defines the system call at SYSCALL_DEFINE3(execve
Simply forwards to do_execve
.
do_execve
Forwards to do_execveat_common
.
do_execveat_common
To find the next major function, track when return value retval
is last modified.
Starts building a struct linux_binprm *bprm
to describe the program, and passes it to exec_binprm
to execute.
exec_binprm
Once again, follow the return value to find the next major call.
search_binary_handler
Handlers are determined by the first magic bytes of the executable.
The two most common handlers are those for interpreted files (#!
magic) and for ELF (\x7fELF
magic), but there are other built-into the kernel, e.g. a.out
. And users can also register their own though /proc/sys/fs/binfmt_misc
The ELF handler is defined at fs/binfmt_elf.c
.
The formats
list contains all the handlers.
Each handler file contains something like:
static int __init init_elf_binfmt(void)
{
register_binfmt(&elf_format);
return 0;
}
and elf_format
is a struct linux_binfmt
defined in that file.
__init
is magic and puts that code into a magic section that gets called when the kernel starts: What does __init mean in the Linux kernel code?
Linker-level dependency injection!
There is also a recursion counter, in case an interpreter executes itself infinitely.
Try this:
echo '#!/tmp/a' > /tmp/a
chmod +x /tmp/a
/tmp/a
Once again we follow the return value to see what comes next, and see that it comes from:
retval = fmt->load_binary(bprm);
where load_binary
is defined for each handler on the struct: C-style polymorsphism.
fs/binfmt_elf.c:load_binary
Does the actual work:
struct linux_binprm
, registers into a struct pt_regs
)start_thread
, which is where it can really start to getting scheduledTODO: enter into more detail here. In particular, what RIP gets set to and how the dynamic loader is started.
# eix -cC app-shells [N] app-shells/autojump (--): change directory command that learns [?] app-shells/bash (4.3_p42-r1@01/14/2016 -> 4.3_p39): The standard GNU Bourne again shell [?] app-shells/bash-completion (2.3-r2@04/28/2016 -> 2.1_p20141224): Programmable Completion for bash [N] app-shells/bashdb (--): bash source code debugging [N] app-shells/bashish (2.2.4): Text console theme engine [N] app-shells/ccsh (0.0.4-r3): UNIX Shell for people already familiar with the C language [N] app-shells/dash (0.5.8.2): DASH is a direct descendant of the NetBSD version of ash (the Almquist SHell) and is POSIX compliant [N] app-shells/dsh (0.25.10): Distributed Shell [N] app-shells/esh (0.8.5-r2): A UNIX Shell with a simplified Scheme syntax [N] app-shells/fish ((~)2.2.0): fish is the Friendly Interactive SHell [I] app-shells/gentoo-bashcomp (20140911@11/24/2014): Gentoo-specific bash command-line completions (emerge, ebuild, equery, repoman, layman, etc) [N] app-shells/gentoo-zsh-completions ((~)20150103): Gentoo specific zsh completion support (includes emerge and ebuild commands) [N] app-shells/heirloom-sh ((~)050706): Heirloom Bourne Shell, derived from OpenSolaris code SVR4/SVID3 [N] app-shells/ksh ((~)93.20140625): The Original Korn Shell, 1993 revision (ksh93) [N] app-shells/localshell (1.3.4): Localshell allows per-user/group local control of shell execution [N] app-shells/mksh ((~)51): MirBSD Korn Shell [N] app-shells/mpibash ((~)1.2): Parallel scripting right from the Bourne-Again Shell (Bash) [N] app-shells/pdmenu ((~)1.3.4): A simple console menu program [N] app-shells/pdsh ((~)2.26): A high-performance, parallel remote shell utility [N] app-shells/posh ((~)0.12): Reimplementation of Bourne shell based on pdksh [N] app-shells/psh (1.8.1-r1): Combines the interactive nature of a Unix shell with the power of Perl [I] app-shells/push (1.6@06/27/2015): A POSIX shell function to treat a variable like an array, quoting args [N] app-shells/rc ((~)1.7.2): A reimplementation of the Plan 9 shell [N] app-shells/rrs (1.70-r1): Reverse Remote Shell [N] app-shells/rssh ((~)2.3.4_p3): Restricted shell for SSHd [N] app-shells/rust-zshcomp ((~)1_beta20150411): Rust zsh completions [N] app-shells/sash (3.8): A small (static) UNIX Shell [N] app-shells/scsh ((~)0.6.7-r1): Unix shell embedded in Scheme [N] app-shells/scsh-install-lib (--): Installation tool for the Scheme Untergrund Library [N] app-shells/shish (--): The diet shell [N] app-shells/smrsh ((~)8.14.9): Sendmail restricted shell, for use with MTAs other than Sendmail [N] app-shells/soapbox ((~)0.3.1-r1): A preload (sandbox) library to restrict filesystem writes [N] app-shells/squirrelsh ((~)1.2.7): An advanced, cross-platform object oriented scripting shell based on the squirrel scripting language [N] app-shells/tcsh ((~)6.18.01-r3): Enhanced version of the Berkeley C shell (csh) [N] app-shells/zsh ((~)5.0.8): UNIX Shell similar to the Korn shell [N] app-shells/zsh-completions ((~)0.12.0-r2): Additional completion definitions for Zsh Found 36 matches.