forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpf: add test_run support for netfilter program type
also extend prog_tests with a small retval test: values other than accept or drop (0, 1) will cause issues. NF_QUEUE could be implemented later if we can guarantee that attachment of such programs can be rejected if they get attached to a pf/hook that doesn't support async reinjection. NF_STOLEN could be implemented via trusted helpers that can guarantee that the skb will eventually be free'd. $ ./test_progs --allow=verifier_netfilter_retcode torvalds#278/1 verifier_netfilter_retcode/bpf_exit with invalid return code. test1:OK torvalds#278/2 verifier_netfilter_retcode/bpf_exit with valid return code. test2:OK torvalds#278/3 verifier_netfilter_retcode/bpf_exit with valid return code. test3:OK torvalds#278/4 verifier_netfilter_retcode/bpf_exit with invalid return code. test4:OK torvalds#278 verifier_netfilter_retcode:OK Signed-off-by: Florian Westphal <[email protected]>
- Loading branch information
1 parent
f959458
commit df8ec6d
Showing
5 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tools/testing/selftests/bpf/progs/verifier_netfilter_retcode.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
#include <linux/bpf.h> | ||
#include <bpf/bpf_helpers.h> | ||
#include "bpf_misc.h" | ||
|
||
SEC("netfilter") | ||
__description("bpf_exit with invalid return code. test1") | ||
__failure __msg("R0 is not a known value") | ||
__naked void with_invalid_return_code_test1(void) | ||
{ | ||
asm volatile (" \ | ||
r0 = *(u64*)(r1 + 0); \ | ||
exit; \ | ||
" ::: __clobber_all); | ||
} | ||
|
||
SEC("netfilter") | ||
__description("bpf_exit with valid return code. test2") | ||
__success | ||
__naked void with_valid_return_code_test2(void) | ||
{ | ||
asm volatile (" \ | ||
r0 = 0; \ | ||
exit; \ | ||
" ::: __clobber_all); | ||
} | ||
|
||
SEC("netfilter") | ||
__description("bpf_exit with valid return code. test3") | ||
__success | ||
__naked void with_valid_return_code_test3(void) | ||
{ | ||
asm volatile (" \ | ||
r0 = 1; \ | ||
exit; \ | ||
" ::: __clobber_all); | ||
} | ||
|
||
SEC("netfilter") | ||
__description("bpf_exit with invalid return code. test4") | ||
__failure __msg("R0 has value (0x2; 0x0)") | ||
__naked void with_invalid_return_code_test4(void) | ||
{ | ||
asm volatile (" \ | ||
r0 = 2; \ | ||
exit; \ | ||
" ::: __clobber_all); | ||
} |