MIPS: Add syscall auditing support
PATCH 1/1 MIPS: Add syscall auditing support
From: Ralf Baechle <[email protected]>
The original patch is from Ralf. I have maintained it for more than six years on Loongson platform, and it works perfectly. Most of the commit messages are written by Ralf.
MIPS doesn't quite fit into the existing pattern of other architectures and I'd appreciate your comments and maybe even an Acked-by.
- Linux on MIPS extends the traditional syscall table used by older UNIX implementations. This is why 32-bit Linux syscalls are starting from 4000; the native 64-bit syscalls start from 5000 and the N32 compat ABI from 6000. The existing syscall bitmap is only large enough for at most 2048 syscalls, so I had to increase AUDIT_BITMASK_SIZE to 256 which provides enough space for 8192 syscalls. Because include/uapi/linux/ audit.h and AUDIT_BITMASK_SIZE are exported to userspace I've used an #ifdef __mips__ for this.
- The code treats the little endian MIPS architecture as separate from big endian. Combined with the 3 ABIs that's 6 combinations. I tried to sort of follow the example set by ARM which explicitly lists the (rare) big endian architecture variant - but it doesn't seem to very useful so I wonder if this could be squashed to just the three ABIs without consideration of endianess?
--- arch/mips/Kconfig | 13 +++++ arch/mips/include/asm/abi.h | 1 + arch/mips/include/asm/unistd.h | 10 ++++ arch/mips/include/uapi/asm/unistd.h | 21 ++++---- arch/mips/kernel/Makefile | 4 ++ arch/mips/kernel/audit-n32.c | 58 ++++++++++++++++++++++ arch/mips/kernel/audit-native.c | 97 +++++++++++++++++++++++++++++++++++++ arch/mips/kernel/audit-o32.c | 60 +++++++++++++++++++++++ arch/mips/kernel/signal.c | 18 +++++++ arch/mips/kernel/signal_n32.c | 8 +++ arch/mips/kernel/signal_o32.c | 8 +++ include/uapi/linux/audit.h | 10 ++++ kernel/auditsc.c | 13 +++++ 13 files changed, 312 insertions(+), 9 deletions(-) create mode 100644 arch/mips/kernel/audit-n32.c create mode 100644 arch/mips/kernel/audit-native.c create mode 100644 arch/mips/kernel/audit-o32.c
arch/mips/Kconfig +13 -0
@@ -14,6 +14,7 @@ config MIPS select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_IPC_PARSE_VERSION + select AUDIT_ARCH select BUILDTIME_EXTABLE_SORT select CLONE_BACKWARDS select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
@@ -35,6 +36,7 @@ config MIPS select GENERIC_SMP_IDLE_THREAD select GENERIC_TIME_VSYSCALL select HANDLE_DOMAIN_IRQ + select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_COMPILER_H select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_KGDB
@@ -1064,6 +1066,15 @@ config FW_ARC config ARCH_MAY_HAVE_PC_FDC bool +config AUDIT_ARCH + bool + +config AUDITSYSCALL_O32 + bool + +config AUDITSYSCALL_N32 + bool + config BOOT_RAW bool
@@ -3149,6 +3160,7 @@ config MIPS32_O32 select COMPAT select MIPS32_COMPAT select SYSVIPC_COMPAT if SYSVIPC + select AUDITSYSCALL_O32 if AUDITSYSCALL help Select this option if you want to run o32 binaries. These are pure 32-bit binaries as used by the 32-bit Linux/MIPS port. Most of
@@ -3162,6 +3174,7 @@ config MIPS32_N32 select COMPAT select MIPS32_COMPAT select SYSVIPC_COMPAT if SYSVIPC + select AUDITSYSCALL_N32 if AUDITSYSCALL help Select this option if you want to run n32 binaries. These are 64-bit binaries using 32-bit quantities for addressing and certain
arch/mips/include/asm/abi.h +1 -0
@@ -21,6 +21,7 @@ struct mips_abi {int (*const setup_rt_frame)(void *sig_return,struct ksignal *ksig,struct pt_regs *regs,sigset_t *set);const unsigned long restart; +const int audit_arch;unsigned off_sc_fpregs;unsigned off_sc_fpc_csr;
arch/mips/include/asm/unistd.h +10 -0
@@ -71,4 +71,14 @@#endif /* !__ASSEMBLY__ */ +#ifdef CONFIG_MIPS32_N32 +#define NR_syscalls (__NR_N32_Linux + __NR_N32_Linux_syscalls) +#elif defined(CONFIG_64BIT ) +#define NR_syscalls (__NR_64_Linux + __NR_64_Linux_syscalls) +#elif defined(CONFIG_32BIT ) +#define NR_syscalls (__NR_O32_Linux + __NR_O32_Linux_syscalls) +#else +#error Must know ABIs in use to define NR_syscalls +#endif +#endif /* _ASM_UNISTD_H */
arch/mips/include/uapi/asm/unistd.h +12 -9
@@ -6,34 +6,37 @@* * Copyright (C) 1995, 96, 97, 98, 99, 2000 by Ralf Baechle * Copyright (C) 1999, 2000 Silicon Graphics, Inc. -* -* Changed system calls macros _syscall5 - _syscall7 to push args 5 to 7 onto -* the stack. Robin Farine for ACN S.A, Copyright (C) 1996 by ACN S.A */ #ifndef _UAPI_ASM_UNISTD_H#define _UAPI_ASM_UNISTD_H#include <asm/sgidefs.h> -#if _MIPS_SIM == _MIPS_SIM_ABI32 +#if (defined(__WANT_SYSCALL_NUMBERS) && \ + (__WANT_SYSCALL_NUMBERS == _MIPS_SIM_ABI32)) || \ + (!defined(__WANT_SYSCALL_NUMBERS) && _MIPS_SIM == _MIPS_SIM_ABI32)#define __NR_Linux 4000#include <asm/unistd_o32.h> -#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */ +#endif /* Want O32 || _MIPS_SIM == _MIPS_SIM_ABI32 */ -#if _MIPS_SIM == _MIPS_SIM_ABI64 +#if (defined(__WANT_SYSCALL_NUMBERS) && \ + (__WANT_SYSCALL_NUMBERS == _MIPS_SIM_ABI64)) || \ + (!defined(__WANT_SYSCALL_NUMBERS) && _MIPS_SIM == _MIPS_SIM_ABI64)#define __NR_Linux 5000#include <asm/unistd_n64.h> -#endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */ +#endif /* Want N64 || _MIPS_SIM == _MIPS_SIM_ABI64 */ -#if _MIPS_SIM == _MIPS_SIM_NABI32 +#if (defined(__WANT_SYSCALL_NUMBERS) && \ + (__WANT_SYSCALL_NUMBERS == _MIPS_SIM_NABI32)) || \ + (!defined(__WANT_SYSCALL_NUMBERS) && _MIPS_SIM == _MIPS_SIM_NABI32)#define __NR_Linux 6000#include <asm/unistd_n32.h> -#endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */ +#endif /* Want N32 || _MIPS_SIM == _MIPS_SIM_NABI32 */ #endif /* _UAPI_ASM_UNISTD_H */
arch/mips/kernel/Makefile +4 -0
@@ -106,6 +106,10 @@ obj-$(CONFIG_HW_PERF_EVENTS) += perf_event_mipsxx.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o obj-$(CONFIG_UPROBES) += uprobes.o +obj-$(CONFIG_AUDITSYSCALL_O32) += audit-o32.o +obj-$(CONFIG_AUDITSYSCALL_N32) += audit-n32.o +obj-$(CONFIG_AUDITSYSCALL) += audit-native.o + obj-$(CONFIG_MIPS_CM) += mips-cm.o obj-$(CONFIG_MIPS_CPC) += mips-cpc.o
arch/mips/kernel/audit-n32.c new file +58 -0
58 lines not on this page · raw message
arch/mips/kernel/audit-native.c new file +97 -0
97 lines not on this page · raw message
arch/mips/kernel/audit-o32.c new file +60 -0
60 lines not on this page · raw message
arch/mips/kernel/signal.c +18 -0
@@ -8,6 +8,7 @@* Copyright (C) 1999, 2000 Silicon Graphics, Inc. * Copyright (C) 2014, Imagination Technologies Ltd. */ +#include <linux/audit.h> #include <linux/cache.h> #include <linux/context_tracking.h> #include <linux/irqflags.h>
@@ -790,6 +791,23 @@ struct mips_abi mips_abi = {#endif .setup_rt_frame = setup_rt_frame, .restart = __NR_restart_syscall, +#ifdef CONFIG_64BIT +# ifdef __BIG_ENDIAN + .audit_arch = AUDIT_ARCH_MIPS64, +# elif defined(__LITTLE_ENDIAN) + .audit_arch = AUDIT_ARCH_MIPSEL64, +# else +# error "Neither big nor little endian ???" +# endif +#else +# ifdef __BIG_ENDIAN + .audit_arch = AUDIT_ARCH_MIPS, +# elif defined(__LITTLE_ENDIAN) + .audit_arch = AUDIT_ARCH_MIPSEL, +# else +# error "Neither big nor little endian ???" +# endif +#endif .off_sc_fpregs = offsetof(struct sigcontext, sc_fpregs), .off_sc_fpc_csr = offsetof(struct sigcontext, sc_fpc_csr),
arch/mips/kernel/signal_n32.c +8 -0
@@ -15,6 +15,7 @@* along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <linux/audit.h> #include <linux/cache.h> #include <linux/sched.h> #include <linux/mm.h>
@@ -153,6 +154,13 @@ static int setup_rt_frame_n32(void *sig_return, struct ksignal *ksig,struct mips_abi mips_abi_n32 = { .setup_rt_frame = setup_rt_frame_n32, .restart = __NR_N32_restart_syscall, +#ifdef __BIG_ENDIAN + .audit_arch =AUDIT_ARCH_MIPS64N32 , +#elif defined(__LITTLE_ENDIAN) + .audit_arch =AUDIT_ARCH_MIPSEL64N32 , +#else +# error "Neither big nor little endian ???" +#endif .off_sc_fpregs = offsetof(struct sigcontext , sc_fpregs), .off_sc_fpc_csr = offsetof(struct sigcontext , sc_fpc_csr),
arch/mips/kernel/signal_o32.c +8 -0
@@ -8,6 +8,7 @@* Copyright (C) 1999, 2000 Silicon Graphics, Inc. * Copyright (C) 2016, Imagination Technologies Ltd. */ +#include <linux/audit.h> #include <linux/compiler.h> #include <linux/errno.h> #include <linux/signal.h>
@@ -244,6 +245,13 @@ struct mips_abi mips_abi_32 = { .setup_frame = setup_frame_32, .setup_rt_frame = setup_rt_frame_32, .restart = __NR_O32_restart_syscall, +#ifdef __BIG_ENDIAN + .audit_arch = AUDIT_ARCH_MIPS, +#elif defined(__LITTLE_ENDIAN) + .audit_arch = AUDIT_ARCH_MIPSEL, +#else +# error "Neither big nor little endian ???" +#endif .off_sc_fpregs = offsetof(struct sigcontext32, sc_fpregs), .off_sc_fpc_csr = offsetof(struct sigcontext32, sc_fpc_csr),
include/uapi/linux/audit.h +10 -0
@@ -175,7 +175,11 @@* AUDIT_LIST commands must be implemented. */ #define AUDIT_MAX_FIELDS 64#define AUDIT_MAX_KEY_LEN 256 +#ifdef __mips__ +#define AUDIT_BITMASK_SIZE 256 +#else #define AUDIT_BITMASK_SIZE 64 +#endif #define AUDIT_WORD (nr) ((__u32)((nr)/32))#define AUDIT_BIT (nr) (1 << ((nr) - AUDIT_WORD(nr)*32))
@@ -191,6 +195,12 @@#define AUDIT_CLASS_SIGNAL 8#define AUDIT_CLASS_SIGNAL_32 9 +#define AUDIT_CLASS_DIR_WRITE_N32 10 +#define AUDIT_CLASS_CHATTR_N32 11 +#define AUDIT_CLASS_READ_N32 12 +#define AUDIT_CLASS_WRITE_N32 13 +#define AUDIT_CLASS_SIGNAL_N32 14 +/* This bitmask is used to validate user input. It represents all bits that * are currently used in an audit field constant understood by the kernel. * If you are adding a new #define AUDIT_<whatever>, please ensure that
kernel/auditsc.c +13 -0
@@ -168,6 +168,19 @@ static int audit_match_perm(struct audit_context *ctx, int mask)return ((mask &AUDIT_PERM_WRITE ) && ctx->argv[0 ] ==SYS_BIND );case 5 :/* execve */ return mask &AUDIT_PERM_EXEC ; +#ifdef CONFIG_MIPS +case 6 :/* for N32 */ +if ((mask &AUDIT_PERM_WRITE ) && +audit_match_class (AUDIT_CLASS_WRITE_N32 , n)) +return 1 ; +if ((mask &AUDIT_PERM_READ ) && +audit_match_class (AUDIT_CLASS_READ_N32 , n)) +return 1 ; +if ((mask &AUDIT_PERM_ATTR ) && +audit_match_class (AUDIT_CLASS_CHATTR_N32 , n)) +return 1 ; +return 0 ; +#endif default :return 0 ; }
Signature · 1 line
2.7.0
Quoted 25 lines · Huacai Chen
From: Ralf Baechle <[email protected]>
The original patch is from Ralf. I have maintained it for more than six years on Loongson platform, and it works perfectly. Most of the commit messages are written by Ralf.
MIPS doesn't quite fit into the existing pattern of other architectures and I'd appreciate your comments and maybe even an Acked-by.
- Linux on MIPS extends the traditional syscall table used by older UNIX implementations. This is why 32-bit Linux syscalls are starting from 4000; the native 64-bit syscalls start from 5000 and the N32 compat ABI from 6000. The existing syscall bitmap is only large enough for at most 2048 syscalls, so I had to increase
AUDIT_BITMASK_SIZEto 256 which provides enough space for 8192 syscalls. Becauseinclude/uapi/linux/audit.handAUDIT_BITMASK_SIZEare exported to userspace I've used an #ifdef__mips__for this.- The code treats the little endian MIPS architecture as separate from big endian. Combined with the 3 ABIs that's 6 combinations. I tried to sort of follow the example set by ARM which explicitly lists the (rare) big endian architecture variant - but it doesn't seem to very useful so I wonder if this could be squashed to just the three ABIs without consideration of endianess?
Quoted 2 lines
Signed-off-by Ralf Baechle <[email protected]>Signed-off-by Huacai Chen <[email protected]>
Any update about this patch?
Thanks.
--
Jiaxun Yang
Hi, Paul,
Nearly all archs (including alpha) have supported syscall audit, can this mips audit patch be merged?
Huacai
Quoted 41 lines · Jiaxun Yang
Quoted 25 lines · Huacai Chen
From: Ralf Baechle <[email protected]>
The original patch is from Ralf. I have maintained it for more than six years on Loongson platform, and it works perfectly. Most of the commit messages are written by Ralf.
MIPS doesn't quite fit into the existing pattern of other architectures and I'd appreciate your comments and maybe even an Acked-by.
- Linux on MIPS extends the traditional syscall table used by older UNIX implementations. This is why 32-bit Linux syscalls are starting from 4000; the native 64-bit syscalls start from 5000 and the N32 compat ABI from 6000. The existing syscall bitmap is only large enough for at most 2048 syscalls, so I had to increase
AUDIT_BITMASK_SIZEto 256 which provides enough space for 8192 syscalls. Becauseinclude/uapi/linux/audit.handAUDIT_BITMASK_SIZEare exported to userspace I've used an #ifdef__mips__for this.- The code treats the little endian MIPS architecture as separate from big endian. Combined with the 3 ABIs that's 6 combinations. I tried to sort of follow the example set by ARM which explicitly lists the (rare) big endian architecture variant - but it doesn't seem to very useful so I wonder if this could be squashed to just the three ABIs without consideration of endianess?
Quoted 2 lines
Signed-off-by Ralf Baechle <[email protected]>Signed-off-by Huacai Chen <[email protected]>Reviewed-by Jiaxun Yang <[email protected]>Any update about this patch?
Thanks.
--
Jiaxun Yang