* [PATCH bpf] selftests/bpf: fix "bind{4,6} deny specific IP & port" on s390
@ 2019-08-13 16:21 Ilya Leoshkevich
2019-08-13 19:53 ` Andrii Nakryiko
0 siblings, 1 reply; 2+ messages in thread
From: Ilya Leoshkevich @ 2019-08-13 16:21 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich
"bind4 allow specific IP & port" and "bind6 deny specific IP & port"
fail on s390 because of endianness issue: the 4 IP address bytes are
loaded as a word and compared with a constant, but the value of this
constant should be different on big- and little- endian machines, which
is not the case right now.
Use __constant_ntohl to generate proper value based on machine
endianness.
Fixes: 1d436885b23b ("selftests/bpf: Selftest for sys_bind post-hooks.")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tools/testing/selftests/bpf/test_sock.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_sock.c b/tools/testing/selftests/bpf/test_sock.c
index fb679ac3d4b0..5c092a85125f 100644
--- a/tools/testing/selftests/bpf/test_sock.c
+++ b/tools/testing/selftests/bpf/test_sock.c
@@ -8,6 +8,7 @@
#include <sys/types.h>
#include <sys/socket.h>
+#include <asm/byteorder.h>
#include <linux/filter.h>
#include <bpf/bpf.h>
@@ -232,7 +233,8 @@ static struct sock_test tests[] = {
/* if (ip == expected && port == expected) */
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
offsetof(struct bpf_sock, src_ip6[3])),
- BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 0x01000000, 4),
+ BPF_JMP_IMM(BPF_JNE, BPF_REG_7,
+ __constant_ntohl(0x00000001), 4),
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
offsetof(struct bpf_sock, src_port)),
BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 0x2001, 2),
@@ -261,7 +263,8 @@ static struct sock_test tests[] = {
/* if (ip == expected && port == expected) */
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
offsetof(struct bpf_sock, src_ip4)),
- BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 0x0100007F, 4),
+ BPF_JMP_IMM(BPF_JNE, BPF_REG_7,
+ __constant_ntohl(0x7F000001), 4),
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
offsetof(struct bpf_sock, src_port)),
BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 0x1002, 2),
--
2.21.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf] selftests/bpf: fix "bind{4,6} deny specific IP & port" on s390
2019-08-13 16:21 [PATCH bpf] selftests/bpf: fix "bind{4,6} deny specific IP & port" on s390 Ilya Leoshkevich
@ 2019-08-13 19:53 ` Andrii Nakryiko
0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2019-08-13 19:53 UTC (permalink / raw)
To: Ilya Leoshkevich
Cc: Daniel Borkmann, Alexei Starovoitov, bpf, Heiko Carstens, Vasily Gorbik
On Tue, Aug 13, 2019 at 9:22 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> "bind4 allow specific IP & port" and "bind6 deny specific IP & port"
> fail on s390 because of endianness issue: the 4 IP address bytes are
> loaded as a word and compared with a constant, but the value of this
> constant should be different on big- and little- endian machines, which
> is not the case right now.
>
> Use __constant_ntohl to generate proper value based on machine
> endianness.
>
> Fixes: 1d436885b23b ("selftests/bpf: Selftest for sys_bind post-hooks.")
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
> tools/testing/selftests/bpf/test_sock.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/test_sock.c b/tools/testing/selftests/bpf/test_sock.c
> index fb679ac3d4b0..5c092a85125f 100644
> --- a/tools/testing/selftests/bpf/test_sock.c
> +++ b/tools/testing/selftests/bpf/test_sock.c
> @@ -8,6 +8,7 @@
> #include <sys/types.h>
> #include <sys/socket.h>
>
> +#include <asm/byteorder.h>
Maybe use bpf_endian.h and bpf_ntohl instead, sticking to BPF stuff
already used by other tests?
> #include <linux/filter.h>
>
> #include <bpf/bpf.h>
> @@ -232,7 +233,8 @@ static struct sock_test tests[] = {
> /* if (ip == expected && port == expected) */
> BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
> offsetof(struct bpf_sock, src_ip6[3])),
> - BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 0x01000000, 4),
> + BPF_JMP_IMM(BPF_JNE, BPF_REG_7,
> + __constant_ntohl(0x00000001), 4),
> BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
> offsetof(struct bpf_sock, src_port)),
> BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 0x2001, 2),
> @@ -261,7 +263,8 @@ static struct sock_test tests[] = {
> /* if (ip == expected && port == expected) */
> BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
> offsetof(struct bpf_sock, src_ip4)),
> - BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 0x0100007F, 4),
> + BPF_JMP_IMM(BPF_JNE, BPF_REG_7,
> + __constant_ntohl(0x7F000001), 4),
> BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
> offsetof(struct bpf_sock, src_port)),
> BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 0x1002, 2),
> --
> 2.21.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-13 19:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-13 16:21 [PATCH bpf] selftests/bpf: fix "bind{4,6} deny specific IP & port" on s390 Ilya Leoshkevich
2019-08-13 19:53 ` Andrii Nakryiko
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).