* [PATCH bpf-next v2] selftests/bpf: Fix endianness issue in test_sockopt_sk
@ 2020-09-15 11:39 Ilya Leoshkevich
2020-09-16 1:19 ` Andrii Nakryiko
2020-09-18 23:08 ` Daniel Borkmann
0 siblings, 2 replies; 4+ messages in thread
From: Ilya Leoshkevich @ 2020-09-15 11:39 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann
Cc: bpf, Heiko Carstens, Vasily Gorbik, Andrii Nakryiko,
Ilya Leoshkevich
getsetsockopt() calls getsockopt() with optlen == 1, but then checks
the resulting int. It is ok on little endian, but not on big endian.
Fix by checking char instead.
Fixes: 8a027dc0 ("selftests/bpf: add sockopt test that exercises sk helpers")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
v1->v2: Also pass a single byte to log_err.
tools/testing/selftests/bpf/prog_tests/sockopt_sk.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
index 5f54c6aec7f0..b25c9c45c148 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
@@ -45,9 +45,9 @@ static int getsetsockopt(void)
goto err;
}
- if (*(int *)big_buf != 0x08) {
+ if (*big_buf != 0x08) {
log_err("Unexpected getsockopt(IP_TOS) optval 0x%x != 0x08",
- *(int *)big_buf);
+ (int)*big_buf);
goto err;
}
--
2.25.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH bpf-next v2] selftests/bpf: Fix endianness issue in test_sockopt_sk
2020-09-15 11:39 [PATCH bpf-next v2] selftests/bpf: Fix endianness issue in test_sockopt_sk Ilya Leoshkevich
@ 2020-09-16 1:19 ` Andrii Nakryiko
2020-09-16 22:20 ` Song Liu
2020-09-18 23:08 ` Daniel Borkmann
1 sibling, 1 reply; 4+ messages in thread
From: Andrii Nakryiko @ 2020-09-16 1:19 UTC (permalink / raw)
To: Ilya Leoshkevich
Cc: Alexei Starovoitov, Daniel Borkmann, bpf, Heiko Carstens,
Vasily Gorbik
On Tue, Sep 15, 2020 at 4:39 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> getsetsockopt() calls getsockopt() with optlen == 1, but then checks
> the resulting int. It is ok on little endian, but not on big endian.
>
> Fix by checking char instead.
>
> Fixes: 8a027dc0 ("selftests/bpf: add sockopt test that exercises sk helpers")
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>
> v1->v2: Also pass a single byte to log_err.
>
Acked-by: Andrii Nakryiko <andriin@fb.com>
> tools/testing/selftests/bpf/prog_tests/sockopt_sk.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> index 5f54c6aec7f0..b25c9c45c148 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> @@ -45,9 +45,9 @@ static int getsetsockopt(void)
> goto err;
> }
>
> - if (*(int *)big_buf != 0x08) {
> + if (*big_buf != 0x08) {
> log_err("Unexpected getsockopt(IP_TOS) optval 0x%x != 0x08",
> - *(int *)big_buf);
> + (int)*big_buf);
> goto err;
> }
>
> --
> 2.25.4
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH bpf-next v2] selftests/bpf: Fix endianness issue in test_sockopt_sk
2020-09-16 1:19 ` Andrii Nakryiko
@ 2020-09-16 22:20 ` Song Liu
0 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2020-09-16 22:20 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: Ilya Leoshkevich, Alexei Starovoitov, Daniel Borkmann, bpf,
Heiko Carstens, Vasily Gorbik
On Tue, Sep 15, 2020 at 6:20 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Tue, Sep 15, 2020 at 4:39 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
> >
> > getsetsockopt() calls getsockopt() with optlen == 1, but then checks
> > the resulting int. It is ok on little endian, but not on big endian.
> >
> > Fix by checking char instead.
> >
> > Fixes: 8a027dc0 ("selftests/bpf: add sockopt test that exercises sk helpers")
> > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> > ---
> >
> > v1->v2: Also pass a single byte to log_err.
> >
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v2] selftests/bpf: Fix endianness issue in test_sockopt_sk
2020-09-15 11:39 [PATCH bpf-next v2] selftests/bpf: Fix endianness issue in test_sockopt_sk Ilya Leoshkevich
2020-09-16 1:19 ` Andrii Nakryiko
@ 2020-09-18 23:08 ` Daniel Borkmann
1 sibling, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2020-09-18 23:08 UTC (permalink / raw)
To: Ilya Leoshkevich, Alexei Starovoitov
Cc: bpf, Heiko Carstens, Vasily Gorbik, Andrii Nakryiko
On 9/15/20 1:39 PM, Ilya Leoshkevich wrote:
> getsetsockopt() calls getsockopt() with optlen == 1, but then checks
> the resulting int. It is ok on little endian, but not on big endian.
>
> Fix by checking char instead.
>
> Fixes: 8a027dc0 ("selftests/bpf: add sockopt test that exercises sk helpers")
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-18 23:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-15 11:39 [PATCH bpf-next v2] selftests/bpf: Fix endianness issue in test_sockopt_sk Ilya Leoshkevich
2020-09-16 1:19 ` Andrii Nakryiko
2020-09-16 22:20 ` Song Liu
2020-09-18 23:08 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox