Skip to content

Commit 29ef73b

Browse files
drnwhAl Viro
authored andcommitted
Kernel: Audit Support For The ARM Platform
This patch provides functionality to audit system call events on the ARM platform. The implementation was based off the structure of the MIPS platform and information in this (http://lists.fedoraproject.org/pipermail/arm/2009-October/000382.html) mailing list thread. The required audit_syscall_exit and audit_syscall_entry checks were added to ptrace using the standard registers for system call values (r0 through r3). A thread information flag was added for auditing (TIF_SYSCALL_AUDIT) and a meta-flag was added (_TIF_SYSCALL_WORK) to simplify modifications to the syscall entry/exit. Now, if either the TRACE flag is set or the AUDIT flag is set, the syscall_trace function will be executed. The prober changes were made to Kconfig to allow CONFIG_AUDITSYSCALL to be enabled. Due to platform availability limitations, this patch was only tested on the Android platform running the modified "android-goldfish-2.6.29" kernel. A test compile was performed using Code Sourcery's cross-compilation toolset and the current linux-3.0 stable kernel. The changes compile without error. I'm hoping, due to the simple modifications, the patch is "obviously correct". Signed-off-by: Nathaniel Husted <nhusted@gmail.com> Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 4043cde commit 29ef73b

6 files changed

Lines changed: 25 additions & 9 deletions

File tree

‎arch/arm/include/asm/kprobes.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#define MAX_INSN_SIZE 2
2525
#define MAX_STACK_SIZE 64 /* 32 would probably be OK */
2626

27-
#define regs_return_value(regs) ((regs)->ARM_r0)
2827
#define flush_insn_slot(p) do { } while (0)
2928
#define kretprobe_blacklist_size 0
3029

‎arch/arm/include/asm/ptrace.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ static inline int valid_user_regs(struct pt_regs *regs)
189189
return 0;
190190
}
191191

192+
static inline long regs_return_value(struct pt_regs *regs)
193+
{
194+
return regs->ARM_r0;
195+
}
196+
192197
#define instruction_pointer(regs) (regs)->ARM_pc
193198

194199
#ifdef CONFIG_SMP

‎arch/arm/include/asm/thread_info.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ extern void vfp_flush_hwstate(struct thread_info *);
129129
/*
130130
* thread information flags:
131131
* TIF_SYSCALL_TRACE - syscall trace active
132+
* TIF_SYSCAL_AUDIT - syscall auditing active
132133
* TIF_SIGPENDING - signal pending
133134
* TIF_NEED_RESCHED - rescheduling necessary
134135
* TIF_NOTIFY_RESUME - callback before returning to user
@@ -139,6 +140,7 @@ extern void vfp_flush_hwstate(struct thread_info *);
139140
#define TIF_NEED_RESCHED 1
140141
#define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
141142
#define TIF_SYSCALL_TRACE 8
143+
#define TIF_SYSCALL_AUDIT 9
142144
#define TIF_POLLING_NRFLAG 16
143145
#define TIF_USING_IWMMXT 17
144146
#define TIF_MEMDIE 18 /* is terminating due to OOM killer */
@@ -149,11 +151,15 @@ extern void vfp_flush_hwstate(struct thread_info *);
149151
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
150152
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
151153
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
154+
#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
152155
#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
153156
#define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
154157
#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
155158
#define _TIF_SECCOMP (1 << TIF_SECCOMP)
156159

160+
/* Checks for any syscall work in entry-common.S */
161+
#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
162+
157163
/*
158164
* Change these and you break ASM code in entry-common.S
159165
*/

‎arch/arm/kernel/entry-common.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ ENTRY(ret_from_fork)
8787
get_thread_info tsk
8888
ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing
8989
mov why, #1
90-
tst r1, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
90+
tst r1, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
9191
beq ret_slow_syscall
9292
mov r1, sp
9393
mov r0, #1 @ trace exit [IP = 1]
@@ -443,7 +443,7 @@ ENTRY(vector_swi)
443443
1:
444444
#endif
445445

446-
tst r10, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
446+
tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
447447
bne __sys_trace
448448

449449
cmp scno, #NR_syscalls @ check upper syscall limit

‎arch/arm/kernel/ptrace.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -906,18 +906,24 @@ asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
906906
{
907907
unsigned long ip;
908908

909-
if (!test_thread_flag(TIF_SYSCALL_TRACE))
910-
return scno;
911-
if (!(current->ptrace & PT_PTRACED))
912-
return scno;
913-
914909
/*
915910
* Save IP. IP is used to denote syscall entry/exit:
916911
* IP = 0 -> entry, = 1 -> exit
917912
*/
918913
ip = regs->ARM_ip;
919914
regs->ARM_ip = why;
920915

916+
if (!ip)
917+
audit_syscall_exit(regs);
918+
else
919+
audit_syscall_entry(AUDIT_ARCH_ARMEB, scno, regs->ARM_r0,
920+
regs->ARM_r1, regs->ARM_r2, regs->ARM_r3);
921+
922+
if (!test_thread_flag(TIF_SYSCALL_TRACE))
923+
return scno;
924+
if (!(current->ptrace & PT_PTRACED))
925+
return scno;
926+
921927
current_thread_info()->syscall = scno;
922928

923929
/* the 0x80 provides a way for the tracing parent to distinguish

‎init/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ config AUDIT
355355

356356
config AUDITSYSCALL
357357
bool "Enable system-call auditing support"
358-
depends on AUDIT && (X86 || PPC || S390 || IA64 || UML || SPARC64 || SUPERH)
358+
depends on AUDIT && (X86 || PPC || S390 || IA64 || UML || SPARC64 || SUPERH || ARM)
359359
default y if SECURITY_SELINUX
360360
help
361361
Enable low-overhead system-call auditing infrastructure that

0 commit comments

Comments
 (0)