Skip to contentSkip to conversation

syscall_trace fixes and cleanups

PATCH Superseded Will Deacon 2 participants 7 messages Jun 8, 2012 – Jun 12, 2012

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover syscall_trace fixes and cleanups

Hello,

This is version 2 of the patches originally posted here:

http://lists.infradead.org/pipermail/linux-arm-kernel/2012-May/097748.html

The only changes are that (a) two of the original patches (fixes) have been now been merged into mainline and (b) the remaining patches in the series are now rebased onto -rc1, which includes Al's work on the signal handling / syscall restarting path.

All comments welcome,

Will

Will Deacon (4):
audit: arm: only allow syscall auditing for pure EABI userspace
ARM: entry: don't bother with syscall tracing on ret_from_fork path
ARM: audit: move syscall auditing until after ptrace SIGTRAP handling
ARM: ptrace: provide separate functions for tracing syscall

    {entry,exit}
 arch/arm/kernel/entry-common.S |   20 +++++-------------
 arch/arm/kernel/ptrace.c       |   42 ++++++++++++++++++++++++++++-----------
 init/Kconfig                   |    2 +-
 3 files changed, 37 insertions(+), 27 deletions(-)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH v2 1/4 audit: arm: only allow syscall auditing for pure EABI userspace

The audit tools support only EABI userspace and, since there are no AUDIT_ARCH_* defines for the ARM OABI, it makes sense to allow syscall auditing on ARM only for EABI at the moment.

---
 init/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
init/Kconfig +1 -1
index d07dcf9..b3f55f1 100644
@@ -357,7 +357,7 @@ config AUDIT
 
 config AUDITSYSCALL
 	bool "Enable system-call auditing support"
-	depends on AUDIT && (X86 || PPC || S390 || IA64 || UML || SPARC64 || SUPERH || ARM)
+	depends on AUDIT && (X86 || PPC || S390 || IA64 || UML || SPARC64 || SUPERH || (ARM && AEABI && !OABI_COMPAT))
 	default y if SECURITY_SELINUX
 	help
 	  Enable low-overhead system-call auditing infrastructure that
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH v2 2/4 ARM: entry: don't bother with syscall tracing on ret_from_fork path

In reply to Will Deacon

ret_from_fork is setup for a freshly spawned child task via copy_thread, called from copy_process. The latter function clears TIF_SYSCALL_TRACE and also resets the child task's audit_context to NULL, meaning that there is little point invoking the system call tracing routines. Furthermore, getting hold of the syscall number is a complete pain and it looks like the current code doesn't even bother.

This patch removes the syscall tracing checks from ret_from_fork.

---
 arch/arm/kernel/entry-common.S |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
arch/arm/kernel/entry-common.S +0 -6
index 4afed88..10911c9 100644
@@ -95,13 +95,7 @@ ENDPROC(ret_to_user)
 ENTRY(ret_from_fork)
 	bl	schedule_tail
 	get_thread_info tsk
-	ldr	r1, [tsk, #TI_FLAGS]		@ check for syscall tracing
 	mov	why, #1
-	tst	r1, #_TIF_SYSCALL_WORK		@ are we tracing syscalls?
-	beq	ret_slow_syscall
-	mov	r1, sp
-	mov	r0, #1				@ trace exit [IP = 1]
-	bl	syscall_trace
 	b	ret_slow_syscall
 ENDPROC(ret_from_fork)
 
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH v2 3/4 ARM: audit: move syscall auditing until after ptrace SIGTRAP handling

In reply to Will Deacon

When auditing system calls on ARM, the audit code is called before notifying the parent process in the case that the current task is being ptraced. At this point, the parent (debugger) may choose to change the system call being issued via the SET_SYSCALL ptrace request, causing the wrong system call to be reported to the audit tools.

This patch moves the audit calls after the ptrace SIGTRAP handling code in the syscall tracing implementation.

---
 arch/arm/kernel/ptrace.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
arch/arm/kernel/ptrace.c +10 -8
index 5700a7a..5256068 100644
@@ -912,16 +912,11 @@ asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
 {
 	unsigned long ip;
 
-	if (why)
-		audit_syscall_exit(regs);
-	else
-		audit_syscall_entry(AUDIT_ARCH_ARM, scno, regs->ARM_r0,
-				    regs->ARM_r1, regs->ARM_r2, regs->ARM_r3);
-
 	if (why == 0 && test_and_clear_thread_flag(TIF_SYSCALL_RESTARTSYS))
 		scno = __NR_restart_syscall - __NR_SYSCALL_BASE;
+
 	if (!test_thread_flag(TIF_SYSCALL_TRACE))
-		return scno;
+		goto out_no_trace;
 
 	current_thread_info()->syscall = scno;
 
@@ -938,6 +933,13 @@ asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
 		current_thread_info()->syscall = -1;
 
 	regs->ARM_ip = ip;
+	scno = current_thread_info()->syscall;
 
-	return current_thread_info()->syscall;
+out_no_trace:
+	if (why)
+		audit_syscall_exit(regs);
+	else
+		audit_syscall_entry(AUDIT_ARCH_ARM, scno, regs->ARM_r0,
+				    regs->ARM_r1, regs->ARM_r2, regs->ARM_r3);
+	return scno;
 }
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH v2 4/4 ARM: ptrace: provide separate functions for tracing syscall {entry, exit}

In reply to Will Deacon

The syscall_trace on ARM takes a `why' parameter to indicate whether or not we are entering or exiting a system call. This can be confusing for people looking at the code since (a) it conflicts with the why register alias in the entry assembly code and (b) it is not immediately clear what it represents.

This patch splits up the syscall_trace function into separate wrappers for syscall entry and exit, allowing the low-level syscall handling code to branch to the appropriate function.

---
 arch/arm/kernel/entry-common.S |   14 +++++-------
 arch/arm/kernel/ptrace.c       |   46 +++++++++++++++++++++++++++-------------
 2 files changed, 37 insertions(+), 23 deletions(-)
arch/arm/kernel/entry-common.S +6 -8
index 10911c9..49d9f93 100644
@@ -442,10 +442,9 @@ ENDPROC(vector_swi)
 	 * context switches, and waiting for our parent to respond.
 	 */
 __sys_trace:
-	mov	r2, scno
-	add	r1, sp, #S_OFF
-	mov	r0, #0				@ trace entry [IP = 0]
-	bl	syscall_trace
+	mov	r1, scno
+	add	r0, sp, #S_OFF
+	bl	syscall_trace_enter
 
 	adr	lr, BSYM(__sys_trace_return)	@ return address
 	mov	scno, r0			@ syscall number (possibly new)
@@ -457,10 +456,9 @@ __sys_trace:
 
 __sys_trace_return:
 	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
-	mov	r2, scno
-	mov	r1, sp
-	mov	r0, #1				@ trace exit [IP = 1]
-	bl	syscall_trace
+	mov	r1, scno
+	mov	r0, sp
+	bl	syscall_trace_exit
 	b	ret_slow_syscall
 
 	.align	5
arch/arm/kernel/ptrace.c +31 -15

67 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#5 lore raw

v2 cover syscall_trace fixes and cleanups

In reply to Will Deacon
Quoted 4 lines · Will Deacon

Hello,

This is version 2 of the patches originally posted here:

Quoted 8 lines

http://lists.infradead.org/pipermail/linux-arm-kernel/2012-May/097748.html

The only changes are that (a) two of the original patches (fixes) have been now been merged into mainline and (b) the remaining patches in the series are now rebased onto -rc1, which includes Al's work on the signal handling / syscall restarting path.

All comments welcome,

It may be a good idea to Cc Al on these.

#6 lore raw

v2 cover syscall_trace fixes and cleanups

Hi Russell,

Quoted 9 lines · Russell King - ARM Linux
Quoted 6 lines · Will Deacon

The only changes are that (a) two of the original patches (fixes) have been now been merged into mainline and (b) the remaining patches in the series are now rebased onto -rc1, which includes Al's work on the signal handling / syscall restarting path.

All comments welcome,

It may be a good idea to Cc Al on these.

Sure. Since I've not received any other comments on this series, I'll repost this week with Al on CC.

Will