lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 10 Nov 2019 08:56:38 -0800
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Alexei Starovoitov <ast@...nel.org>
Cc:     "David S. Miller" <davem@...emloft.net>,
        Daniel Borkmann <daniel@...earbox.net>, x86@...nel.org,
        Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
        Kernel Team <kernel-team@...com>
Subject: Re: [PATCH v3 bpf-next 16/18] libbpf: Add support for attaching BPF
 programs to other BPF programs

On Thu, Nov 7, 2019 at 10:41 PM Alexei Starovoitov <ast@...nel.org> wrote:
>
> Extend libbpf api to pass attach_prog_fd into bpf_object__open.
>
> Signed-off-by: Alexei Starovoitov <ast@...nel.org>
> ---
>  tools/include/uapi/linux/bpf.h |  1 +
>  tools/lib/bpf/bpf.c            |  9 +++--
>  tools/lib/bpf/bpf.h            |  5 ++-
>  tools/lib/bpf/libbpf.c         | 65 +++++++++++++++++++++++++++++-----
>  tools/lib/bpf/libbpf.h         |  3 +-
>  5 files changed, 69 insertions(+), 14 deletions(-)
>
> diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
> index 69c200e6e696..4842a134b202 100644
> --- a/tools/include/uapi/linux/bpf.h
> +++ b/tools/include/uapi/linux/bpf.h
> @@ -425,6 +425,7 @@ union bpf_attr {
>                 __aligned_u64   line_info;      /* line info */
>                 __u32           line_info_cnt;  /* number of bpf_line_info records */
>                 __u32           attach_btf_id;  /* in-kernel BTF type id to attach to */
> +               __u32           attach_prog_fd; /* 0 to attach to vmlinux */
>         };
>
>         struct { /* anonymous struct used by BPF_OBJ_* commands */
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index b3e3e99a0f28..f805787c8efd 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -228,10 +228,14 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
>         memset(&attr, 0, sizeof(attr));
>         attr.prog_type = load_attr->prog_type;
>         attr.expected_attach_type = load_attr->expected_attach_type;
> -       if (attr.prog_type == BPF_PROG_TYPE_TRACING)
> +       if (attr.prog_type == BPF_PROG_TYPE_TRACING) {
>                 attr.attach_btf_id = load_attr->attach_btf_id;
> -       else
> +               if (load_attr->attach_prog_fd)
> +                       attr.attach_prog_fd = load_attr->attach_prog_fd;

why the if? if it's zero, attr.attach_prog_fd will stay zero.

> +       } else {
>                 attr.prog_ifindex = load_attr->prog_ifindex;
> +               attr.kern_version = load_attr->kern_version;
> +       }
>         attr.insn_cnt = (__u32)load_attr->insns_cnt;
>         attr.insns = ptr_to_u64(load_attr->insns);
>         attr.license = ptr_to_u64(load_attr->license);

[...]

>         CHECK_ERR(bpf_object__elf_init(obj), err, out);
>         CHECK_ERR(bpf_object__check_endianness(obj), err, out);
> @@ -3927,10 +3934,12 @@ __bpf_object__open(const char *path, const void *obj_buf, size_t obj_buf_sz,
>                 bpf_program__set_expected_attach_type(prog, attach_type);
>                 if (prog_type == BPF_PROG_TYPE_TRACING) {
>                         err = libbpf_attach_btf_id_by_name(prog->section_name,
> -                                                          attach_type);
> +                                                          attach_type,
> +                                                          attach_prog_fd);

libbpf_find_attach_btf_id seems like a better name at this point

>                         if (err <= 0)
>                                 goto out;
>                         prog->attach_btf_id = err;
> +                       prog->attach_prog_fd = attach_prog_fd;
>                 }
>         }
>

[...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ