lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 4 Aug 2017 15:26:59 -0700
From:   Yonghong Song <yhs@...com>
To:     Daniel Borkmann <daniel@...earbox.net>, <davem@...emloft.net>
CC:     <alexei.starovoitov@...il.com>, <netdev@...r.kernel.org>
Subject: Re: [PATCH net] bpf: fix byte order test in test_verifier



On 8/4/17 1:24 PM, Daniel Borkmann wrote:
> We really must check with #if __BYTE_ORDER == XYZ instead of
> just presence of #ifdef __LITTLE_ENDIAN. I noticed that when
> actually running this on big endian machine, the latter test
> resolves to true for user space, same for #ifdef __BIG_ENDIAN.
> 
> E.g., looking at endian.h from libc, both are also defined
> there, so we really must test this against __BYTE_ORDER instead
> for proper insns selection. For the kernel, such checks are
> fine though e.g. see 13da9e200fe4 ("Revert "endian: #define
> __BYTE_ORDER"") and 415586c9e6d3 ("UAPI: fix endianness conditionals
> in M32R's asm/stat.h") for some more context, but not for
> user space. Lets also make sure to properly include endian.h.
> After that, suite passes for me:
> 
> ./test_verifier: ELF 64-bit MSB executable, [...]
> 
> Linux foo 4.13.0-rc3+ #4 SMP Fri Aug 4 06:59:30 EDT 2017 s390x s390x s390x GNU/Linux
> 
> Before fix: Summary: 505 PASSED, 11 FAILED
> After  fix: Summary: 516 PASSED,  0 FAILED
> 
> Fixes: 18f3d6be6be1 ("selftests/bpf: Add test cases to test narrower ctx field loads")
> Signed-off-by: Daniel Borkmann <daniel@...earbox.net>
> ---
>   tools/testing/selftests/bpf/test_verifier.c | 19 ++++++++++---------
>   1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
> index addea82..d3ed732 100644
> --- a/tools/testing/selftests/bpf/test_verifier.c
> +++ b/tools/testing/selftests/bpf/test_verifier.c
> @@ -8,6 +8,7 @@
>    * License as published by the Free Software Foundation.
>    */
>   
> +#include <endian.h>
>   #include <asm/types.h>
>   #include <linux/types.h>
>   #include <stdint.h>
> @@ -1098,7 +1099,7 @@ struct test_val {
>   		"check skb->hash byte load permitted",
>   		.insns = {
>   			BPF_MOV64_IMM(BPF_REG_0, 0),
> -#ifdef __LITTLE_ENDIAN
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>   			BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
>   				    offsetof(struct __sk_buff, hash)),
>   #else
> @@ -1135,7 +1136,7 @@ struct test_val {
>   		"check skb->hash byte load not permitted 3",
>   		.insns = {
>   			BPF_MOV64_IMM(BPF_REG_0, 0),
> -#ifdef __LITTLE_ENDIAN
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>   			BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
>   				    offsetof(struct __sk_buff, hash) + 3),
>   #else
> @@ -1244,7 +1245,7 @@ struct test_val {
>   		"check skb->hash half load permitted",
>   		.insns = {
>   			BPF_MOV64_IMM(BPF_REG_0, 0),
> -#ifdef __LITTLE_ENDIAN
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>   			BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
>   				    offsetof(struct __sk_buff, hash)),
>   #else
> @@ -1259,7 +1260,7 @@ struct test_val {
>   		"check skb->hash half load not permitted",
>   		.insns = {
>   			BPF_MOV64_IMM(BPF_REG_0, 0),
> -#ifdef __LITTLE_ENDIAN
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>   			BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
>   				    offsetof(struct __sk_buff, hash) + 2),
>   #else
> @@ -5422,7 +5423,7 @@ struct test_val {
>   		"check bpf_perf_event_data->sample_period byte load permitted",
>   		.insns = {
>   			BPF_MOV64_IMM(BPF_REG_0, 0),
> -#ifdef __LITTLE_ENDIAN
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>   			BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
>   				    offsetof(struct bpf_perf_event_data, sample_period)),
>   #else
> @@ -5438,7 +5439,7 @@ struct test_val {
>   		"check bpf_perf_event_data->sample_period half load permitted",
>   		.insns = {
>   			BPF_MOV64_IMM(BPF_REG_0, 0),
> -#ifdef __LITTLE_ENDIAN
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>   			BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
>   				    offsetof(struct bpf_perf_event_data, sample_period)),
>   #else
> @@ -5454,7 +5455,7 @@ struct test_val {
>   		"check bpf_perf_event_data->sample_period word load permitted",
>   		.insns = {
>   			BPF_MOV64_IMM(BPF_REG_0, 0),
> -#ifdef __LITTLE_ENDIAN
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>   			BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
>   				    offsetof(struct bpf_perf_event_data, sample_period)),
>   #else
> @@ -5481,7 +5482,7 @@ struct test_val {
>   		"check skb->data half load not permitted",
>   		.insns = {
>   			BPF_MOV64_IMM(BPF_REG_0, 0),
> -#ifdef __LITTLE_ENDIAN
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>   			BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
>   				    offsetof(struct __sk_buff, data)),
>   #else
> @@ -5497,7 +5498,7 @@ struct test_val {
>   		"check skb->tc_classid half load not permitted for lwt prog",
>   		.insns = {
>   			BPF_MOV64_IMM(BPF_REG_0, 0),
> -#ifdef __LITTLE_ENDIAN
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>   			BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
>   				    offsetof(struct __sk_buff, tc_classid)),
>   #else
> 

The change looks good to me.
Acked-by: Yonghong <yhs@...com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ