提交 472f8501 编写于 作者: F Felix Maurer 提交者: Zheng Zengkai

selftests: bpf: Check bpf_msg_push_data return value

stable inclusion
from stable-v5.10.103
commit 4f5d47e6b43f518f0bafbab1a1343d8b410a11b6
bugzilla: https://gitee.com/openeuler/kernel/issues/I56NE7

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4f5d47e6b43f518f0bafbab1a1343d8b410a11b6

--------------------------------

commit 61d06f01 upstream.

bpf_msg_push_data may return a non-zero value to indicate an error. The
return value should be checked to prevent undetected errors.

To indicate an error, the BPF programs now perform a different action
than their intended one to make the userspace test program notice the
error, i.e., the programs supposed to pass/redirect drop, the program
supposed to drop passes.

Fixes: 84fbfe02 ("bpf: test_sockmap add options to use msg_push_data")
Signed-off-by: NFelix Maurer <fmaurer@redhat.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/89f767bb44005d6b4dd1f42038c438f76b3ebfad.1644601294.git.fmaurer@redhat.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYu Liao <liaoyu15@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 460f13e1
...@@ -235,7 +235,7 @@ SEC("sk_msg1") ...@@ -235,7 +235,7 @@ SEC("sk_msg1")
int bpf_prog4(struct sk_msg_md *msg) int bpf_prog4(struct sk_msg_md *msg)
{ {
int *bytes, zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5; int *bytes, zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5;
int *start, *end, *start_push, *end_push, *start_pop, *pop; int *start, *end, *start_push, *end_push, *start_pop, *pop, err = 0;
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero); bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
if (bytes) if (bytes)
...@@ -249,8 +249,11 @@ int bpf_prog4(struct sk_msg_md *msg) ...@@ -249,8 +249,11 @@ int bpf_prog4(struct sk_msg_md *msg)
bpf_msg_pull_data(msg, *start, *end, 0); bpf_msg_pull_data(msg, *start, *end, 0);
start_push = bpf_map_lookup_elem(&sock_bytes, &two); start_push = bpf_map_lookup_elem(&sock_bytes, &two);
end_push = bpf_map_lookup_elem(&sock_bytes, &three); end_push = bpf_map_lookup_elem(&sock_bytes, &three);
if (start_push && end_push) if (start_push && end_push) {
bpf_msg_push_data(msg, *start_push, *end_push, 0); err = bpf_msg_push_data(msg, *start_push, *end_push, 0);
if (err)
return SK_DROP;
}
start_pop = bpf_map_lookup_elem(&sock_bytes, &four); start_pop = bpf_map_lookup_elem(&sock_bytes, &four);
pop = bpf_map_lookup_elem(&sock_bytes, &five); pop = bpf_map_lookup_elem(&sock_bytes, &five);
if (start_pop && pop) if (start_pop && pop)
...@@ -263,6 +266,7 @@ int bpf_prog6(struct sk_msg_md *msg) ...@@ -263,6 +266,7 @@ int bpf_prog6(struct sk_msg_md *msg)
{ {
int zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5, key = 0; int zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5, key = 0;
int *bytes, *start, *end, *start_push, *end_push, *start_pop, *pop, *f; int *bytes, *start, *end, *start_push, *end_push, *start_pop, *pop, *f;
int err = 0;
__u64 flags = 0; __u64 flags = 0;
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero); bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
...@@ -279,8 +283,11 @@ int bpf_prog6(struct sk_msg_md *msg) ...@@ -279,8 +283,11 @@ int bpf_prog6(struct sk_msg_md *msg)
start_push = bpf_map_lookup_elem(&sock_bytes, &two); start_push = bpf_map_lookup_elem(&sock_bytes, &two);
end_push = bpf_map_lookup_elem(&sock_bytes, &three); end_push = bpf_map_lookup_elem(&sock_bytes, &three);
if (start_push && end_push) if (start_push && end_push) {
bpf_msg_push_data(msg, *start_push, *end_push, 0); err = bpf_msg_push_data(msg, *start_push, *end_push, 0);
if (err)
return SK_DROP;
}
start_pop = bpf_map_lookup_elem(&sock_bytes, &four); start_pop = bpf_map_lookup_elem(&sock_bytes, &four);
pop = bpf_map_lookup_elem(&sock_bytes, &five); pop = bpf_map_lookup_elem(&sock_bytes, &five);
...@@ -338,7 +345,7 @@ SEC("sk_msg5") ...@@ -338,7 +345,7 @@ SEC("sk_msg5")
int bpf_prog10(struct sk_msg_md *msg) int bpf_prog10(struct sk_msg_md *msg)
{ {
int *bytes, *start, *end, *start_push, *end_push, *start_pop, *pop; int *bytes, *start, *end, *start_push, *end_push, *start_pop, *pop;
int zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5; int zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5, err = 0;
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero); bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
if (bytes) if (bytes)
...@@ -352,8 +359,11 @@ int bpf_prog10(struct sk_msg_md *msg) ...@@ -352,8 +359,11 @@ int bpf_prog10(struct sk_msg_md *msg)
bpf_msg_pull_data(msg, *start, *end, 0); bpf_msg_pull_data(msg, *start, *end, 0);
start_push = bpf_map_lookup_elem(&sock_bytes, &two); start_push = bpf_map_lookup_elem(&sock_bytes, &two);
end_push = bpf_map_lookup_elem(&sock_bytes, &three); end_push = bpf_map_lookup_elem(&sock_bytes, &three);
if (start_push && end_push) if (start_push && end_push) {
bpf_msg_push_data(msg, *start_push, *end_push, 0); err = bpf_msg_push_data(msg, *start_push, *end_push, 0);
if (err)
return SK_PASS;
}
start_pop = bpf_map_lookup_elem(&sock_bytes, &four); start_pop = bpf_map_lookup_elem(&sock_bytes, &four);
pop = bpf_map_lookup_elem(&sock_bytes, &five); pop = bpf_map_lookup_elem(&sock_bytes, &five);
if (start_pop && pop) if (start_pop && pop)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册