Skip to content

Commit

Permalink
Merge git://git.infradead.org/users/eparis/audit
Browse files Browse the repository at this point in the history
Pull audit updates from Eric Paris:
 "So this change across a whole bunch of arches really solves one basic
  problem.  We want to audit when seccomp is killing a process.  seccomp
  hooks in before the audit syscall entry code.  audit_syscall_entry
  took as an argument the arch of the given syscall.  Since the arch is
  part of what makes a syscall number meaningful it's an important part
  of the record, but it isn't available when seccomp shoots the
  syscall...

  For most arch's we have a better way to get the arch (syscall_get_arch)
  So the solution was two fold: Implement syscall_get_arch() everywhere
  there is audit which didn't have it.  Use syscall_get_arch() in the
  seccomp audit code.  Having syscall_get_arch() everywhere meant it was
  a useless flag on the stack and we could get rid of it for the typical
  syscall entry.

  The other changes inside the audit system aren't grand, fixed some
  records that had invalid spaces.  Better locking around the task comm
  field.  Removing some dead functions and structs.  Make some things
  static.  Really minor stuff"

* git://git.infradead.org/users/eparis/audit: (31 commits)
  audit: rename audit_log_remove_rule to disambiguate for trees
  audit: cull redundancy in audit_rule_change
  audit: WARN if audit_rule_change called illegally
  audit: put rule existence check in canonical order
  next: openrisc: Fix build
  audit: get comm using lock to avoid race in string printing
  audit: remove open_arg() function that is never used
  audit: correct AUDIT_GET_FEATURE return message type
  audit: set nlmsg_len for multicast messages.
  audit: use union for audit_field values since they are mutually exclusive
  audit: invalid op= values for rules
  audit: use atomic_t to simplify audit_serial()
  kernel/audit.c: use ARRAY_SIZE instead of sizeof/sizeof[0]
  audit: reduce scope of audit_log_fcaps
  audit: reduce scope of audit_net_id
  audit: arm64: Remove the audit arch argument to audit_syscall_entry
  arm64: audit: Add audit hook in syscall_trace_enter/exit()
  audit: x86: drop arch from __audit_syscall_entry() interface
  sparc: implement is_32bit_task
  sparc: properly conditionalize use of TIF_32BIT
  ...
  • Loading branch information
torvalds committed Oct 19, 2014
2 parents 61ed53d + 2991dd2 commit ab074ad
Show file tree
Hide file tree
Showing 43 changed files with 204 additions and 180 deletions.
11 changes: 11 additions & 0 deletions arch/alpha/include/asm/syscall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef _ASM_ALPHA_SYSCALL_H
#define _ASM_ALPHA_SYSCALL_H

#include <uapi/linux/audit.h>

static inline int syscall_get_arch(void)
{
return AUDIT_ARCH_ALPHA;
}

#endif /* _ASM_ALPHA_SYSCALL_H */
2 changes: 1 addition & 1 deletion arch/alpha/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ asmlinkage unsigned long syscall_trace_enter(void)
if (test_thread_flag(TIF_SYSCALL_TRACE) &&
tracehook_report_syscall_entry(current_pt_regs()))
ret = -1UL;
audit_syscall_entry(AUDIT_ARCH_ALPHA, regs->r0, regs->r16, regs->r17, regs->r18, regs->r19);
audit_syscall_entry(regs->r0, regs->r16, regs->r17, regs->r18, regs->r19);
return ret ?: current_pt_regs()->r0;
}

Expand Down
4 changes: 2 additions & 2 deletions arch/arm/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,8 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
trace_sys_enter(regs, scno);

audit_syscall_entry(AUDIT_ARCH_ARM, scno, regs->ARM_r0, regs->ARM_r1,
regs->ARM_r2, regs->ARM_r3);
audit_syscall_entry(scno, regs->ARM_r0, regs->ARM_r1, regs->ARM_r2,
regs->ARM_r3);

return scno;
}
Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,8 +1120,8 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
trace_sys_enter(regs, regs->syscallno);

audit_syscall_entry(syscall_get_arch(), regs->syscallno,
regs->orig_x0, regs->regs[1], regs->regs[2], regs->regs[3]);
audit_syscall_entry(regs->syscallno, regs->orig_x0, regs->regs[1],
regs->regs[2], regs->regs[3]);

return regs->syscallno;
}
Expand Down
6 changes: 6 additions & 0 deletions arch/ia64/include/asm/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef _ASM_SYSCALL_H
#define _ASM_SYSCALL_H 1

#include <uapi/linux/audit.h>
#include <linux/sched.h>
#include <linux/err.h>

Expand Down Expand Up @@ -79,4 +80,9 @@ static inline void syscall_set_arguments(struct task_struct *task,

ia64_syscall_get_set_arguments(task, regs, i, n, args, 1);
}

static inline int syscall_get_arch(void)
{
return AUDIT_ARCH_IA64;
}
#endif /* _ASM_SYSCALL_H */
2 changes: 1 addition & 1 deletion arch/ia64/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ syscall_trace_enter (long arg0, long arg1, long arg2, long arg3,
ia64_sync_krbs();


audit_syscall_entry(AUDIT_ARCH_IA64, regs.r15, arg0, arg1, arg2, arg3);
audit_syscall_entry(regs.r15, arg0, arg1, arg2, arg3);

return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions arch/microblaze/include/asm/syscall.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef __ASM_MICROBLAZE_SYSCALL_H
#define __ASM_MICROBLAZE_SYSCALL_H

#include <uapi/linux/audit.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <asm/ptrace.h>
Expand Down Expand Up @@ -99,4 +100,8 @@ static inline void syscall_set_arguments(struct task_struct *task,
asmlinkage long do_syscall_trace_enter(struct pt_regs *regs);
asmlinkage void do_syscall_trace_leave(struct pt_regs *regs);

static inline int syscall_get_arch(void)
{
return AUDIT_ARCH_MICROBLAZE;
}
#endif /* __ASM_MICROBLAZE_SYSCALL_H */
3 changes: 1 addition & 2 deletions arch/microblaze/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
*/
ret = -1L;

audit_syscall_entry(EM_MICROBLAZE, regs->r12, regs->r5, regs->r6,
regs->r7, regs->r8);
audit_syscall_entry(regs->r12, regs->r5, regs->r6, regs->r7, regs->r8);

return ret ?: regs->r12;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/include/asm/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ extern const unsigned long sysn32_call_table[];

static inline int syscall_get_arch(void)
{
int arch = EM_MIPS;
int arch = AUDIT_ARCH_MIPS;
#ifdef CONFIG_64BIT
if (!test_thread_flag(TIF_32BIT_REGS)) {
arch |= __AUDIT_ARCH_64BIT;
Expand Down
4 changes: 1 addition & 3 deletions arch/mips/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
trace_sys_enter(regs, regs->regs[2]);

audit_syscall_entry(syscall_get_arch(),
syscall,
regs->regs[4], regs->regs[5],
audit_syscall_entry(syscall, regs->regs[4], regs->regs[5],
regs->regs[6], regs->regs[7]);
return syscall;
}
Expand Down
5 changes: 5 additions & 0 deletions arch/openrisc/include/asm/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef __ASM_OPENRISC_SYSCALL_H__
#define __ASM_OPENRISC_SYSCALL_H__

#include <uapi/linux/audit.h>
#include <linux/err.h>
#include <linux/sched.h>

Expand Down Expand Up @@ -71,4 +72,8 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
}

static inline int syscall_get_arch(void)
{
return AUDIT_ARCH_OPENRISC;
}
#endif
3 changes: 1 addition & 2 deletions arch/openrisc/include/uapi/asm/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
/* A placeholder; OR32 does not have fp support yes, so no fp regs for now. */
typedef unsigned long elf_fpregset_t;

/* This should be moved to include/linux/elf.h */
/* EM_OPENRISC is defined in linux/elf-em.h */
#define EM_OR32 0x8472
#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */

/*
* These are used to set parameters in the core dumps.
Expand Down
3 changes: 1 addition & 2 deletions arch/openrisc/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
*/
ret = -1L;

audit_syscall_entry(AUDIT_ARCH_OPENRISC, regs->gpr[11],
regs->gpr[3], regs->gpr[4],
audit_syscall_entry(regs->gpr[11], regs->gpr[3], regs->gpr[4],
regs->gpr[5], regs->gpr[6]);

return ret ? : regs->gpr[11];
Expand Down
11 changes: 11 additions & 0 deletions arch/parisc/include/asm/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#ifndef _ASM_PARISC_SYSCALL_H_
#define _ASM_PARISC_SYSCALL_H_

#include <uapi/linux/audit.h>
#include <linux/compat.h>
#include <linux/err.h>
#include <asm/ptrace.h>

Expand Down Expand Up @@ -37,4 +39,13 @@ static inline void syscall_get_arguments(struct task_struct *tsk,
}
}

static inline int syscall_get_arch(void)
{
int arch = AUDIT_ARCH_PARISC;
#ifdef CONFIG_64BIT
if (!is_compat_task())
arch = AUDIT_ARCH_PARISC64;
#endif
return arch;
}
#endif /*_ASM_PARISC_SYSCALL_H_*/
9 changes: 3 additions & 6 deletions arch/parisc/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)

#ifdef CONFIG_64BIT
if (!is_compat_task())
audit_syscall_entry(AUDIT_ARCH_PARISC64,
regs->gr[20],
regs->gr[26], regs->gr[25],
regs->gr[24], regs->gr[23]);
audit_syscall_entry(regs->gr[20], regs->gr[26], regs->gr[25],
regs->gr[24], regs->gr[23]);
else
#endif
audit_syscall_entry(AUDIT_ARCH_PARISC,
regs->gr[20] & 0xffffffff,
audit_syscall_entry(regs->gr[20] & 0xffffffff,
regs->gr[26] & 0xffffffff,
regs->gr[25] & 0xffffffff,
regs->gr[24] & 0xffffffff,
Expand Down
6 changes: 6 additions & 0 deletions arch/powerpc/include/asm/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#ifndef _ASM_SYSCALL_H
#define _ASM_SYSCALL_H 1

#include <uapi/linux/audit.h>
#include <linux/sched.h>
#include <linux/thread_info.h>

/* ftrace syscalls requires exporting the sys_call_table */
#ifdef CONFIG_FTRACE_SYSCALLS
Expand Down Expand Up @@ -86,4 +88,8 @@ static inline void syscall_set_arguments(struct task_struct *task,
memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
}

static inline int syscall_get_arch(void)
{
return is_32bit_task() ? AUDIT_ARCH_PPC : AUDIT_ARCH_PPC64;
}
#endif /* _ASM_SYSCALL_H */
7 changes: 2 additions & 5 deletions arch/powerpc/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1788,14 +1788,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)

#ifdef CONFIG_PPC64
if (!is_32bit_task())
audit_syscall_entry(AUDIT_ARCH_PPC64,
regs->gpr[0],
regs->gpr[3], regs->gpr[4],
audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4],
regs->gpr[5], regs->gpr[6]);
else
#endif
audit_syscall_entry(AUDIT_ARCH_PPC,
regs->gpr[0],
audit_syscall_entry(regs->gpr[0],
regs->gpr[3] & 0xffffffff,
regs->gpr[4] & 0xffffffff,
regs->gpr[5] & 0xffffffff,
Expand Down
4 changes: 1 addition & 3 deletions arch/s390/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
trace_sys_enter(regs, regs->gprs[2]);

audit_syscall_entry(is_compat_task() ?
AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
regs->gprs[2], regs->orig_gpr2,
audit_syscall_entry(regs->gprs[2], regs->orig_gpr2,
regs->gprs[3], regs->gprs[4],
regs->gprs[5]);
out:
Expand Down
10 changes: 10 additions & 0 deletions arch/sh/include/asm/syscall_32.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef __ASM_SH_SYSCALL_32_H
#define __ASM_SH_SYSCALL_32_H

#include <uapi/linux/audit.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/err.h>
Expand Down Expand Up @@ -93,4 +94,13 @@ static inline void syscall_set_arguments(struct task_struct *task,
}
}

static inline int syscall_get_arch(void)
{
int arch = AUDIT_ARCH_SH;

#ifdef CONFIG_CPU_LITTLE_ENDIAN
arch |= __AUDIT_ARCH_LE;
#endif
return arch;
}
#endif /* __ASM_SH_SYSCALL_32_H */
14 changes: 14 additions & 0 deletions arch/sh/include/asm/syscall_64.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef __ASM_SH_SYSCALL_64_H
#define __ASM_SH_SYSCALL_64_H

#include <uapi/linux/audit.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <asm/ptrace.h>
Expand Down Expand Up @@ -61,4 +62,17 @@ static inline void syscall_set_arguments(struct task_struct *task,
memcpy(&regs->regs[2 + i], args, n * sizeof(args[0]));
}

static inline int syscall_get_arch(void)
{
int arch = AUDIT_ARCH_SH;

#ifdef CONFIG_64BIT
arch |= __AUDIT_ARCH_64BIT;
#endif
#ifdef CONFIG_CPU_LITTLE_ENDIAN
arch |= __AUDIT_ARCH_LE;
#endif

return arch;
}
#endif /* __ASM_SH_SYSCALL_64_H */
14 changes: 1 addition & 13 deletions arch/sh/kernel/ptrace_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,17 +484,6 @@ long arch_ptrace(struct task_struct *child, long request,
return ret;
}

static inline int audit_arch(void)
{
int arch = EM_SH;

#ifdef CONFIG_CPU_LITTLE_ENDIAN
arch |= __AUDIT_ARCH_LE;
#endif

return arch;
}

asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
{
long ret = 0;
Expand All @@ -513,8 +502,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
trace_sys_enter(regs, regs->regs[0]);

audit_syscall_entry(audit_arch(), regs->regs[3],
regs->regs[4], regs->regs[5],
audit_syscall_entry(regs->regs[3], regs->regs[4], regs->regs[5],
regs->regs[6], regs->regs[7]);

return ret ?: regs->regs[0];
Expand Down
17 changes: 1 addition & 16 deletions arch/sh/kernel/ptrace_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,20 +504,6 @@ asmlinkage int sh64_ptrace(long request, long pid,
return sys_ptrace(request, pid, addr, data);
}

static inline int audit_arch(void)
{
int arch = EM_SH;

#ifdef CONFIG_64BIT
arch |= __AUDIT_ARCH_64BIT;
#endif
#ifdef CONFIG_CPU_LITTLE_ENDIAN
arch |= __AUDIT_ARCH_LE;
#endif

return arch;
}

asmlinkage long long do_syscall_trace_enter(struct pt_regs *regs)
{
long long ret = 0;
Expand All @@ -536,8 +522,7 @@ asmlinkage long long do_syscall_trace_enter(struct pt_regs *regs)
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
trace_sys_enter(regs, regs->regs[9]);

audit_syscall_entry(audit_arch(), regs->regs[1],
regs->regs[2], regs->regs[3],
audit_syscall_entry(regs->regs[1], regs->regs[2], regs->regs[3],
regs->regs[4], regs->regs[5]);

return ret ?: regs->regs[9];
Expand Down
7 changes: 7 additions & 0 deletions arch/sparc/include/asm/syscall.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef __ASM_SPARC_SYSCALL_H
#define __ASM_SPARC_SYSCALL_H

#include <uapi/linux/audit.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <asm/ptrace.h>
#include <asm/thread_info.h>

/*
* The syscall table always contains 32 bit pointers since we know that the
Expand Down Expand Up @@ -124,4 +126,9 @@ static inline void syscall_set_arguments(struct task_struct *task,
regs->u_regs[UREG_I0 + i + j] = args[j];
}

static inline int syscall_get_arch(void)
{
return is_32bit_task() ? AUDIT_ARCH_SPARC : AUDIT_ARCH_SPARC64;
}

#endif /* __ASM_SPARC_SYSCALL_H */
2 changes: 2 additions & 0 deletions arch/sparc/include/asm/thread_info_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ register struct thread_info *current_thread_info_reg asm("g6");
#define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | \
_TIF_SIGPENDING)

#define is_32bit_task() (1)

#endif /* __KERNEL__ */

#endif /* _ASM_THREAD_INFO_H */
2 changes: 2 additions & 0 deletions arch/sparc/include/asm/thread_info_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ register struct thread_info *current_thread_info_reg asm("g6");
_TIF_NEED_RESCHED)
#define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)

#define is_32bit_task() (test_thread_flag(TIF_32BIT))

/*
* Thread-synchronous status.
*
Expand Down
Loading

0 comments on commit ab074ad

Please sign in to comment.