diff options
author | Heiko Carstens <heiko.carstens@de.ibm.com> | 2012-07-31 10:15:36 -0400 |
---|---|---|
committer | James Morris <james.l.morris@oracle.com> | 2012-08-03 00:27:40 -0400 |
commit | de4bb3b9c788ea5504dfe094e34d831e8395075d (patch) | |
tree | e957a72a3c695d442838b2fef184da8ad5acc193 /samples/seccomp | |
parent | 663728418e3494f8e4a82f5d1b2f23c22d11be35 (diff) |
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>
Diffstat (limited to 'samples/seccomp')
-rw-r--r-- | samples/seccomp/bpf-helper.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/samples/seccomp/bpf-helper.h b/samples/seccomp/bpf-helper.h index 643279dd30fb..38ee70f3cd5b 100644 --- a/samples/seccomp/bpf-helper.h +++ b/samples/seccomp/bpf-helper.h | |||
@@ -59,6 +59,16 @@ void seccomp_bpf_print(struct sock_filter *filter, size_t count); | |||
59 | #define FIND_LABEL(labels, label) seccomp_bpf_label((labels), #label) | 59 | #define FIND_LABEL(labels, label) seccomp_bpf_label((labels), #label) |
60 | 60 | ||
61 | #define EXPAND(...) __VA_ARGS__ | 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 | /* Map all width-sensitive operations */ | 72 | /* Map all width-sensitive operations */ |
63 | #if __BITS_PER_LONG == 32 | 73 | #if __BITS_PER_LONG == 32 |
64 | 74 | ||
@@ -70,21 +80,16 @@ void seccomp_bpf_print(struct sock_filter *filter, size_t count); | |||
70 | #define JLE(x, jt) JLE32(x, EXPAND(jt)) | 80 | #define JLE(x, jt) JLE32(x, EXPAND(jt)) |
71 | #define JA(x, jt) JA32(x, EXPAND(jt)) | 81 | #define JA(x, jt) JA32(x, EXPAND(jt)) |
72 | #define ARG(i) ARG_32(i) | 82 | #define ARG(i) ARG_32(i) |
73 | #define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) | ||
74 | 83 | ||
75 | #elif __BITS_PER_LONG == 64 | 84 | #elif __BITS_PER_LONG == 64 |
76 | 85 | ||
77 | /* Ensure that we load the logically correct offset. */ | 86 | /* Ensure that we load the logically correct offset. */ |
78 | #if __BYTE_ORDER == __LITTLE_ENDIAN | 87 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
79 | #define ENDIAN(_lo, _hi) _lo, _hi | 88 | #define ENDIAN(_lo, _hi) _lo, _hi |
80 | #define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) | ||
81 | #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32) | 89 | #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32) |
82 | #elif __BYTE_ORDER == __BIG_ENDIAN | 90 | #elif __BYTE_ORDER == __BIG_ENDIAN |
83 | #define ENDIAN(_lo, _hi) _hi, _lo | 91 | #define ENDIAN(_lo, _hi) _hi, _lo |
84 | #define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32) | ||
85 | #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) | 92 | #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) |
86 | #else | ||
87 | #error "Unknown endianness" | ||
88 | #endif | 93 | #endif |
89 | 94 | ||
90 | union arg64 { | 95 | union arg64 { |