From 7cd5fa0412845911c2756da98295d5d6ac514ef3 Mon Sep 17 00:00:00 2001 From: Michal Kubecek Date: Nov 06 2019 12:12:49 +0000 Subject: Merge branch 'users/glin/SLE15-SP2/for-next' into SLE15-SP2 Pull bpf fixes from Gary Lin. --- diff --git a/patches.suse/selftests-bpf-More-compatible-nc-options-in-test_lwt.patch b/patches.suse/selftests-bpf-More-compatible-nc-options-in-test_lwt.patch new file mode 100644 index 0000000..b0214d8 --- /dev/null +++ b/patches.suse/selftests-bpf-More-compatible-nc-options-in-test_lwt.patch @@ -0,0 +1,41 @@ +From: Jiri Benc +Date: Tue, 8 Oct 2019 15:10:45 +0200 +Subject: selftests/bpf: More compatible nc options in test_lwt_ip_encap +Patch-mainline: v5.4-rc4 +Git-commit: 106c35dda32f8b63f88cad7433f1b8bb0056958a +References: bsc#1155518 + +Out of the three nc implementations widely in use, at least two (BSD netcat +and nmap-ncat) do not support -l combined with -s. Modify the nc invocation +to be accepted by all of them. + +Fixes: 17a90a788473 ("selftests/bpf: test that GSO works in lwt_ip_encap") +Signed-off-by: Jiri Benc +Signed-off-by: Daniel Borkmann +Link: https://lore.kernel.org/bpf/9f177682c387f3f943bb64d849e6c6774df3c5b4.1570539863.git.jbenc@redhat.com +Acked-by: Gary Lin +--- + tools/testing/selftests/bpf/test_lwt_ip_encap.sh | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +--- a/tools/testing/selftests/bpf/test_lwt_ip_encap.sh ++++ b/tools/testing/selftests/bpf/test_lwt_ip_encap.sh +@@ -314,15 +314,15 @@ test_gso() + command -v nc >/dev/null 2>&1 || \ + { echo >&2 "nc is not available: skipping TSO tests"; return; } + +- # listen on IPv*_DST, capture TCP into $TMPFILE ++ # listen on port 9000, capture TCP into $TMPFILE + if [ "${PROTO}" == "IPv4" ] ; then + IP_DST=${IPv4_DST} + ip netns exec ${NS3} bash -c \ +- "nc -4 -l -s ${IPv4_DST} -p 9000 > ${TMPFILE} &" ++ "nc -4 -l -p 9000 > ${TMPFILE} &" + elif [ "${PROTO}" == "IPv6" ] ; then + IP_DST=${IPv6_DST} + ip netns exec ${NS3} bash -c \ +- "nc -6 -l -s ${IPv6_DST} -p 9000 > ${TMPFILE} &" ++ "nc -6 -l -p 9000 > ${TMPFILE} &" + RET=$? + else + echo " test_gso: unknown PROTO: ${PROTO}" diff --git a/patches.suse/selftests-bpf-Set-rp_filter-in-test_flow_dissector.patch b/patches.suse/selftests-bpf-Set-rp_filter-in-test_flow_dissector.patch new file mode 100644 index 0000000..0d1b549 --- /dev/null +++ b/patches.suse/selftests-bpf-Set-rp_filter-in-test_flow_dissector.patch @@ -0,0 +1,36 @@ +From: Jiri Benc +Date: Tue, 8 Oct 2019 15:10:44 +0200 +Subject: selftests/bpf: Set rp_filter in test_flow_dissector +Patch-mainline: v5.4-rc4 +Git-commit: fd418b01fe26c2430b1091675cceb3ab2b52e1e0 +References: bsc#1155518 + +Many distributions enable rp_filter. However, the flow dissector test +generates packets that have 1.1.1.1 set as (inner) source address without +this address being reachable. This causes the selftest to fail. + +The selftests should not assume a particular initial configuration. Switch +off rp_filter. + +Fixes: 50b3ed57dee9 ("selftests/bpf: test bpf flow dissection") +Signed-off-by: Jiri Benc +Signed-off-by: Daniel Borkmann +Acked-by: Petar Penkov +Link: https://lore.kernel.org/bpf/513a298f53e99561d2f70b2e60e2858ea6cda754.1570539863.git.jbenc@redhat.com +Acked-by: Gary Lin +--- + tools/testing/selftests/bpf/test_flow_dissector.sh | 3 +++ + 1 file changed, 3 insertions(+) + +--- a/tools/testing/selftests/bpf/test_flow_dissector.sh ++++ b/tools/testing/selftests/bpf/test_flow_dissector.sh +@@ -63,6 +63,9 @@ fi + + # Setup + tc qdisc add dev lo ingress ++echo 0 > /proc/sys/net/ipv4/conf/default/rp_filter ++echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter ++echo 0 > /proc/sys/net/ipv4/conf/lo/rp_filter + + echo "Testing IPv4..." + # Drops all IP/UDP packets coming from port 9 diff --git a/patches.suse/selftests-bpf-fix-ctx-write-sysctl-write-read-ok-on-.patch b/patches.suse/selftests-bpf-fix-ctx-write-sysctl-write-read-ok-on-.patch new file mode 100644 index 0000000..bb1328a --- /dev/null +++ b/patches.suse/selftests-bpf-fix-ctx-write-sysctl-write-read-ok-on-.patch @@ -0,0 +1,32 @@ +From: Ilya Leoshkevich +Date: Fri, 30 Aug 2019 13:07:30 +0200 +Subject: selftests/bpf: fix "ctx:write sysctl:write read ok" on s390 +Patch-mainline: v5.4-rc1 +Git-commit: 3404ddf234ba4677bf224cb15ddcdea0ceab956e +References: bsc#1155518 + +"ctx:write sysctl:write read ok" fails on s390 because it reads the +first byte of an int assuming it's the least-significant one, which +is not the case on big-endian arches. Since we are not testing narrow +accesses here (there is e.g. "ctx:file_pos sysctl:read read ok narrow" +for that), simply read the whole int. + +Fixes: 1f5fa9ab6e2e ("selftests/bpf: Test BPF_CGROUP_SYSCTL") +Signed-off-by: Ilya Leoshkevich +Signed-off-by: Daniel Borkmann +Acked-by: Gary Lin +--- + tools/testing/selftests/bpf/test_sysctl.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/tools/testing/selftests/bpf/test_sysctl.c ++++ b/tools/testing/selftests/bpf/test_sysctl.c +@@ -100,7 +100,7 @@ static struct sysctl_test tests[] = { + .descr = "ctx:write sysctl:write read ok", + .insns = { + /* If (write) */ +- BPF_LDX_MEM(BPF_B, BPF_REG_7, BPF_REG_1, ++ BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_1, + offsetof(struct bpf_sysctl, write)), + BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 1, 2), + diff --git a/patches.suse/selftests-bpf-fix-endianness-issues-in-test_sysctl.patch b/patches.suse/selftests-bpf-fix-endianness-issues-in-test_sysctl.patch new file mode 100644 index 0000000..59f8e8b --- /dev/null +++ b/patches.suse/selftests-bpf-fix-endianness-issues-in-test_sysctl.patch @@ -0,0 +1,366 @@ +From: Ilya Leoshkevich +Date: Fri, 30 Aug 2019 13:07:32 +0200 +Subject: selftests/bpf: fix endianness issues in test_sysctl +Patch-mainline: v5.4-rc1 +Git-commit: 3ec2a0ed3fec4ec8b27d9b71fdcbc1c30d1542d3 +References: bsc#1155518 + +A lot of test_sysctl sub-tests fail due to handling strings as a bunch +of immediate values in a little-endian-specific manner. + +Fix by wrapping all immediates in bpf_ntohl and the new bpf_be64_to_cpu. + +fixup_sysctl_value() dynamically writes an immediate, and thus should be +endianness-aware. Implement this by simply memcpy()ing the raw +user-provided value, since testcase endianness and bpf program +endianness match. + +Fixes: 1f5fa9ab6e2e ("selftests/bpf: Test BPF_CGROUP_SYSCTL") +Fixes: 9a1027e52535 ("selftests/bpf: Test file_pos field in bpf_sysctl ctx") +Fixes: 6041c67f28d8 ("selftests/bpf: Test bpf_sysctl_get_name helper") +Fixes: 11ff34f74e32 ("selftests/bpf: Test sysctl_get_current_value helper") +Fixes: 786047dd08de ("selftests/bpf: Test bpf_sysctl_{get,set}_new_value helpers") +Fixes: 8549ddc832d6 ("selftests/bpf: Test bpf_strtol and bpf_strtoul helpers") +Signed-off-by: Ilya Leoshkevich +Signed-off-by: Daniel Borkmann +Acked-by: Gary Lin +--- + tools/testing/selftests/bpf/test_sysctl.c | 125 +++++++++++++++++++----------- + 1 file changed, 82 insertions(+), 43 deletions(-) + +--- a/tools/testing/selftests/bpf/test_sysctl.c ++++ b/tools/testing/selftests/bpf/test_sysctl.c +@@ -13,6 +13,7 @@ + #include + #include + ++#include "bpf_endian.h" + #include "bpf_rlimit.h" + #include "bpf_util.h" + #include "cgroup_helpers.h" +@@ -214,7 +215,8 @@ static struct sysctl_test tests[] = { + /* if (ret == expected && */ + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, sizeof("tcp_mem") - 1, 6), + /* buf == "tcp_mem\0") */ +- BPF_LD_IMM64(BPF_REG_8, 0x006d656d5f706374ULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x7463705f6d656d00ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 2), + +@@ -255,7 +257,8 @@ static struct sysctl_test tests[] = { + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, -E2BIG, 6), + + /* buf[0:7] == "tcp_me\0") */ +- BPF_LD_IMM64(BPF_REG_8, 0x00656d5f706374ULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x7463705f6d650000ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 2), + +@@ -298,12 +301,14 @@ static struct sysctl_test tests[] = { + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 16, 14), + + /* buf[0:8] == "net/ipv4" && */ +- BPF_LD_IMM64(BPF_REG_8, 0x347670692f74656eULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x6e65742f69707634ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 10), + + /* buf[8:16] == "/tcp_mem" && */ +- BPF_LD_IMM64(BPF_REG_8, 0x6d656d5f7063742fULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x2f7463705f6d656dULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 8), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 6), + +@@ -350,12 +355,14 @@ static struct sysctl_test tests[] = { + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, -E2BIG, 10), + + /* buf[0:8] == "net/ipv4" && */ +- BPF_LD_IMM64(BPF_REG_8, 0x347670692f74656eULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x6e65742f69707634ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 6), + + /* buf[8:16] == "/tcp_me\0") */ +- BPF_LD_IMM64(BPF_REG_8, 0x00656d5f7063742fULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x2f7463705f6d6500ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 8), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 2), + +@@ -396,7 +403,8 @@ static struct sysctl_test tests[] = { + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, -E2BIG, 6), + + /* buf[0:8] == "net/ip\0") */ +- BPF_LD_IMM64(BPF_REG_8, 0x000070692f74656eULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x6e65742f69700000ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 2), + +@@ -431,7 +439,8 @@ static struct sysctl_test tests[] = { + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 6, 6), + + /* buf[0:6] == "Linux\n\0") */ +- BPF_LD_IMM64(BPF_REG_8, 0x000a78756e694cULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x4c696e75780a0000ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 2), + +@@ -469,7 +478,8 @@ static struct sysctl_test tests[] = { + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 6, 6), + + /* buf[0:6] == "Linux\n\0") */ +- BPF_LD_IMM64(BPF_REG_8, 0x000a78756e694cULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x4c696e75780a0000ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 2), + +@@ -507,7 +517,8 @@ static struct sysctl_test tests[] = { + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, -E2BIG, 6), + + /* buf[0:6] == "Linux\0") */ +- BPF_LD_IMM64(BPF_REG_8, 0x000078756e694cULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x4c696e7578000000ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 2), + +@@ -650,7 +661,8 @@ static struct sysctl_test tests[] = { + + /* buf[0:4] == "606\0") */ + BPF_LDX_MEM(BPF_W, BPF_REG_9, BPF_REG_7, 0), +- BPF_JMP_IMM(BPF_JNE, BPF_REG_9, 0x00363036, 2), ++ BPF_JMP_IMM(BPF_JNE, BPF_REG_9, ++ bpf_ntohl(0x36303600), 2), + + /* return DENY; */ + BPF_MOV64_IMM(BPF_REG_0, 0), +@@ -685,17 +697,20 @@ static struct sysctl_test tests[] = { + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 23, 14), + + /* buf[0:8] == "3000000 " && */ +- BPF_LD_IMM64(BPF_REG_8, 0x2030303030303033ULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x3330303030303020ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 10), + + /* buf[8:16] == "4000000 " && */ +- BPF_LD_IMM64(BPF_REG_8, 0x2030303030303034ULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x3430303030303020ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 8), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 6), + + /* buf[16:24] == "6000000\0") */ +- BPF_LD_IMM64(BPF_REG_8, 0x0030303030303036ULL), ++ BPF_LD_IMM64(BPF_REG_8, ++ bpf_be64_to_cpu(0x3630303030303000ULL)), + BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 16), + BPF_JMP_REG(BPF_JNE, BPF_REG_8, BPF_REG_9, 2), + +@@ -735,7 +750,8 @@ static struct sysctl_test tests[] = { + + /* buf[0:3] == "60\0") */ + BPF_LDX_MEM(BPF_W, BPF_REG_9, BPF_REG_7, 0), +- BPF_JMP_IMM(BPF_JNE, BPF_REG_9, 0x003036, 2), ++ BPF_JMP_IMM(BPF_JNE, BPF_REG_9, ++ bpf_ntohl(0x36300000), 2), + + /* return DENY; */ + BPF_MOV64_IMM(BPF_REG_0, 0), +@@ -757,7 +773,8 @@ static struct sysctl_test tests[] = { + /* sysctl_set_new_value arg2 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, 0x00303036), ++ BPF_MOV64_IMM(BPF_REG_0, ++ bpf_ntohl(0x36303000)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_2, BPF_REG_7), +@@ -791,7 +808,7 @@ static struct sysctl_test tests[] = { + /* sysctl_set_new_value arg2 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, FIXUP_SYSCTL_VALUE), ++ BPF_LD_IMM64(BPF_REG_0, FIXUP_SYSCTL_VALUE), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_2, BPF_REG_7), +@@ -825,8 +842,9 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, 0x00303036), +- BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), ++ BPF_MOV64_IMM(BPF_REG_0, ++ bpf_ntohl(0x36303000)), ++ BPF_STX_MEM(BPF_W, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), + +@@ -869,7 +887,8 @@ static struct sysctl_test tests[] = { + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), + /* "600 602\0" */ +- BPF_LD_IMM64(BPF_REG_0, 0x0032303620303036ULL), ++ BPF_LD_IMM64(BPF_REG_0, ++ bpf_be64_to_cpu(0x3630302036303200ULL)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), + +@@ -937,7 +956,8 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, 0x00303036), ++ BPF_MOV64_IMM(BPF_REG_0, ++ bpf_ntohl(0x36303000)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), +@@ -969,8 +989,9 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, 0x00373730), +- BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), ++ BPF_MOV64_IMM(BPF_REG_0, ++ bpf_ntohl(0x30373700)), ++ BPF_STX_MEM(BPF_W, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), + +@@ -1012,7 +1033,8 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, 0x00303036), ++ BPF_MOV64_IMM(BPF_REG_0, ++ bpf_ntohl(0x36303000)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), +@@ -1052,7 +1074,8 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, 0x090a0c0d), ++ BPF_MOV64_IMM(BPF_REG_0, ++ bpf_ntohl(0x0d0c0a09)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), +@@ -1092,7 +1115,9 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, 0x00362d0a), /* " -6\0" */ ++ /* " -6\0" */ ++ BPF_MOV64_IMM(BPF_REG_0, ++ bpf_ntohl(0x0a2d3600)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), +@@ -1132,8 +1157,10 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, 0x00362d0a), /* " -6\0" */ +- BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), ++ /* " -6\0" */ ++ BPF_MOV64_IMM(BPF_REG_0, ++ bpf_ntohl(0x0a2d3600)), ++ BPF_STX_MEM(BPF_W, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), + +@@ -1175,8 +1202,10 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8), +- BPF_MOV64_IMM(BPF_REG_0, 0x65667830), /* "0xfe" */ +- BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), ++ /* "0xfe" */ ++ BPF_MOV64_IMM(BPF_REG_0, ++ bpf_ntohl(0x30786665)), ++ BPF_STX_MEM(BPF_W, BPF_REG_7, BPF_REG_0, 0), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), + +@@ -1218,11 +1247,14 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) 9223372036854775807 */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -24), +- BPF_LD_IMM64(BPF_REG_0, 0x3032373333323239ULL), ++ BPF_LD_IMM64(BPF_REG_0, ++ bpf_be64_to_cpu(0x3932323333373230ULL)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), +- BPF_LD_IMM64(BPF_REG_0, 0x3537373435383633ULL), ++ BPF_LD_IMM64(BPF_REG_0, ++ bpf_be64_to_cpu(0x3336383534373735ULL)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 8), +- BPF_LD_IMM64(BPF_REG_0, 0x0000000000373038ULL), ++ BPF_LD_IMM64(BPF_REG_0, ++ bpf_be64_to_cpu(0x3830370000000000ULL)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 16), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), +@@ -1266,11 +1298,14 @@ static struct sysctl_test tests[] = { + /* arg1 (buf) 9223372036854775808 */ + BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -24), +- BPF_LD_IMM64(BPF_REG_0, 0x3032373333323239ULL), ++ BPF_LD_IMM64(BPF_REG_0, ++ bpf_be64_to_cpu(0x3932323333373230ULL)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 0), +- BPF_LD_IMM64(BPF_REG_0, 0x3537373435383633ULL), ++ BPF_LD_IMM64(BPF_REG_0, ++ bpf_be64_to_cpu(0x3336383534373735ULL)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 8), +- BPF_LD_IMM64(BPF_REG_0, 0x0000000000383038ULL), ++ BPF_LD_IMM64(BPF_REG_0, ++ bpf_be64_to_cpu(0x3830380000000000ULL)), + BPF_STX_MEM(BPF_DW, BPF_REG_7, BPF_REG_0, 16), + + BPF_MOV64_REG(BPF_REG_1, BPF_REG_7), +@@ -1344,20 +1379,24 @@ static size_t probe_prog_length(const st + static int fixup_sysctl_value(const char *buf, size_t buf_len, + struct bpf_insn *prog, size_t insn_num) + { +- uint32_t value_num = 0; ++ union { ++ uint8_t raw[sizeof(uint64_t)]; ++ uint64_t num; ++ } value = {}; + uint8_t c, i; + +- if (buf_len > sizeof(value_num)) { ++ if (buf_len > sizeof(value)) { + log_err("Value is too big (%zd) to use in fixup", buf_len); + return -1; + } +- +- for (i = 0; i < buf_len; ++i) { +- c = buf[i]; +- value_num |= (c << i * 8); ++ if (prog[insn_num].code != (BPF_LD | BPF_DW | BPF_IMM)) { ++ log_err("Can fixup only BPF_LD_IMM64 insns"); ++ return -1; + } + +- prog[insn_num].imm = value_num; ++ memcpy(value.raw, buf, buf_len); ++ prog[insn_num].imm = (uint32_t)value.num; ++ prog[insn_num + 1].imm = (uint32_t)(value.num >> 32); + + return 0; + } diff --git a/patches.suse/selftests-bpf-fix-race-in-test_tcp_rtt-test.patch b/patches.suse/selftests-bpf-fix-race-in-test_tcp_rtt-test.patch new file mode 100644 index 0000000..9f53693 --- /dev/null +++ b/patches.suse/selftests-bpf-fix-race-in-test_tcp_rtt-test.patch @@ -0,0 +1,95 @@ +From: Petar Penkov +Date: Fri, 16 Aug 2019 10:08:25 -0700 +Subject: selftests/bpf: fix race in test_tcp_rtt test +Patch-mainline: v5.4-rc1 +Git-commit: fae55527ac1164b66bee983a4d82ade2bfedb332 +References: bsc#1155518 + +There is a race in this test between receiving the ACK for the +single-byte packet sent in the test, and reading the values from the +map. + +This patch fixes this by having the client wait until there are no more +unacknowledged packets. + +Before: +for i in {1..1000}; do ../net/in_netns.sh ./test_tcp_rtt; \ +done | grep -c PASSED +< trimmed error messages > +993 + +After: +for i in {1..10000}; do ../net/in_netns.sh ./test_tcp_rtt; \ +done | grep -c PASSED +10000 + +Fixes: b55873984dab ("selftests/bpf: test BPF_SOCK_OPS_RTT_CB") +Signed-off-by: Petar Penkov +Reviewed-by: Stanislav Fomichev +Signed-off-by: Daniel Borkmann +Acked-by: Gary Lin +--- + tools/testing/selftests/bpf/test_tcp_rtt.c | 31 +++++++++++++++++++++++++++++ + 1 file changed, 31 insertions(+) + +--- a/tools/testing/selftests/bpf/test_tcp_rtt.c ++++ b/tools/testing/selftests/bpf/test_tcp_rtt.c +@@ -6,6 +6,7 @@ + #include + #include + #include ++#include + #include + + #include +@@ -34,6 +35,30 @@ static void send_byte(int fd) + error(1, errno, "Failed to send single byte"); + } + ++static int wait_for_ack(int fd, int retries) ++{ ++ struct tcp_info info; ++ socklen_t optlen; ++ int i, err; ++ ++ for (i = 0; i < retries; i++) { ++ optlen = sizeof(info); ++ err = getsockopt(fd, SOL_TCP, TCP_INFO, &info, &optlen); ++ if (err < 0) { ++ log_err("Failed to lookup TCP stats"); ++ return err; ++ } ++ ++ if (info.tcpi_unacked == 0) ++ return 0; ++ ++ usleep(10); ++ } ++ ++ log_err("Did not receive ACK"); ++ return -1; ++} ++ + static int verify_sk(int map_fd, int client_fd, const char *msg, __u32 invoked, + __u32 dsack_dups, __u32 delivered, __u32 delivered_ce, + __u32 icsk_retransmits) +@@ -149,6 +174,11 @@ static int run_test(int cgroup_fd, int s + /*icsk_retransmits=*/0); + + send_byte(client_fd); ++ if (wait_for_ack(client_fd, 100) < 0) { ++ err = -1; ++ goto close_client_fd; ++ } ++ + + err += verify_sk(map_fd, client_fd, "first payload byte", + /*invoked=*/2, +@@ -157,6 +187,7 @@ static int run_test(int cgroup_fd, int s + /*delivered_ce=*/0, + /*icsk_retransmits=*/0); + ++close_client_fd: + close(client_fd); + + close_bpf_object: diff --git a/patches.suse/selftests-bpf-improve-unexpected-success-reporting-i.patch b/patches.suse/selftests-bpf-improve-unexpected-success-reporting-i.patch new file mode 100644 index 0000000..5d38c06 --- /dev/null +++ b/patches.suse/selftests-bpf-improve-unexpected-success-reporting-i.patch @@ -0,0 +1,39 @@ +From: Ilya Leoshkevich +Date: Fri, 30 Aug 2019 13:07:31 +0200 +Subject: selftests/bpf: improve unexpected success reporting in test_syctl +Patch-mainline: v5.4-rc1 +Git-commit: 416c572821841bef2cbb6346fb559901efff4ff3 +References: bsc#1155518 + +When tests fail because sysctl() unexpectedly succeeds, they print an +inappropriate "Unexpected failure" message and a random errno. Zero +out errno before calling sysctl() and replace the message with +"Unexpected success". + +Fixes: 1f5fa9ab6e2e ("selftests/bpf: Test BPF_CGROUP_SYSCTL") +Signed-off-by: Ilya Leoshkevich +Signed-off-by: Daniel Borkmann +Acked-by: Gary Lin +--- + tools/testing/selftests/bpf/test_sysctl.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/tools/testing/selftests/bpf/test_sysctl.c ++++ b/tools/testing/selftests/bpf/test_sysctl.c +@@ -1499,6 +1499,7 @@ static int run_test_case(int cgfd, struc + goto err; + } + ++ errno = 0; + if (access_sysctl(sysctl_path, test) == -1) { + if (test->result == OP_EPERM && errno == EPERM) + goto out; +@@ -1507,7 +1508,7 @@ static int run_test_case(int cgfd, struc + } + + if (test->result != SUCCESS) { +- log_err("Unexpected failure"); ++ log_err("Unexpected success"); + goto err; + } + diff --git a/patches.suse/selftests-bpf-introduce-bpf_cpu_to_be64-and-bpf_be64.patch b/patches.suse/selftests-bpf-introduce-bpf_cpu_to_be64-and-bpf_be64.patch new file mode 100644 index 0000000..b0d58fd --- /dev/null +++ b/patches.suse/selftests-bpf-introduce-bpf_cpu_to_be64-and-bpf_be64.patch @@ -0,0 +1,127 @@ +From: Ilya Leoshkevich +Date: Fri, 30 Aug 2019 13:07:29 +0200 +Subject: selftests/bpf: introduce bpf_cpu_to_be64 and bpf_be64_to_cpu +Patch-mainline: v5.4-rc1 +Git-commit: b9632679944307f3caab183fa69a4d79ffeb40ce +References: bsc#1155518 + +test_lwt_seg6local and test_seg6_loop use custom 64-bit endianness +conversion macros. Centralize their definitions in bpf_endian.h in order +to reduce code duplication. This will also be useful when bpf_endian.h +is promoted to an offical libbpf header. + +Signed-off-by: Ilya Leoshkevich +Signed-off-by: Daniel Borkmann +Acked-by: Gary Lin +--- + tools/testing/selftests/bpf/bpf_endian.h | 14 ++++++++++++++ + tools/testing/selftests/bpf/progs/test_lwt_seg6local.c | 16 ++++++---------- + tools/testing/selftests/bpf/progs/test_seg6_loop.c | 8 ++------ + 3 files changed, 22 insertions(+), 16 deletions(-) + +--- a/tools/testing/selftests/bpf/bpf_endian.h ++++ b/tools/testing/selftests/bpf/bpf_endian.h +@@ -29,6 +29,10 @@ + # define __bpf_htonl(x) __builtin_bswap32(x) + # define __bpf_constant_ntohl(x) ___constant_swab32(x) + # define __bpf_constant_htonl(x) ___constant_swab32(x) ++# define __bpf_be64_to_cpu(x) __builtin_bswap64(x) ++# define __bpf_cpu_to_be64(x) __builtin_bswap64(x) ++# define __bpf_constant_be64_to_cpu(x) ___constant_swab64(x) ++# define __bpf_constant_cpu_to_be64(x) ___constant_swab64(x) + #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + # define __bpf_ntohs(x) (x) + # define __bpf_htons(x) (x) +@@ -38,6 +42,10 @@ + # define __bpf_htonl(x) (x) + # define __bpf_constant_ntohl(x) (x) + # define __bpf_constant_htonl(x) (x) ++# define __bpf_be64_to_cpu(x) (x) ++# define __bpf_cpu_to_be64(x) (x) ++# define __bpf_constant_be64_to_cpu(x) (x) ++# define __bpf_constant_cpu_to_be64(x) (x) + #else + # error "Fix your compiler's __BYTE_ORDER__?!" + #endif +@@ -54,5 +62,11 @@ + #define bpf_ntohl(x) \ + (__builtin_constant_p(x) ? \ + __bpf_constant_ntohl(x) : __bpf_ntohl(x)) ++#define bpf_cpu_to_be64(x) \ ++ (__builtin_constant_p(x) ? \ ++ __bpf_constant_cpu_to_be64(x) : __bpf_cpu_to_be64(x)) ++#define bpf_be64_to_cpu(x) \ ++ (__builtin_constant_p(x) ? \ ++ __bpf_constant_be64_to_cpu(x) : __bpf_be64_to_cpu(x)) + + #endif /* __BPF_ENDIAN__ */ +--- a/tools/testing/selftests/bpf/progs/test_lwt_seg6local.c ++++ b/tools/testing/selftests/bpf/progs/test_lwt_seg6local.c +@@ -12,10 +12,6 @@ + + #define SR6_FLAG_ALERT (1 << 4) + +-#define htonll(x) ((bpf_htonl(1)) == 1 ? (x) : ((uint64_t)bpf_htonl((x) & \ +- 0xFFFFFFFF) << 32) | bpf_htonl((x) >> 32)) +-#define ntohll(x) ((bpf_ntohl(1)) == 1 ? (x) : ((uint64_t)bpf_ntohl((x) & \ +- 0xFFFFFFFF) << 32) | bpf_ntohl((x) >> 32)) + #define BPF_PACKET_HEADER __attribute__((packed)) + + struct ip6_t { +@@ -276,8 +272,8 @@ int has_egr_tlv(struct __sk_buff *skb, s + return 0; + + // check if egress TLV value is correct +- if (ntohll(egr_addr.hi) == 0xfd00000000000000 && +- ntohll(egr_addr.lo) == 0x4) ++ if (bpf_be64_to_cpu(egr_addr.hi) == 0xfd00000000000000 && ++ bpf_be64_to_cpu(egr_addr.lo) == 0x4) + return 1; + } + +@@ -308,8 +304,8 @@ int __encap_srh(struct __sk_buff *skb) + + #pragma clang loop unroll(full) + for (unsigned long long lo = 0; lo < 4; lo++) { +- seg->lo = htonll(4 - lo); +- seg->hi = htonll(hi); ++ seg->lo = bpf_cpu_to_be64(4 - lo); ++ seg->hi = bpf_cpu_to_be64(hi); + seg = (struct ip6_addr_t *)((char *)seg + sizeof(*seg)); + } + +@@ -349,8 +345,8 @@ int __add_egr_x(struct __sk_buff *skb) + if (err) + return BPF_DROP; + +- addr.lo = htonll(lo); +- addr.hi = htonll(hi); ++ addr.lo = bpf_cpu_to_be64(lo); ++ addr.hi = bpf_cpu_to_be64(hi); + err = bpf_lwt_seg6_action(skb, SEG6_LOCAL_ACTION_END_X, + (void *)&addr, sizeof(addr)); + if (err) +--- a/tools/testing/selftests/bpf/progs/test_seg6_loop.c ++++ b/tools/testing/selftests/bpf/progs/test_seg6_loop.c +@@ -12,10 +12,6 @@ + + #define SR6_FLAG_ALERT (1 << 4) + +-#define htonll(x) ((bpf_htonl(1)) == 1 ? (x) : ((uint64_t)bpf_htonl((x) & \ +- 0xFFFFFFFF) << 32) | bpf_htonl((x) >> 32)) +-#define ntohll(x) ((bpf_ntohl(1)) == 1 ? (x) : ((uint64_t)bpf_ntohl((x) & \ +- 0xFFFFFFFF) << 32) | bpf_ntohl((x) >> 32)) + #define BPF_PACKET_HEADER __attribute__((packed)) + + struct ip6_t { +@@ -251,8 +247,8 @@ int __add_egr_x(struct __sk_buff *skb) + if (err) + return BPF_DROP; + +- addr.lo = htonll(lo); +- addr.hi = htonll(hi); ++ addr.lo = bpf_cpu_to_be64(lo); ++ addr.hi = bpf_cpu_to_be64(hi); + err = bpf_lwt_seg6_action(skb, SEG6_LOCAL_ACTION_END_X, + (void *)&addr, sizeof(addr)); + if (err) diff --git a/patches.suse/tools-bpftool-fix-argument-for-p_err-in-BTF-do_dump.patch b/patches.suse/tools-bpftool-fix-argument-for-p_err-in-BTF-do_dump.patch new file mode 100644 index 0000000..72bf9e0 --- /dev/null +++ b/patches.suse/tools-bpftool-fix-argument-for-p_err-in-BTF-do_dump.patch @@ -0,0 +1,32 @@ +From: Quentin Monnet +Date: Thu, 15 Aug 2019 15:32:17 +0100 +Subject: tools: bpftool: fix argument for p_err() in BTF do_dump() +Patch-mainline: v5.4-rc1 +Git-commit: ed4a3983cd3eb93aaf80de8d8a36efed808acff2 +References: bsc#1155518 + +The last argument passed to one call to the p_err() function is not +correct, it should be "*argv" instead of "**argv". This may lead to a +segmentation fault error if BTF id cannot be parsed correctly. Let's fix +this. + +Fixes: c93cc69004dt ("bpftool: add ability to dump BTF types") +Signed-off-by: Quentin Monnet +Reviewed-by: Jakub Kicinski +Signed-off-by: Alexei Starovoitov +Acked-by: Gary Lin +--- + tools/bpf/bpftool/btf.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/tools/bpf/bpftool/btf.c ++++ b/tools/bpf/bpftool/btf.c +@@ -449,7 +449,7 @@ static int do_dump(int argc, char **argv + + btf_id = strtoul(*argv, &endptr, 0); + if (*endptr) { +- p_err("can't parse %s as ID", **argv); ++ p_err("can't parse %s as ID", *argv); + return -1; + } + NEXT_ARG(); diff --git a/patches.suse/tools-bpftool-fix-arguments-for-p_err-in-do_event_pi.patch b/patches.suse/tools-bpftool-fix-arguments-for-p_err-in-do_event_pi.patch new file mode 100644 index 0000000..e15bec9 --- /dev/null +++ b/patches.suse/tools-bpftool-fix-arguments-for-p_err-in-do_event_pi.patch @@ -0,0 +1,41 @@ +From: Quentin Monnet +Date: Thu, 15 Aug 2019 15:32:15 +0100 +Subject: tools: bpftool: fix arguments for p_err() in do_event_pipe() +Patch-mainline: v5.4-rc1 +Git-commit: 9def249dc8409ffc1f5a1d7195f1c462f2b49c07 +References: bsc#1155518 + +The last argument passed to some calls to the p_err() functions is not +correct, it should be "*argv" instead of "**argv". This may lead to a +segmentation fault error if CPU IDs or indices from the command line +cannot be parsed correctly. Let's fix this. + +Fixes: f412eed9dfde ("tools: bpftool: add simple perf event output reader") +Signed-off-by: Quentin Monnet +Reviewed-by: Jakub Kicinski +Signed-off-by: Alexei Starovoitov +Acked-by: Gary Lin +--- + tools/bpf/bpftool/map_perf_ring.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--- a/tools/bpf/bpftool/map_perf_ring.c ++++ b/tools/bpf/bpftool/map_perf_ring.c +@@ -157,7 +157,7 @@ int do_event_pipe(int argc, char **argv) + NEXT_ARG(); + ctx.cpu = strtoul(*argv, &endptr, 0); + if (*endptr) { +- p_err("can't parse %s as CPU ID", **argv); ++ p_err("can't parse %s as CPU ID", *argv); + goto err_close_map; + } + +@@ -168,7 +168,7 @@ int do_event_pipe(int argc, char **argv) + NEXT_ARG(); + ctx.idx = strtoul(*argv, &endptr, 0); + if (*endptr) { +- p_err("can't parse %s as index", **argv); ++ p_err("can't parse %s as index", *argv); + goto err_close_map; + } + diff --git a/patches.suse/tools-bpftool-fix-format-string-for-p_err-in-detect_.patch b/patches.suse/tools-bpftool-fix-format-string-for-p_err-in-detect_.patch new file mode 100644 index 0000000..9cfc842 --- /dev/null +++ b/patches.suse/tools-bpftool-fix-format-string-for-p_err-in-detect_.patch @@ -0,0 +1,34 @@ +From: Quentin Monnet +Date: Thu, 15 Aug 2019 15:32:19 +0100 +Subject: tools: bpftool: fix format string for p_err() in + detect_common_prefix() +Patch-mainline: v5.4-rc1 +Git-commit: b0ead6d75a5b335287337e602e6b815e1115481c +References: bsc#1155518 + +There is one call to the p_err() function in detect_common_prefix() +where the message to print is passed directly as the first argument, +without using a format string. This is harmless, but may trigger +warnings if the "__printf()" attribute is used correctly for the p_err() +function. Let's fix it by using a "%s" format string. + +Fixes: ba95c7452439 ("tools: bpftool: add "prog run" subcommand to test-run programs") +Signed-off-by: Quentin Monnet +Reviewed-by: Jakub Kicinski +Signed-off-by: Alexei Starovoitov +Acked-by: Gary Lin +--- + tools/bpf/bpftool/main.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/tools/bpf/bpftool/main.c ++++ b/tools/bpf/bpftool/main.c +@@ -139,7 +139,7 @@ int detect_common_prefix(const char *arg + strncat(msg, "'", sizeof(msg) - strlen(msg) - 1); + + if (count >= 2) { +- p_err(msg); ++ p_err("%s", msg); + return -1; + } + diff --git a/patches.suse/tools-bpftool-fix-format-string-for-p_err-in-query_f.patch b/patches.suse/tools-bpftool-fix-format-string-for-p_err-in-query_f.patch new file mode 100644 index 0000000..cd02e8d --- /dev/null +++ b/patches.suse/tools-bpftool-fix-format-string-for-p_err-in-query_f.patch @@ -0,0 +1,34 @@ +From: Quentin Monnet +Date: Thu, 15 Aug 2019 15:32:18 +0100 +Subject: tools: bpftool: fix format string for p_err() in + query_flow_dissector() +Patch-mainline: v5.4-rc1 +Git-commit: 8a15d5ced8c626c0331974c7281c1d651f7b0d83 +References: bsc#1155518 + +The format string passed to one call to the p_err() function in +query_flow_dissector() does not match the value that should be printed, +resulting in some garbage integer being printed instead of +strerror(errno) if /proc/self/ns/net cannot be open. Let's fix the +format string. + +Fixes: 7f0c57fec80f ("bpftool: show flow_dissector attachment status") +Signed-off-by: Quentin Monnet +Reviewed-by: Jakub Kicinski +Signed-off-by: Alexei Starovoitov +Acked-by: Gary Lin +--- + tools/bpf/bpftool/net.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/tools/bpf/bpftool/net.c ++++ b/tools/bpf/bpftool/net.c +@@ -197,7 +197,7 @@ static int query_flow_dissector(struct b + + fd = open("/proc/self/ns/net", O_RDONLY); + if (fd < 0) { +- p_err("can't open /proc/self/ns/net: %d", ++ p_err("can't open /proc/self/ns/net: %s", + strerror(errno)); + return -1; + } diff --git a/patches.suse/tools-bpftool-fix-format-strings-and-arguments-for-j.patch b/patches.suse/tools-bpftool-fix-format-strings-and-arguments-for-j.patch new file mode 100644 index 0000000..5fdfa84 --- /dev/null +++ b/patches.suse/tools-bpftool-fix-format-strings-and-arguments-for-j.patch @@ -0,0 +1,53 @@ +From: Quentin Monnet +Date: Thu, 15 Aug 2019 15:32:16 +0100 +Subject: tools: bpftool: fix format strings and arguments for jsonw_printf() +Patch-mainline: v5.4-rc1 +Git-commit: 22c349e8db89df86804d3ba23cef037ccd44a8bf +References: bsc#1155518 + +There are some mismatches between format strings and arguments passed to +jsonw_printf() in the BTF dumper for bpftool, which seems harmless but +may result in warnings if the "__printf()" attribute is used correctly +for jsonw_printf(). Let's fix relevant format strings and type cast. + +Fixes: b12d6ec09730 ("bpf: btf: add btf print functionality") +Signed-off-by: Quentin Monnet +Reviewed-by: Jakub Kicinski +Signed-off-by: Alexei Starovoitov +Acked-by: Gary Lin +--- + tools/bpf/bpftool/btf_dumper.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +--- a/tools/bpf/bpftool/btf_dumper.c ++++ b/tools/bpf/bpftool/btf_dumper.c +@@ -26,9 +26,9 @@ static void btf_dumper_ptr(const void *d + bool is_plain_text) + { + if (is_plain_text) +- jsonw_printf(jw, "%p", *(unsigned long *)data); ++ jsonw_printf(jw, "%p", data); + else +- jsonw_printf(jw, "%u", *(unsigned long *)data); ++ jsonw_printf(jw, "%lu", *(unsigned long *)data); + } + + static int btf_dumper_modifier(const struct btf_dumper *d, __u32 type_id, +@@ -216,7 +216,7 @@ static int btf_dumper_int(const struct b + switch (BTF_INT_ENCODING(*int_type)) { + case 0: + if (BTF_INT_BITS(*int_type) == 64) +- jsonw_printf(jw, "%lu", *(__u64 *)data); ++ jsonw_printf(jw, "%llu", *(__u64 *)data); + else if (BTF_INT_BITS(*int_type) == 32) + jsonw_printf(jw, "%u", *(__u32 *)data); + else if (BTF_INT_BITS(*int_type) == 16) +@@ -229,7 +229,7 @@ static int btf_dumper_int(const struct b + break; + case BTF_INT_SIGNED: + if (BTF_INT_BITS(*int_type) == 64) +- jsonw_printf(jw, "%ld", *(long long *)data); ++ jsonw_printf(jw, "%lld", *(long long *)data); + else if (BTF_INT_BITS(*int_type) == 32) + jsonw_printf(jw, "%d", *(int *)data); + else if (BTF_INT_BITS(*int_type) == 16) diff --git a/patches.suse/tools-bpftool-move-__printf-attributes-to-header-fil.patch b/patches.suse/tools-bpftool-move-__printf-attributes-to-header-fil.patch new file mode 100644 index 0000000..585a97a --- /dev/null +++ b/patches.suse/tools-bpftool-move-__printf-attributes-to-header-fil.patch @@ -0,0 +1,132 @@ +From: Quentin Monnet +Date: Thu, 15 Aug 2019 15:32:20 +0100 +Subject: tools: bpftool: move "__printf()" attributes to header file +Patch-mainline: v5.4-rc1 +Git-commit: 8918dc42dc85ba6981028f65a989c478eb80bc02 +References: bsc#1155518 + +Some functions in bpftool have a "__printf()" format attributes to tell +the compiler they should expect printf()-like arguments. But because +these attributes are not used for the function prototypes in the header +files, the compiler does not run the checks everywhere the functions are +used, and some mistakes on format string and corresponding arguments +slipped in over time. + +Let's move the __printf() attributes to the correct places. + +Note: We add guards around the definition of GCC_VERSION in +tools/include/linux/compiler-gcc.h to prevent a conflict in jit_disasm.c +on GCC_VERSION from headers pulled via libbfd. + +Fixes: c101189bc968 ("tools: bpftool: fix -Wmissing declaration warnings") +Reported-by: Jakub Kicinski +Signed-off-by: Quentin Monnet +Reviewed-by: Jakub Kicinski +Signed-off-by: Alexei Starovoitov +Acked-by: Gary Lin +--- + tools/bpf/bpftool/common.c | 4 ++-- + tools/bpf/bpftool/json_writer.c | 6 ++---- + tools/bpf/bpftool/json_writer.h | 6 ++++-- + tools/bpf/bpftool/main.h | 4 ++-- + tools/include/linux/compiler-gcc.h | 2 ++ + 5 files changed, 12 insertions(+), 10 deletions(-) + +--- a/tools/bpf/bpftool/common.c ++++ b/tools/bpf/bpftool/common.c +@@ -29,7 +29,7 @@ + #define BPF_FS_MAGIC 0xcafe4a11 + #endif + +-void __printf(1, 2) p_err(const char *fmt, ...) ++void p_err(const char *fmt, ...) + { + va_list ap; + +@@ -47,7 +47,7 @@ void __printf(1, 2) p_err(const char *fm + va_end(ap); + } + +-void __printf(1, 2) p_info(const char *fmt, ...) ++void p_info(const char *fmt, ...) + { + va_list ap; + +--- a/tools/bpf/bpftool/json_writer.c ++++ b/tools/bpf/bpftool/json_writer.c +@@ -15,7 +15,6 @@ + #include + #include + #include +-#include + + #include "json_writer.h" + +@@ -153,8 +152,7 @@ void jsonw_name(json_writer_t *self, con + putc(' ', self->out); + } + +-void __printf(2, 0) +-jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap) ++void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap) + { + jsonw_eor(self); + putc('"', self->out); +@@ -162,7 +160,7 @@ jsonw_vprintf_enquote(json_writer_t *sel + putc('"', self->out); + } + +-void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...) ++void jsonw_printf(json_writer_t *self, const char *fmt, ...) + { + va_list ap; + +--- a/tools/bpf/bpftool/json_writer.h ++++ b/tools/bpf/bpftool/json_writer.h +@@ -14,6 +14,7 @@ + #include + #include + #include ++#include + + /* Opaque class structure */ + typedef struct json_writer json_writer_t; +@@ -30,8 +31,9 @@ void jsonw_pretty(json_writer_t *self, b + void jsonw_name(json_writer_t *self, const char *name); + + /* Add value */ +-void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap); +-void jsonw_printf(json_writer_t *self, const char *fmt, ...); ++void __printf(2, 0) jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, ++ va_list ap); ++void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...); + void jsonw_string(json_writer_t *self, const char *value); + void jsonw_bool(json_writer_t *self, bool value); + void jsonw_float(json_writer_t *self, double number); +--- a/tools/bpf/bpftool/main.h ++++ b/tools/bpf/bpftool/main.h +@@ -98,8 +98,8 @@ extern int bpf_flags; + extern struct pinned_obj_table prog_table; + extern struct pinned_obj_table map_table; + +-void p_err(const char *fmt, ...); +-void p_info(const char *fmt, ...); ++void __printf(1, 2) p_err(const char *fmt, ...); ++void __printf(1, 2) p_info(const char *fmt, ...); + + bool is_prefix(const char *pfx, const char *str); + int detect_common_prefix(const char *arg, ...); +--- a/tools/include/linux/compiler-gcc.h ++++ b/tools/include/linux/compiler-gcc.h +@@ -6,9 +6,11 @@ + /* + * Common definitions for all gcc versions go here. + */ ++#ifndef GCC_VERSION + #define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) ++#endif + + #if GCC_VERSION >= 70000 && !defined(__CHECKER__) + # define __fallthrough __attribute__ ((fallthrough)) diff --git a/series.conf b/series.conf index cc8ce86..ed1515c 100644 --- a/series.conf +++ b/series.conf @@ -1089,6 +1089,12 @@ patches.suse/net-hns3-make-hclge_dbg_get_m7_stats_info-static.patch patches.suse/tools-bpftool-compile-with-EXTRA_WARNINGS.patch patches.suse/libbpf-make-libbpf.map-source-of-truth-for-libbpf-ve.patch + patches.suse/tools-bpftool-fix-arguments-for-p_err-in-do_event_pi.patch + patches.suse/tools-bpftool-fix-format-strings-and-arguments-for-j.patch + patches.suse/tools-bpftool-fix-argument-for-p_err-in-BTF-do_dump.patch + patches.suse/tools-bpftool-fix-format-string-for-p_err-in-query_f.patch + patches.suse/tools-bpftool-fix-format-string-for-p_err-in-detect_.patch + patches.suse/tools-bpftool-move-__printf-attributes-to-header-fil.patch patches.suse/btf-fix-return-value-check-in-btf_vmlinux_init.patch patches.suse/xsk-replace-ndo_xsk_async_xmit-with-ndo_xsk_wakeup.patch patches.suse/xsk-add-support-for-need_wakeup-flag-in-AF_XDP-rings.patch @@ -1098,6 +1104,7 @@ patches.suse/net-mlx5e-Move-the-SW-XSK-code-from-NAPI-poll-to-a-s.patch patches.suse/net-mlx5e-Add-AF_XDP-need_wakeup-support.patch patches.suse/net-Don-t-call-XDP_SETUP_PROG-when-nothing-is-change.patch + patches.suse/selftests-bpf-fix-race-in-test_tcp_rtt-test.patch patches.suse/bpf-export-bpf_map_inc_not_zero.patch patches.suse/bpf-support-cloning-sk-storage-on-accept.patch patches.suse/bpf-sync-bpf.h-to-tools-9e819ffc.patch @@ -1129,6 +1136,10 @@ patches.suse/mlx5e-modify-driver-for-handling-offsets.patch patches.suse/net-mlx5e-Allow-XSK-frames-smaller-than-a-page.patch patches.suse/libbpf-add-flags-to-umem-config.patch + patches.suse/selftests-bpf-introduce-bpf_cpu_to_be64-and-bpf_be64.patch + patches.suse/selftests-bpf-fix-ctx-write-sysctl-write-read-ok-on-.patch + patches.suse/selftests-bpf-improve-unexpected-success-reporting-i.patch + patches.suse/selftests-bpf-fix-endianness-issues-in-test_sysctl.patch patches.suse/i40e-fix-xdp-handle-calculations.patch patches.suse/ixgbe-fix-xdp-handle-calculations.patch patches.suse/xsk-avoid-store-tearing-when-assigning-queues.patch @@ -2658,6 +2669,8 @@ patches.suse/net-silence-KCSAN-warnings-about-sk-sk_backlog.len-r.patch patches.suse/rxrpc-Fix-possible-NULL-pointer-access-in-ICMP-handl.patch patches.suse/xsk-Fix-crash-in-poll-when-device-does-not-support-n.patch + patches.suse/selftests-bpf-Set-rp_filter-in-test_flow_dissector.patch + patches.suse/selftests-bpf-More-compatible-nc-options-in-test_lwt.patch patches.suse/tcp-add-rcu-protection-around-tp-fastopen_rsk.patch patches.suse/tcp-annotate-tp-rcv_nxt-lockless-reads.patch patches.suse/tcp-annotate-tp-copied_seq-lockless-reads.patch