Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Heiko Carstens and committed by
James Morris
de4bb3b9 66372841

+10 -5
+10 -5
samples/seccomp/bpf-helper.h
··· 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 ··· 80 70 #define JLE(x, jt) JLE32(x, EXPAND(jt)) 81 71 #define JA(x, jt) JA32(x, EXPAND(jt)) 82 72 #define ARG(i) ARG_32(i) 83 - #define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) 84 73 85 74 #elif __BITS_PER_LONG == 64 86 75 87 76 /* Ensure that we load the logically correct offset. */ 88 77 #if __BYTE_ORDER == __LITTLE_ENDIAN 89 78 #define ENDIAN(_lo, _hi) _lo, _hi 90 - #define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) 91 79 #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32) 92 80 #elif __BYTE_ORDER == __BIG_ENDIAN 93 81 #define ENDIAN(_lo, _hi) _hi, _lo 94 - #define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32) 95 82 #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) 96 - #else 97 - #error "Unknown endianness" 98 83 #endif 99 84 100 85 union arg64 {