[PATCH v3 3/3] m68k: track syscalls being traced with shallow user context stack

Michael Schmitz
2021-06-20T08:14:48Z

Add 'status' field to thread_info struct to hold syscall trace
status info.

Set flag bit in thread_info->status at syscall trace entry, clear
flag bit on trace exit.

Set another flag bit on entering syscall where the full stack
frame has been saved. These flags can be checked whenever a
syscall calls ptrace_stop().

Tested on ARAnyM only - boots and survives running strace on a
binary, nothing fancy.

CC: Eric W. Biederman <ebiederm@xmission.com>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
---
arch/m68k/include/asm/entry.h | 5 +++++
arch/m68k/include/asm/thread_info.h | 1 +
arch/m68k/kernel/asm-offsets.c | 1 +
arch/m68k/kernel/entry.S | 8 ++++++++
4 files changed, 15 insertions(+)

diff --git a/arch/m68k/include/asm/entry.h b/arch/m68k/include/asm/entry.h
index 9b52b06..e6a5318 100644
--- a/arch/m68k/include/asm/entry.h
+++ b/arch/m68k/include/asm/entry.h
@@ -41,6 +41,11 @@
#define ALLOWINT (~0x700)
#endif /* machine compilation types */

+#define TIS_TRACE_ON (0x1)
+#define TIS_TRACE_OFF (0xfe)
+#define TIS_SWITCH_STACK (0x2)
+#define TIS_NO_SWITCH_STACK (0xfd)
+
#ifdef __ASSEMBLY__
/*
* This defines the normal kernel pt-regs layout.
diff --git a/arch/m68k/include/asm/thread_info.h b/arch/m68k/include/asm/thread_info.h
index 15a7570..a88b48b 100644
--- a/arch/m68k/include/asm/thread_info.h
+++ b/arch/m68k/include/asm/thread_info.h
@@ -29,6 +29,7 @@ struct thread_info {
unsigned long flags;
mm_segment_t addr_limit; /* thread address space */
int preempt_count; /* 0 => preemptable, <0 => BUG */
+ unsigned int status; /* thread-synchronous flags */
__u32 cpu; /* should always be 0 on m68k */
unsigned long tp_value; /* thread pointer */
};
diff --git a/arch/m68k/kernel/asm-offsets.c b/arch/m68k/kernel/asm-offsets.c
index ccea355..ac1ec8f 100644
--- a/arch/m68k/kernel/asm-offsets.c
+++ b/arch/m68k/kernel/asm-offsets.c
@@ -41,6 +41,7 @@ int main(void)
/* offsets into the thread_info struct */
DEFINE(TINFO_PREEMPT, offsetof(struct thread_info, preempt_count));
DEFINE(TINFO_FLAGS, offsetof(struct thread_info, flags));
+ DEFINE(TINFO_STATUS, offsetof(struct thread_info, status));

/* offsets into the pt_regs */
DEFINE(PT_OFF_D0, offsetof(struct pt_regs, d0));
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index 0c25038..7fe0cdf 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -77,10 +77,14 @@ ENTRY(__sys_clone3)
rts

ENTRY(__sys_exit)
+ movel %curptr@(TASK_STACK),%a1
+ orb #TIS_SWITCH_STACK, %a1@(TINFO_STATUS+3)
SAVE_SWITCH_STACK
pea %sp@(SWITCH_STACK_SIZE)
jbsr m68k_exit
lea %sp@(28),%sp
+ movel %curptr@(TASK_STACK),%a1
+ andb #TIS_NO_SWITCH_STACK, %a1@(TINFO_STATUS+3)
rts

ENTRY(__sys_exit_group)
@@ -200,6 +204,7 @@ ENTRY(ret_from_user_rt_signal)
#else

do_trace_entry:
+ orb #TIS_TRACE_ON, %a1@(TINFO_STATUS+3)
movel #-ENOSYS,%sp@(PT_OFF_D0)| needed for strace
subql #4,%sp
SAVE_SWITCH_STACK
@@ -210,6 +215,7 @@ do_trace_entry:
cmpl #NR_syscalls,%d0
jcs syscall
badsys:
+ andb #TIS_TRACE_OFF, %a1@(TINFO_STATUS+3)
movel #-ENOSYS,%sp@(PT_OFF_D0)
jra ret_from_syscall

@@ -219,6 +225,8 @@ do_trace_exit:
jbsr syscall_trace
RESTORE_SWITCH_STACK
addql #4,%sp
+ movel %curptr@(TASK_STACK),%a1
+ andb #TIS_TRACE_OFF, %a1@(TINFO_STATUS+3)
jra .Lret_from_exception

ENTRY(ret_from_signal)
--
2.7.4