提交 7f2c0811 编写于 作者: F Florian Lehner 提交者: Zheng Zengkai

selftests/bpf: Avoid errno clobbering

mainline inclusion
from mainline-5.11-rc1
commit 5f61b7c6
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5f61b7c6975b03e6ace2cfb13d415d5f475c8830

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

Print a message when the returned error is about a program type being
not supported or because of permission problems.
These messages are expected if the program to test was actually
executed.
Signed-off-by: NFlorian Lehner <dev@der-flo.net>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201204181828.11974-3-dev@der-flo.net
(cherry picked from commit 5f61b7c6)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 bb900295
...@@ -885,19 +885,36 @@ static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val, ...@@ -885,19 +885,36 @@ static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val,
__u8 tmp[TEST_DATA_LEN << 2]; __u8 tmp[TEST_DATA_LEN << 2];
__u32 size_tmp = sizeof(tmp); __u32 size_tmp = sizeof(tmp);
uint32_t retval; uint32_t retval;
int err; int err, saved_errno;
if (unpriv) if (unpriv)
set_admin(true); set_admin(true);
err = bpf_prog_test_run(fd_prog, 1, data, size_data, err = bpf_prog_test_run(fd_prog, 1, data, size_data,
tmp, &size_tmp, &retval, NULL); tmp, &size_tmp, &retval, NULL);
saved_errno = errno;
if (unpriv) if (unpriv)
set_admin(false); set_admin(false);
if (err && errno != 524/*ENOTSUPP*/ && errno != EPERM) {
printf("Unexpected bpf_prog_test_run error "); if (err) {
return err; switch (saved_errno) {
case 524/*ENOTSUPP*/:
printf("Did not run the program (not supported) ");
return 0;
case EPERM:
if (unpriv) {
printf("Did not run the program (no permission) ");
return 0;
}
/* fallthrough; */
default:
printf("FAIL: Unexpected bpf_prog_test_run error (%s) ",
strerror(saved_errno));
return err;
}
} }
if (!err && retval != expected_val &&
if (retval != expected_val &&
expected_val != POINTER_VALUE) { expected_val != POINTER_VALUE) {
printf("FAIL retval %d != %d ", retval, expected_val); printf("FAIL retval %d != %d ", retval, expected_val);
return 1; return 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册