All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: filter: fix nlattr and nlattr_nest BPF tests
@ 2014-06-07  0:48 Alexei Starovoitov
  2014-06-08 20:07 ` Daniel Borkmann
  2014-06-11  7:13 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2014-06-07  0:48 UTC (permalink / raw)
  To: David S. Miller; +Cc: Daniel Borkmann, netdev

- 'struct nlattr' must be 2 byte aligned
- provide big-endian input data for nlattr/nlattr_nest tests

Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
---
tested on x64, qemu-arm32 and qemu-sparc64

 lib/test_bpf.c |   34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index ea60ad8d5242..c579e0f58818 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -385,7 +385,7 @@ static struct bpf_test tests[] = {
 	{
 		"LD_NLATTR",
 		.u.insns = {
-			BPF_STMT(BPF_LDX | BPF_IMM, 1),
+			BPF_STMT(BPF_LDX | BPF_IMM, 2),
 			BPF_STMT(BPF_MISC | BPF_TXA, 0),
 			BPF_STMT(BPF_LDX | BPF_IMM, 3),
 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
@@ -393,42 +393,50 @@ static struct bpf_test tests[] = {
 			BPF_STMT(BPF_RET | BPF_A, 0)
 		},
 		CLASSIC,
-		{ 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
-		{ { 4, 0 }, { 20, 5 } },
+#ifdef __BIG_ENDIAN
+		{ 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
+#else
+		{ 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
+#endif
+		{ { 4, 0 }, { 20, 6 } },
 	},
 	{
 		"LD_NLATTR_NEST",
 		.u.insns = {
-			BPF_STMT(BPF_LD | BPF_IMM, 1),
+			BPF_STMT(BPF_LD | BPF_IMM, 2),
 			BPF_STMT(BPF_LDX | BPF_IMM, 3),
 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
-			BPF_STMT(BPF_LD | BPF_IMM, 1),
+			BPF_STMT(BPF_LD | BPF_IMM, 2),
 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
-			BPF_STMT(BPF_LD | BPF_IMM, 1),
+			BPF_STMT(BPF_LD | BPF_IMM, 2),
 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
-			BPF_STMT(BPF_LD | BPF_IMM, 1),
+			BPF_STMT(BPF_LD | BPF_IMM, 2),
 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
-			BPF_STMT(BPF_LD | BPF_IMM, 1),
+			BPF_STMT(BPF_LD | BPF_IMM, 2),
 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
-			BPF_STMT(BPF_LD | BPF_IMM, 1),
+			BPF_STMT(BPF_LD | BPF_IMM, 2),
 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
-			BPF_STMT(BPF_LD | BPF_IMM, 1),
+			BPF_STMT(BPF_LD | BPF_IMM, 2),
 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
-			BPF_STMT(BPF_LD | BPF_IMM, 1),
+			BPF_STMT(BPF_LD | BPF_IMM, 2),
 			BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
 				 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
 			BPF_STMT(BPF_RET | BPF_A, 0)
 		},
 		CLASSIC,
-		{ 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
-		{ { 4, 0 }, { 20, 9 } },
+#ifdef __BIG_ENDIAN
+		{ 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
+#else
+		{ 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
+#endif
+		{ { 4, 0 }, { 20, 10 } },
 	},
 	{
 		"LD_PAYLOAD_OFF",
-- 
1.7.9.5

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

* Re: [PATCH net-next] net: filter: fix nlattr and nlattr_nest BPF tests
  2014-06-07  0:48 [PATCH net-next] net: filter: fix nlattr and nlattr_nest BPF tests Alexei Starovoitov
@ 2014-06-08 20:07 ` Daniel Borkmann
  2014-06-11  7:13 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2014-06-08 20:07 UTC (permalink / raw)
  To: Alexei Starovoitov; +Cc: David S. Miller, netdev

On 06/07/2014 02:48 AM, Alexei Starovoitov wrote:
> - 'struct nlattr' must be 2 byte aligned
> - provide big-endian input data for nlattr/nlattr_nest tests
>
> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>

Acked-by: Daniel Borkmann <dborkman@redhat.com>

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

* Re: [PATCH net-next] net: filter: fix nlattr and nlattr_nest BPF tests
  2014-06-07  0:48 [PATCH net-next] net: filter: fix nlattr and nlattr_nest BPF tests Alexei Starovoitov
  2014-06-08 20:07 ` Daniel Borkmann
@ 2014-06-11  7:13 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2014-06-11  7:13 UTC (permalink / raw)
  To: ast; +Cc: dborkman, netdev

From: Alexei Starovoitov <ast@plumgrid.com>
Date: Fri,  6 Jun 2014 17:48:20 -0700

> - 'struct nlattr' must be 2 byte aligned
> - provide big-endian input data for nlattr/nlattr_nest tests
> 
> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>

Applied.

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

end of thread, other threads:[~2014-06-11  7:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-07  0:48 [PATCH net-next] net: filter: fix nlattr and nlattr_nest BPF tests Alexei Starovoitov
2014-06-08 20:07 ` Daniel Borkmann
2014-06-11  7:13 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.