bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] selftest/bpf: testing for multiple logs on REJECT
@ 2021-01-30 22:01 Andrei Matei
  2021-02-01 23:49 ` Song Liu
  2021-02-03 23:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Andrei Matei @ 2021-01-30 22:01 UTC (permalink / raw)
  To: bpf, daniel; +Cc: Andrei Matei

This patch adds support to verifier tests to check for a succession of
verifier log messages on program load failure. This makes the
errstr field work uniformly across REJECT and VERBOSE_ACCEPT checks.

This patch also increases the maximum size of a message in the series of
messages to test from 80 chars to 200 chars. This is in order to keep
existing tests working, which sometimes test for messages larger than 80
chars (which was accepted in the REJECT case, when testing for a single
message, but not in the VERBOSE_ACCEPT case, when testing for possibly
multiple messages).
And example of such a long, checked message is in bounds.c:
"R1 has unknown scalar with mixed signed bounds, pointer arithmetic with
it prohibited for !root"

Signed-off-by: Andrei Matei <andreimatei1@gmail.com>
---
 tools/testing/selftests/bpf/test_verifier.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 59bfa6201d1d..58b5a349d3ba 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -88,6 +88,10 @@ struct bpf_test {
 	int fixup_map_event_output[MAX_FIXUPS];
 	int fixup_map_reuseport_array[MAX_FIXUPS];
 	int fixup_map_ringbuf[MAX_FIXUPS];
+	/* Expected verifier log output for result REJECT or VERBOSE_ACCEPT.
+	 * Can be a tab-separated sequence of expected strings. An empty string
+	 * means no log verification.
+	 */
 	const char *errstr;
 	const char *errstr_unpriv;
 	uint32_t insn_processed;
@@ -995,13 +999,19 @@ static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val,
 	return 0;
 }
 
+/* Returns true if every part of exp (tab-separated) appears in log, in order.
+ *
+ * If exp is an empty string, returns true.
+ */
 static bool cmp_str_seq(const char *log, const char *exp)
 {
-	char needle[80];
+	char needle[200];
 	const char *p, *q;
 	int len;
 
 	do {
+		if (!strlen(exp))
+			break;
 		p = strchr(exp, '\t');
 		if (!p)
 			p = exp + strlen(exp);
@@ -1015,7 +1025,7 @@ static bool cmp_str_seq(const char *log, const char *exp)
 		needle[len] = 0;
 		q = strstr(log, needle);
 		if (!q) {
-			printf("FAIL\nUnexpected verifier log in successful load!\n"
+			printf("FAIL\nUnexpected verifier log!\n"
 			       "EXP: %s\nRES:\n", needle);
 			return false;
 		}
@@ -1130,7 +1140,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
 			printf("FAIL\nUnexpected success to load!\n");
 			goto fail_log;
 		}
-		if (!expected_err || !strstr(bpf_vlog, expected_err)) {
+		if (!expected_err || !cmp_str_seq(bpf_vlog, expected_err)) {
 			printf("FAIL\nUnexpected error message!\n\tEXP: %s\n\tRES: %s\n",
 			      expected_err, bpf_vlog);
 			goto fail_log;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next v2] selftest/bpf: testing for multiple logs on REJECT
  2021-01-30 22:01 [PATCH bpf-next v2] selftest/bpf: testing for multiple logs on REJECT Andrei Matei
@ 2021-02-01 23:49 ` Song Liu
  2021-02-03 23:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Song Liu @ 2021-02-01 23:49 UTC (permalink / raw)
  To: Andrei Matei; +Cc: bpf, Daniel Borkmann

On Sat, Jan 30, 2021 at 2:10 PM Andrei Matei <andreimatei1@gmail.com> wrote:
>
> This patch adds support to verifier tests to check for a succession of
> verifier log messages on program load failure. This makes the
> errstr field work uniformly across REJECT and VERBOSE_ACCEPT checks.
>
> This patch also increases the maximum size of a message in the series of
> messages to test from 80 chars to 200 chars. This is in order to keep
> existing tests working, which sometimes test for messages larger than 80
> chars (which was accepted in the REJECT case, when testing for a single
> message, but not in the VERBOSE_ACCEPT case, when testing for possibly
> multiple messages).
> And example of such a long, checked message is in bounds.c:
> "R1 has unknown scalar with mixed signed bounds, pointer arithmetic with
> it prohibited for !root"
>
> Signed-off-by: Andrei Matei <andreimatei1@gmail.com>

Acked-by: Song Liu <songliubraving@fb.com>

> ---
>  tools/testing/selftests/bpf/test_verifier.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
> index 59bfa6201d1d..58b5a349d3ba 100644
> --- a/tools/testing/selftests/bpf/test_verifier.c
> +++ b/tools/testing/selftests/bpf/test_verifier.c
> @@ -88,6 +88,10 @@ struct bpf_test {
>         int fixup_map_event_output[MAX_FIXUPS];
>         int fixup_map_reuseport_array[MAX_FIXUPS];
>         int fixup_map_ringbuf[MAX_FIXUPS];
> +       /* Expected verifier log output for result REJECT or VERBOSE_ACCEPT.
> +        * Can be a tab-separated sequence of expected strings. An empty string
> +        * means no log verification.
> +        */
>         const char *errstr;
>         const char *errstr_unpriv;
>         uint32_t insn_processed;
> @@ -995,13 +999,19 @@ static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val,
>         return 0;
>  }
>
> +/* Returns true if every part of exp (tab-separated) appears in log, in order.
> + *
> + * If exp is an empty string, returns true.
> + */
>  static bool cmp_str_seq(const char *log, const char *exp)
>  {
> -       char needle[80];
> +       char needle[200];
>         const char *p, *q;
>         int len;
>
>         do {
> +               if (!strlen(exp))
> +                       break;
>                 p = strchr(exp, '\t');
>                 if (!p)
>                         p = exp + strlen(exp);
> @@ -1015,7 +1025,7 @@ static bool cmp_str_seq(const char *log, const char *exp)
>                 needle[len] = 0;
>                 q = strstr(log, needle);
>                 if (!q) {
> -                       printf("FAIL\nUnexpected verifier log in successful load!\n"
> +                       printf("FAIL\nUnexpected verifier log!\n"
>                                "EXP: %s\nRES:\n", needle);
>                         return false;
>                 }
> @@ -1130,7 +1140,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
>                         printf("FAIL\nUnexpected success to load!\n");
>                         goto fail_log;
>                 }
> -               if (!expected_err || !strstr(bpf_vlog, expected_err)) {
> +               if (!expected_err || !cmp_str_seq(bpf_vlog, expected_err)) {
>                         printf("FAIL\nUnexpected error message!\n\tEXP: %s\n\tRES: %s\n",
>                               expected_err, bpf_vlog);
>                         goto fail_log;
> --
> 2.27.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next v2] selftest/bpf: testing for multiple logs on REJECT
  2021-01-30 22:01 [PATCH bpf-next v2] selftest/bpf: testing for multiple logs on REJECT Andrei Matei
  2021-02-01 23:49 ` Song Liu
@ 2021-02-03 23:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-02-03 23:30 UTC (permalink / raw)
  To: Andrei Matei; +Cc: bpf, daniel

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

On Sat, 30 Jan 2021 17:01:50 -0500 you wrote:
> This patch adds support to verifier tests to check for a succession of
> verifier log messages on program load failure. This makes the
> errstr field work uniformly across REJECT and VERBOSE_ACCEPT checks.
> 
> This patch also increases the maximum size of a message in the series of
> messages to test from 80 chars to 200 chars. This is in order to keep
> existing tests working, which sometimes test for messages larger than 80
> chars (which was accepted in the REJECT case, when testing for a single
> message, but not in the VERBOSE_ACCEPT case, when testing for possibly
> multiple messages).
> And example of such a long, checked message is in bounds.c:
> "R1 has unknown scalar with mixed signed bounds, pointer arithmetic with
> it prohibited for !root"
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2] selftest/bpf: testing for multiple logs on REJECT
    https://git.kernel.org/bpf/bpf-next/c/060fd1035880

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-03 23:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-30 22:01 [PATCH bpf-next v2] selftest/bpf: testing for multiple logs on REJECT Andrei Matei
2021-02-01 23:49 ` Song Liu
2021-02-03 23:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).