Skip to content

Commit f874472

Browse files
florianlkernel-patches-bot
authored andcommitted
selftests/bpf: Avoid errno clobbering
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. Cc: Krzesimir Nowak <krzesimir@kinvolk.io> Signed-off-by: Florian Lehner <dev@der-flo.net>
1 parent bbc6058 commit f874472

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,19 +875,36 @@ static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val,
875875
__u8 tmp[TEST_DATA_LEN << 2];
876876
__u32 size_tmp = sizeof(tmp);
877877
uint32_t retval;
878-
int err;
878+
int err, saved_errno;
879879

880880
if (unpriv)
881881
set_admin(true);
882882
err = bpf_prog_test_run(fd_prog, 1, data, size_data,
883883
tmp, &size_tmp, &retval, NULL);
884+
saved_errno = errno;
885+
884886
if (unpriv)
885887
set_admin(false);
886-
if (err && errno != 524/*ENOTSUPP*/ && errno != EPERM) {
887-
printf("Unexpected bpf_prog_test_run error ");
888-
return err;
888+
889+
if (err) {
890+
switch (saved_errno) {
891+
case 524/*ENOTSUPP*/:
892+
printf("Did not run the program (not supported) ");
893+
return 0;
894+
case EPERM:
895+
if (unpriv) {
896+
printf("Did not run the program (no permission) ");
897+
return 0;
898+
}
899+
/* fallthrough; */
900+
default:
901+
printf("FAIL: Unexpected bpf_prog_test_run error (%s) ",
902+
strerror(saved_errno));
903+
return err;
904+
}
889905
}
890-
if (!err && retval != expected_val &&
906+
907+
if (retval != expected_val &&
891908
expected_val != POINTER_VALUE) {
892909
printf("FAIL retval %d != %d ", retval, expected_val);
893910
return 1;

0 commit comments

Comments
 (0)