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]
Message-ID: <tencent_6AD8D17AC411037DA1AC2C8FCB0D15A3D707@qq.com>
Date:   Fri,  4 Nov 2022 11:17:13 +0800
From:   Rong Tao <rtoax@...mail.com>
To:     andrii.nakryiko@...il.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, rtoax@...mail.com,
        sdf@...gle.com, song@...nel.org, yhs@...com
Subject: Re: Re: [PATCH bpf-next] samples/bpf: Fix sockex3: missing BPF prog type

We can not just remove the number of program like:

-#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F
+#define PROG(F) SEC("socket_filter") int bpf_func_##F

because "sockex3" use the _NUMBER_ as index(see map "jmp_table"), if we
apply the following patch, it's still not recognize "socket_filter/xxx"
as "socket_filter", still have "missing BPF prog type" error:

diff --git a/samples/bpf/sockex3_kern.c b/samples/bpf/sockex3_kern.c
index b363503357e5..ab5a7bde66d0 100644
--- a/samples/bpf/sockex3_kern.c
+++ b/samples/bpf/sockex3_kern.c
@@ -17,7 +17,7 @@
 #define IP_MF          0x2000
 #define IP_OFFSET      0x1FFF

-#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F
+#define PROG(F) SEC("socket_filter/"__stringify(F)) int bpf_func_##F

 struct {
        __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
@@ -279,7 +279,7 @@ PROG(PARSE_MPLS)(struct __sk_buff *skb)
        return 0;
 }

-SEC("socket/0")
+SEC("socket_filter/0")
 int main_prog(struct __sk_buff *skb)
 {
        __u32 nhoff = ETH_HLEN;
diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c
index cd6fa79df900..63fc9a8077b1 100644
--- a/samples/bpf/sockex3_user.c
+++ b/samples/bpf/sockex3_user.c
@@ -56,7 +56,7 @@ int main(int argc, char **argv)
                fd = bpf_program__fd(prog);

                section = bpf_program__section_name(prog);
-               if (sscanf(section, "socket/%d", &key) != 1) {
+               if (sscanf(section, "socket_filter/%d", &key) != 1) {
                        fprintf(stderr, "ERROR: finding prog failed\n");
                        goto cleanup;
                }

For a reason, in sockex3_kern.c only have five PROGs, list all five:

#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F
PROG(PARSE_IP)(struct __sk_buff *skb)
PROG(PARSE_IPV6)(struct __sk_buff *skb)
PROG(PARSE_VLAN)(struct __sk_buff *skb)
PROG(PARSE_MPLS)(struct __sk_buff *skb)
SEC("socket/0") int main_prog(struct __sk_buff *skb)

As you can see, all those PROGs are BPF_PROG_TYPE_SOCKET_FILTER, so we can
use the follow patch specify bpf program type as SOCKET_FILTER:

https://lore.kernel.org/lkml/tencent_7DD02046A8398BE3324F85E0F56ED41EB105@qq.com/

diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c
index cd6fa79df900..dc79c17ad195 100644
--- a/samples/bpf/sockex3_user.c
+++ b/samples/bpf/sockex3_user.c
@@ -39,6 +39,9 @@ int main(int argc, char **argv)
                return 0;
        }

+       bpf_object__for_each_program(prog, obj)
+               bpf_program__set_type(prog, BPF_PROG_TYPE_SOCKET_FILTER);
+
        /* load BPF program */
        if (bpf_object__load(obj)) {
                fprintf(stderr, "ERROR: loading BPF object file failed\n");

This patch above totally solved the compile error.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ