execve 继承了什么?映射、信号、文件描述符、优先级、ptrace

简介

execve syscall 做了什么

重要参考
Linux 进程启动 execve 系统调用内核源码解析

execve 一次简单的跟踪

入口

SYSCALL_DEFINE3(execve,
		const char __user *, filename,
		const char __user *const __user *, argv,
		const char __user *const __user *, envp)
{
	return do_execve(getname(filename), argv, envp);
}
  • SYSCALL_DEFINE3 表示这个syscall有三个参数 宏定义 实际函数名do_sys_execve
  • 还有个execveat系统调用 区别仅仅是filename的cwd可以指定
    static int do_execve(struct filename *filename,
    	const char __user *const __user *__argv,
    	const char __user *const __user *__envp)
    {
    	struct user_arg_ptr argv = { .ptr.native = __argv };
    	struct user_arg_ptr envp = { .ptr.native = __envp };
    	return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
    }

ftrace

对bash中敲ls跟踪 部分不重要的地方已省略…

抓的是do_execveat_common,因为do_sys_execvedo_execve 都不让抓,报错,不懂

# perf ftrace --graph-opts depth=7 -a -G do_execveat_common
# tracer: function_graph
#
# CPU  DURATION                  FUNCTION CALLS
# |     |   |                     |   |   |   |
   1)               |  do_execveat_common() {
   1)               |    alloc_bprm() {
   1)               |      ...
   1) + 13.133 us   |    }
   1)               |    copy_string_kernel() {
                           ...   
   1) + 14.515 us   |    }
   1)               |    copy_strings.isra.0() {
                           ...
   1) + 66.078 us   |    }
   1)               |    copy_strings.isra.0() {
                           ...
   1)   6.495 us    |    }
   1)               |    bprm_execve() {
   1)   0.188 us    |      mutex_lock_interruptible();
   1)               |      prepare_exec_creds() {
                              ...
   1)   3.646 us    |      }
   1)               |      bprm_execve.part.0() {
   1)               |        check_unsafe_exec() {
                                 ...
   1)   3.999 us    |        }
   1)               |        do_open_execat() {
                                 ...
   1) + 57.539 us   |        }
   1)               |        sched_exec() {
                                 ...
   1)   3.658 us    |        }
   1)               |        security_bprm_creds_for_exec() {
                                 ...
   1) + 13.107 us   |        }
   1)               |        exec_binprm() {
   1)               |          search_binary_handler() {
   1)               |            kernel_read() {
                                 ...
   1) ! 445.465 us  |            }
   1)               |            security_bprm_check() {
   1)   1.134 us    |              ima_bprm_check();
   1)   1.431 us    |            }
   1)   0.229 us    |            _raw_read_lock();
   1)   0.407 us    |            try_module_get();
   1)   0.124 us    |            load_script();
   1)   0.119 us    |            _raw_read_lock();
   1)   0.094 us    |            module_put();
   1)   0.095 us    |            try_module_get();
   1)               |            load_elf_binary() {
   1)   3.002 us    |              load_elf_phdrs();
   1)   0.263 us    |              __kmalloc();
   1)   0.933 us    |              kernel_read();
   1) + 12.149 us   |              open_exec();
   1)   0.207 us    |              irq_enter_rcu();
   1)   0.532 us    |              __sysvec_irq_work();
   1)   0.230 us    |              irq_exit_rcu();
   1)   0.283 us    |              kfree();
   1)   0.413 us    |              would_dump();
   1)   0.314 us    |              kmem_cache_alloc_trace();
   1)   1.875 us    |              kernel_read();
   1)   1.352 us    |              load_elf_phdrs();
   1) ! 273.565 us  |              begin_new_exec();
   1)   0.418 us    |              irq_enter_rcu();
   1)   0.336 us    |              __sysvec_irq_work();
   1)   0.169 us    |              irq_exit_rcu();
   1)   0.368 us    |          
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值