Skip to content

Commit 64c19ba

Browse files
krisman-at-collaboraKAGA-KOKO
authored andcommitted
ptrace: Migrate to use SYSCALL_TRACE flag
On architectures using the generic syscall entry code the architecture independent syscall work is moved to flags in thread_info::syscall_work. This removes architecture dependencies and frees up TIF bits. Define SYSCALL_WORK_SYSCALL_TRACE, use it in the generic entry code and convert the code which uses the TIF specific helper functions to use the new *_syscall_work() helpers which either resolve to the new mode for users of the generic entry code or to the TIF based functions for the other architectures. Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Andy Lutomirski <luto@kernel.org> Link: https://lore.kernel.org/r/20201116174206.2639648-7-krisman@collabora.com
1 parent 524666c commit 64c19ba

7 files changed

Lines changed: 31 additions & 25 deletions

File tree

‎include/asm-generic/syscall.h‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int syscall_get_nr(struct task_struct *task, struct pt_regs *regs);
4343
* @regs: task_pt_regs() of @task
4444
*
4545
* It's only valid to call this when @task is stopped for system
46-
* call exit tracing (due to TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT),
46+
* call exit tracing (due to %SYSCALL_WORK_SYSCALL_TRACE or TIF_SYSCALL_AUDIT),
4747
* after tracehook_report_syscall_entry() returned nonzero to prevent
4848
* the system call from taking place.
4949
*
@@ -63,7 +63,7 @@ void syscall_rollback(struct task_struct *task, struct pt_regs *regs);
6363
* Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
6464
*
6565
* It's only valid to call this when @task is stopped for tracing on exit
66-
* from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
66+
* from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
6767
*/
6868
long syscall_get_error(struct task_struct *task, struct pt_regs *regs);
6969

@@ -76,7 +76,7 @@ long syscall_get_error(struct task_struct *task, struct pt_regs *regs);
7676
* This value is meaningless if syscall_get_error() returned nonzero.
7777
*
7878
* It's only valid to call this when @task is stopped for tracing on exit
79-
* from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
79+
* from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
8080
*/
8181
long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs);
8282

@@ -93,7 +93,7 @@ long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs);
9393
* code; the user sees a failed system call with this errno code.
9494
*
9595
* It's only valid to call this when @task is stopped for tracing on exit
96-
* from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
96+
* from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
9797
*/
9898
void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
9999
int error, long val);
@@ -108,7 +108,7 @@ void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
108108
* @args[0], and so on.
109109
*
110110
* It's only valid to call this when @task is stopped for tracing on
111-
* entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
111+
* entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
112112
*/
113113
void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
114114
unsigned long *args);
@@ -123,7 +123,7 @@ void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
123123
* The first argument gets value @args[0], and so on.
124124
*
125125
* It's only valid to call this when @task is stopped for tracing on
126-
* entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
126+
* entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
127127
*/
128128
void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
129129
const unsigned long *args);
@@ -135,7 +135,8 @@ void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
135135
* Returns the AUDIT_ARCH_* based on the system call convention in use.
136136
*
137137
* It's only valid to call this when @task is stopped on entry to a system
138-
* call, due to %TIF_SYSCALL_TRACE, %TIF_SYSCALL_AUDIT, or %SYSCALL_WORK_SECCOMP.
138+
* call, due to %SYSCALL_WORK_SYSCALL_TRACE, %TIF_SYSCALL_AUDIT, or
139+
* %SYSCALL_WORK_SECCOMP.
139140
*
140141
* Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
141142
* provide an implementation of this.

‎include/linux/entry-common.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#endif
4242

4343
#define SYSCALL_ENTER_WORK \
44-
(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
44+
(_TIF_SYSCALL_AUDIT | \
4545
_TIF_SYSCALL_EMU | \
4646
ARCH_SYSCALL_ENTER_WORK)
4747

@@ -53,12 +53,14 @@
5353
#endif
5454

5555
#define SYSCALL_EXIT_WORK \
56-
(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
56+
(_TIF_SYSCALL_AUDIT | \
5757
ARCH_SYSCALL_EXIT_WORK)
5858

5959
#define SYSCALL_WORK_ENTER (SYSCALL_WORK_SECCOMP | \
60-
SYSCALL_WORK_SYSCALL_TRACEPOINT)
61-
#define SYSCALL_WORK_EXIT (SYSCALL_WORK_SYSCALL_TRACEPOINT)
60+
SYSCALL_WORK_SYSCALL_TRACEPOINT | \
61+
SYSCALL_WORK_SYSCALL_TRACE)
62+
#define SYSCALL_WORK_EXIT (SYSCALL_WORK_SYSCALL_TRACEPOINT | \
63+
SYSCALL_WORK_SYSCALL_TRACE)
6264

6365
/*
6466
* TIF flags handled in exit_to_user_mode_loop()

‎include/linux/thread_info.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ enum {
3838
enum syscall_work_bit {
3939
SYSCALL_WORK_BIT_SECCOMP,
4040
SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT,
41+
SYSCALL_WORK_BIT_SYSCALL_TRACE,
4142
};
4243

4344
#define SYSCALL_WORK_SECCOMP BIT(SYSCALL_WORK_BIT_SECCOMP)
4445
#define SYSCALL_WORK_SYSCALL_TRACEPOINT BIT(SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT)
46+
#define SYSCALL_WORK_SYSCALL_TRACE BIT(SYSCALL_WORK_BIT_SYSCALL_TRACE)
4547

4648
#include <asm/thread_info.h>
4749

‎include/linux/tracehook.h‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ static inline int ptrace_report_syscall(struct pt_regs *regs,
8383
* tracehook_report_syscall_entry - task is about to attempt a system call
8484
* @regs: user register state of current task
8585
*
86-
* This will be called if %TIF_SYSCALL_TRACE or %TIF_SYSCALL_EMU have been set,
87-
* when the current task has just entered the kernel for a system call.
88-
* Full user register state is available here. Changing the values
89-
* in @regs can affect the system call number and arguments to be tried.
90-
* It is safe to block here, preventing the system call from beginning.
86+
* This will be called if %SYSCALL_WORK_SYSCALL_TRACE or
87+
* %TIF_SYSCALL_EMU have been set, when the current task has just
88+
* entered the kernel for a system call. Full user register state is
89+
* available here. Changing the values in @regs can affect the system
90+
* call number and arguments to be tried. It is safe to block here,
91+
* preventing the system call from beginning.
9192
*
9293
* Returns zero normally, or nonzero if the calling arch code should abort
9394
* the system call. That must prevent normal entry so no system call is
@@ -109,15 +110,15 @@ static inline __must_check int tracehook_report_syscall_entry(
109110
* @regs: user register state of current task
110111
* @step: nonzero if simulating single-step or block-step
111112
*
112-
* This will be called if %TIF_SYSCALL_TRACE has been set, when the
113-
* current task has just finished an attempted system call. Full
113+
* This will be called if %SYSCALL_WORK_SYSCALL_TRACE has been set, when
114+
* the current task has just finished an attempted system call. Full
114115
* user register state is available here. It is safe to block here,
115116
* preventing signals from being processed.
116117
*
117118
* If @step is nonzero, this report is also in lieu of the normal
118119
* trap that would follow the system call instruction because
119120
* user_enable_block_step() or user_enable_single_step() was used.
120-
* In this case, %TIF_SYSCALL_TRACE might not be set.
121+
* In this case, %SYSCALL_WORK_SYSCALL_TRACE might not be set.
121122
*
122123
* Called without locks, just before checking for pending signals.
123124
*/

‎kernel/entry/common.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static long syscall_trace_enter(struct pt_regs *regs, long syscall,
4747
long ret = 0;
4848

4949
/* Handle ptrace */
50-
if (ti_work & (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU)) {
50+
if (work & SYSCALL_WORK_SYSCALL_TRACE || ti_work & _TIF_SYSCALL_EMU) {
5151
ret = arch_syscall_enter_tracehook(regs);
5252
if (ret || (ti_work & _TIF_SYSCALL_EMU))
5353
return -1L;
@@ -237,7 +237,7 @@ static void syscall_exit_work(struct pt_regs *regs, unsigned long ti_work,
237237
trace_sys_exit(regs, syscall_get_return_value(current, regs));
238238

239239
step = report_single_step(ti_work);
240-
if (step || ti_work & _TIF_SYSCALL_TRACE)
240+
if (step || work & SYSCALL_WORK_SYSCALL_TRACE)
241241
arch_syscall_exit_tracehook(regs, step);
242242
}
243243

‎kernel/fork.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@ static __latent_entropy struct task_struct *copy_process(
21582158
* child regardless of CLONE_PTRACE.
21592159
*/
21602160
user_disable_single_step(p);
2161-
clear_tsk_thread_flag(p, TIF_SYSCALL_TRACE);
2161+
clear_task_syscall_work(p, SYSCALL_TRACE);
21622162
#ifdef TIF_SYSCALL_EMU
21632163
clear_tsk_thread_flag(p, TIF_SYSCALL_EMU);
21642164
#endif

‎kernel/ptrace.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void __ptrace_unlink(struct task_struct *child)
117117
const struct cred *old_cred;
118118
BUG_ON(!child->ptrace);
119119

120-
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
120+
clear_task_syscall_work(child, SYSCALL_TRACE);
121121
#ifdef TIF_SYSCALL_EMU
122122
clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
123123
#endif
@@ -812,9 +812,9 @@ static int ptrace_resume(struct task_struct *child, long request,
812812
return -EIO;
813813

814814
if (request == PTRACE_SYSCALL)
815-
set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
815+
set_task_syscall_work(child, SYSCALL_TRACE);
816816
else
817-
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
817+
clear_task_syscall_work(child, SYSCALL_TRACE);
818818

819819
#ifdef TIF_SYSCALL_EMU
820820
if (request == PTRACE_SYSEMU || request == PTRACE_SYSEMU_SINGLESTEP)

0 commit comments

Comments
 (0)