From 4fcb367b1a7ff06a55c8bc4a25c38e46b77a1261 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 22 Jun 2012 19:42:08 -0700 Subject: libsandbox: handle broken kernel headers Sometimes the struct in asm/ptrace.h is too small for what the kernel actually writes. Check to see which struct is larger (the one that the kernel declares or the C library declares), and use that. Signed-off-by: Mike Frysinger --- configure.ac | 2 ++ localdecls.h | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/configure.ac b/configure.ac index da6f75d..573e412 100644 --- a/configure.ac +++ b/configure.ac @@ -119,6 +119,8 @@ AC_CHECK_TYPES([sighandler_t, sig_t, __sighandler_t],,,[#include ]) save_CPPFLAGS=$CPPFLAGS CPPFLAGS="-I$srcdir $CPPFLAGS" AC_CHECK_TYPES([struct user_regs_struct, struct pt_regs],,,[#include "headers.h"]) +AC_CHECK_SIZEOF([struct user_regs_struct],,[#include "headers.h"]) +AC_CHECK_SIZEOF([struct pt_regs],,[#include "headers.h"]) CPPFLAGS=$save_CPPFLAGS dnl Checks for library functions. diff --git a/localdecls.h b/localdecls.h index eef7295..be99617 100644 --- a/localdecls.h +++ b/localdecls.h @@ -68,6 +68,17 @@ typedef __sighandler_t sighandler_t; #endif #define HAVE_TRACE_REGS +#if defined(HAVE_STRUCT_PT_REGS) && defined(HAVE_STRUCT_USER_REGS_STRUCT) +/* + * Some systems have broken kernel headers who declare struct pt_regs as + * smaller than what the kernel actually operates on. If we have both + * reg structs available, pick the one that is larger in the hopes that + * we won't randomly clobber memory. + */ +# if SIZEOF_STRUCT_PT_REGS < SIZEOF_STRUCT_USER_REGS_STRUCT +# undef HAVE_STRUCT_PT_REGS +# endif +#endif #if defined(HAVE_STRUCT_PT_REGS) typedef struct pt_regs trace_regs; #elif defined(HAVE_STRUCT_USER_REGS_STRUCT) -- cgit v1.2.3-65-gdbad