Commit de4bb3b9c788ea5504dfe094e34d831e8395075d

Authored by Heiko Carstens
Committed by James Morris
1 parent 663728418e

samples/seccomp: fix endianness bug in LO_ARG define

The LO_ARG define needs to consider endianness also for 32 bit builds.

The "bpf_fancy" test case didn't work on s390 in 32 bit and compat mode
because the LO_ARG define resulted in a BPF program which read the upper
halve of the 64 bit system call arguments instead of the lower halves.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: James Morris <james.l.morris@oracle.com>

Showing 1 changed file with 10 additions and 5 deletions Side-by-side Diff

samples/seccomp/bpf-helper.h
... ... @@ -59,6 +59,16 @@
59 59 #define FIND_LABEL(labels, label) seccomp_bpf_label((labels), #label)
60 60  
61 61 #define EXPAND(...) __VA_ARGS__
  62 +
  63 +/* Ensure that we load the logically correct offset. */
  64 +#if __BYTE_ORDER == __LITTLE_ENDIAN
  65 +#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
  66 +#elif __BYTE_ORDER == __BIG_ENDIAN
  67 +#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32)
  68 +#else
  69 +#error "Unknown endianness"
  70 +#endif
  71 +
62 72 /* Map all width-sensitive operations */
63 73 #if __BITS_PER_LONG == 32
64 74  
65 75  
66 76  
67 77  
... ... @@ -70,21 +80,16 @@
70 80 #define JLE(x, jt) JLE32(x, EXPAND(jt))
71 81 #define JA(x, jt) JA32(x, EXPAND(jt))
72 82 #define ARG(i) ARG_32(i)
73   -#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
74 83  
75 84 #elif __BITS_PER_LONG == 64
76 85  
77 86 /* Ensure that we load the logically correct offset. */
78 87 #if __BYTE_ORDER == __LITTLE_ENDIAN
79 88 #define ENDIAN(_lo, _hi) _lo, _hi
80   -#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
81 89 #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32)
82 90 #elif __BYTE_ORDER == __BIG_ENDIAN
83 91 #define ENDIAN(_lo, _hi) _hi, _lo
84   -#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32)
85 92 #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
86   -#else
87   -#error "Unknown endianness"
88 93 #endif
89 94  
90 95 union arg64 {