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:   Mon, 7 Nov 2022 17:14:43 -0800
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Rong Tao <rtoax@...mail.com>
Cc:     andrii@...nel.org, ast@...nel.org, bpf@...r.kernel.org,
        daniel@...earbox.net, haoluo@...gle.com, john.fastabend@...il.com,
        jolsa@...nel.org, kpsingh@...nel.org, linux-kernel@...r.kernel.org,
        martin.lau@...ux.dev, rongtao@...tc.cn, sdf@...gle.com,
        song@...nel.org, yhs@...com
Subject: Re: [PATCH bpf-next] samples/bpf: Fix sockex3 error: missing BPF prog type

On Fri, Nov 4, 2022 at 11:48 PM Rong Tao <rtoax@...mail.com> wrote:
>
> From: Rong Tao <rongtao@...tc.cn>
>
> since commit 450b167fb9be("libbpf: clean up SEC() handling"),
> sec_def_matches() does not recognize "socket/xxx" as "socket", therefore,
> the BPF program type is not recognized.
>
> Instead of sockex3_user.c parsing section names to get the BPF program fd.
> We use the program array map to assign a static index to each BPF program
> (get inspired by selftests/bpf progs/test_prog_array_init.c).
> Therefore, use SEC("socket") as section name instead of SEC("socket/xxx"),
> so that the BPF program is parsed to SOCKET_FILTER type. The "missing BPF
> prog type" problem is solved.
>
> How to reproduce this error:
> $ cd samples/bpf
> $ sudo ./sockex3
> libbpf: prog 'bpf_func_PARSE_IP': missing BPF prog type, check ELF section name 'socket/3'
> libbpf: prog 'bpf_func_PARSE_IP': failed to load: -22
> libbpf: failed to load object './sockex3_kern.o'
> ERROR: loading BPF object file failed
>
> Signed-off-by: Rong Tao <rongtao@...tc.cn>
> ---
>  samples/bpf/sockex3_kern.c | 95 ++++++++++++++++++++++----------------
>  samples/bpf/sockex3_user.c | 23 ++++-----
>  2 files changed, 64 insertions(+), 54 deletions(-)
>
> diff --git a/samples/bpf/sockex3_kern.c b/samples/bpf/sockex3_kern.c
> index b363503357e5..26d916834865 100644
> --- a/samples/bpf/sockex3_kern.c
> +++ b/samples/bpf/sockex3_kern.c
> @@ -17,47 +17,12 @@
>  #define IP_MF          0x2000
>  #define IP_OFFSET      0x1FFF
>
> -#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F
> -
> -struct {
> -       __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
> -       __uint(key_size, sizeof(u32));
> -       __uint(value_size, sizeof(u32));
> -       __uint(max_entries, 8);
> -} jmp_table SEC(".maps");
> -
>  #define PARSE_VLAN 1
>  #define PARSE_MPLS 2
>  #define PARSE_IP 3
>  #define PARSE_IPV6 4
>
> -/* Protocol dispatch routine. It tail-calls next BPF program depending
> - * on eth proto. Note, we could have used ...
> - *
> - *   bpf_tail_call(skb, &jmp_table, proto);
> - *
> - * ... but it would need large prog_array and cannot be optimised given
> - * the map key is not static.
> - */
> -static inline void parse_eth_proto(struct __sk_buff *skb, u32 proto)
> -{
> -       switch (proto) {
> -       case ETH_P_8021Q:
> -       case ETH_P_8021AD:
> -               bpf_tail_call(skb, &jmp_table, PARSE_VLAN);
> -               break;
> -       case ETH_P_MPLS_UC:
> -       case ETH_P_MPLS_MC:
> -               bpf_tail_call(skb, &jmp_table, PARSE_MPLS);
> -               break;
> -       case ETH_P_IP:
> -               bpf_tail_call(skb, &jmp_table, PARSE_IP);
> -               break;
> -       case ETH_P_IPV6:
> -               bpf_tail_call(skb, &jmp_table, PARSE_IPV6);
> -               break;
> -       }
> -}
> +#define PROG_SOCKET_FILTER     SEC("socket")

I dropped this and made SEC("socket") annotations explicit everywhere.
Applied to bpf-next, thank.

>
>  struct vlan_hdr {
>         __be16 h_vlan_TCI;
> @@ -74,6 +39,8 @@ struct flow_key_record {
>         __u32 ip_proto;
>  };
>

[...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ