Re: [PATCH] bpf:add function bpf_get_task_exe_path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 6, 2022 at 11:54 AM mangosteen728 <mangosteen728@xxxxxxx> wrote:
>
> Add the absolute path to get the executable corresponding tothe task
>
> Signed-off-by: mangosteen728 <mangosteen728@xxxxxxx>
> ---
> Hi
> This is my first attempt to submit patch, there are shortcomings please more but wait.
>
> In security audit often need to get the absolute path to the executable of the process so I tried to add bpf_get_task_exe_path in the helpers function to get.
>
> The code currently only submits the implementation of the function and how is this patch merge possible if I then add the relevant places。
>

See bpf_d_path() BPF helper, you should be able to do what you want
without adding new BPF helper.

> thanks
> mangosteen728
> kernel/bpf/helpers.c | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index 225806a..797f850 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -257,6 +257,43 @@
>         .arg2_type      = ARG_CONST_SIZE,
>  };
>
> +BPF_CALL_3(bpf_get_task_exe_path, struct task_struct *, task, char *, buf, u32, sz)
> +{
> +       struct file *exe_file = NULL;
> +       char *p = NULL;
> +       long len = 0;
> +
> +       if (!sz)
> +               return 0;
> +       exe_file = get_task_exe_file(tsk);
> +       if (IS_ERR_OR_NULL(exe_file))
> +               return 0;
> +       p = d_path(&exe_file->f_path, buf, sz);
> +       if (IS_ERR_OR_NULL(path)) {
> +               len = PTR_ERR(p);
> +       } else {
> +               len = buf + sz - p;
> +               memmove(buf, p, len);
> +       }
> +       fput(exe_file);
> +       return len;
> +}
> +
> +static const struct bpf_func_proto bpf_get_task_exe_path_proto = {
> +       .func       = bpf_get_task_exe_path,
> +       .gpl_only   = false,
> +       .ret_type   = RET_INTEGER,
> +       .arg1_type  = ARG_PTR_TO_BTF_ID,
> +       .arg2_type  = ARG_PTR_TO_MEM,
> +       .arg3_type  = ARG_CONST_SIZE_OR_ZERO,
> +};
> +
> --
>




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux