* [PATCH] samples/seccomp: fix endianness bug in LO_ARG define
@ 2012-07-31 14:15 Heiko Carstens
2012-07-31 16:21 ` Kees Cook
0 siblings, 1 reply; 3+ messages in thread
From: Heiko Carstens @ 2012-07-31 14:15 UTC (permalink / raw)
To: Will Drewry, Kees Cook, James Morris; +Cc: linux-kernel
From: Heiko Carstens <heiko.carstens@de.ibm.com>
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>
---
samples/seccomp/bpf-helper.h | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/samples/seccomp/bpf-helper.h b/samples/seccomp/bpf-helper.h
index 643279d..38ee70f 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);
#define FIND_LABEL(labels, label) seccomp_bpf_label((labels), #label)
#define EXPAND(...) __VA_ARGS__
+
+/* Ensure that we load the logically correct offset. */
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32)
+#else
+#error "Unknown endianness"
+#endif
+
/* Map all width-sensitive operations */
#if __BITS_PER_LONG == 32
@@ -70,21 +80,16 @@ void seccomp_bpf_print(struct sock_filter *filter, size_t count);
#define JLE(x, jt) JLE32(x, EXPAND(jt))
#define JA(x, jt) JA32(x, EXPAND(jt))
#define ARG(i) ARG_32(i)
-#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
#elif __BITS_PER_LONG == 64
/* Ensure that we load the logically correct offset. */
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define ENDIAN(_lo, _hi) _lo, _hi
-#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
#define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32)
#elif __BYTE_ORDER == __BIG_ENDIAN
#define ENDIAN(_lo, _hi) _hi, _lo
-#define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32)
#define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)])
-#else
-#error "Unknown endianness"
#endif
union arg64 {
--
1.7.11.4
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] samples/seccomp: fix endianness bug in LO_ARG define
2012-07-31 14:15 [PATCH] samples/seccomp: fix endianness bug in LO_ARG define Heiko Carstens
@ 2012-07-31 16:21 ` Kees Cook
2012-08-03 4:37 ` James Morris
0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2012-07-31 16:21 UTC (permalink / raw)
To: Heiko Carstens; +Cc: Will Drewry, James Morris, linux-kernel
On Tue, Jul 31, 2012 at 7:15 AM, Heiko Carstens
<heiko.carstens@de.ibm.com> wrote:
> From: Heiko Carstens <heiko.carstens@de.ibm.com>
>
> 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>
Good catch; thanks for the fix!
Acked-by: Kees Cook <keescook@chromium.org>
-Kees
--
Kees Cook
Chrome OS Security
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] samples/seccomp: fix endianness bug in LO_ARG define
2012-07-31 16:21 ` Kees Cook
@ 2012-08-03 4:37 ` James Morris
0 siblings, 0 replies; 3+ messages in thread
From: James Morris @ 2012-08-03 4:37 UTC (permalink / raw)
To: Kees Cook; +Cc: Heiko Carstens, Will Drewry, James Morris, linux-kernel
On Tue, 31 Jul 2012, Kees Cook wrote:
> On Tue, Jul 31, 2012 at 7:15 AM, Heiko Carstens
> <heiko.carstens@de.ibm.com> wrote:
> > From: Heiko Carstens <heiko.carstens@de.ibm.com>
> >
> > 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>
>
> Good catch; thanks for the fix!
>
> Acked-by: Kees Cook <keescook@chromium.org>
Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git next
--
James Morris
<jmorris@namei.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-08-03 4:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-31 14:15 [PATCH] samples/seccomp: fix endianness bug in LO_ARG define Heiko Carstens
2012-07-31 16:21 ` Kees Cook
2012-08-03 4:37 ` James Morris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®