Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'Improve error handling of verifier tests'

Florian Lehner says:

====================
These patches improve the error handling for verifier tests. With "Test
the 32bit narrow read" Krzesimir Nowak provided these patches first, but
they were never merged.
The improved error handling helps to implement and test BPF program types
that are not supported yet.

v3:
- Add explicit fallthrough

v2:
- Add unpriv check in error validation
====================

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

+25 -6
+25 -6
tools/testing/selftests/bpf/test_verifier.c
··· 875 875 __u8 tmp[TEST_DATA_LEN << 2]; 876 876 __u32 size_tmp = sizeof(tmp); 877 877 uint32_t retval; 878 - int err; 878 + int err, saved_errno; 879 879 880 880 if (unpriv) 881 881 set_admin(true); 882 882 err = bpf_prog_test_run(fd_prog, 1, data, size_data, 883 883 tmp, &size_tmp, &retval, NULL); 884 + saved_errno = errno; 885 + 884 886 if (unpriv) 885 887 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 + } 889 905 } 890 - if (!err && retval != expected_val && 906 + 907 + if (retval != expected_val && 891 908 expected_val != POINTER_VALUE) { 892 909 printf("FAIL retval %d != %d ", retval, expected_val); 893 910 return 1; ··· 953 936 int run_errs, run_successes; 954 937 int map_fds[MAX_NR_MAPS]; 955 938 const char *expected_err; 939 + int saved_errno; 956 940 int fixup_skips; 957 941 __u32 pflags; 958 942 int i, err; ··· 1015 997 } 1016 998 1017 999 fd_prog = bpf_load_program_xattr(&attr, bpf_vlog, sizeof(bpf_vlog)); 1000 + saved_errno = errno; 1018 1001 1019 1002 /* BPF_PROG_TYPE_TRACING requires more setup and 1020 1003 * bpf_probe_prog_type won't give correct answer ··· 1032 1013 if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) { 1033 1014 if (fd_prog < 0) { 1034 1015 printf("FAIL\nFailed to load prog '%s'!\n", 1035 - strerror(errno)); 1016 + strerror(saved_errno)); 1036 1017 goto fail_log; 1037 1018 } 1038 1019 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS