Skip to content

Commit de4bb3b

Browse files
heicarstJames Morris
authored andcommitted
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>
1 parent 6637284 commit de4bb3b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

samples/seccomp/bpf-helper.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ void seccomp_bpf_print(struct sock_filter *filter, size_t count);
5959
#define FIND_LABEL(labels, label) seccomp_bpf_label((labels), #label)
6060

6161
#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+
6272
/* Map all width-sensitive operations */
6373
#if __BITS_PER_LONG == 32
6474

@@ -70,21 +80,16 @@ void seccomp_bpf_print(struct sock_filter *filter, size_t count);
7080
#define JLE(x, jt) JLE32(x, EXPAND(jt))
7181
#define JA(x, jt) JA32(x, EXPAND(jt))
7282
#define ARG(i) ARG_32(i)
73-
#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
7483

7584
#elif __BITS_PER_LONG == 64
7685

7786
/* Ensure that we load the logically correct offset. */
7887
#if __BYTE_ORDER == __LITTLE_ENDIAN
7988
#define ENDIAN(_lo, _hi) _lo, _hi
80-
#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
8189
#define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32)
8290
#elif __BYTE_ORDER == __BIG_ENDIAN
8391
#define ENDIAN(_lo, _hi) _hi, _lo
84-
#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32)
8592
#define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
86-
#else
87-
#error "Unknown endianness"
8893
#endif
8994

9095
union arg64 {

0 commit comments

Comments
 (0)