Skip to content

Commit 1930a6e

Browse files
committed
Merge tag 'ptrace-cleanups-for-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull ptrace cleanups from Eric Biederman: "This set of changes removes tracehook.h, moves modification of all of the ptrace fields inside of siglock to remove races, adds a missing permission check to ptrace.c The removal of tracehook.h is quite significant as it has been a major source of confusion in recent years. Much of that confusion was around task_work and TIF_NOTIFY_SIGNAL (which I have now decoupled making the semantics clearer). For people who don't know tracehook.h is a vestiage of an attempt to implement uprobes like functionality that was never fully merged, and was later superseeded by uprobes when uprobes was merged. For many years now we have been removing what tracehook functionaly a little bit at a time. To the point where anything left in tracehook.h was some weird strange thing that was difficult to understand" * tag 'ptrace-cleanups-for-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: ptrace: Remove duplicated include in ptrace.c ptrace: Check PTRACE_O_SUSPEND_SECCOMP permission on PTRACE_SEIZE ptrace: Return the signal to continue with from ptrace_stop ptrace: Move setting/clearing ptrace_message into ptrace_stop tracehook: Remove tracehook.h resume_user_mode: Move to resume_user_mode.h resume_user_mode: Remove #ifdef TIF_NOTIFY_RESUME in set_notify_resume signal: Move set_notify_signal and clear_notify_signal into sched/signal.h task_work: Decouple TIF_NOTIFY_SIGNAL and task_work task_work: Call tracehook_notify_signal from get_signal on all architectures task_work: Introduce task_work_pending task_work: Remove unnecessary include from posix_timers.h ptrace: Remove tracehook_signal_handler ptrace: Remove arch_syscall_{enter,exit}_tracehook ptrace: Create ptrace_report_syscall_{entry,exit} in ptrace.h ptrace/arm: Rename tracehook_report_syscall report_syscall ptrace: Move ptrace_report_syscall into ptrace.h
2 parents 0a815d0 + dcbc65a commit 1930a6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+368
-489
lines changed

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15930,7 +15930,6 @@ F: arch/*/ptrace*.c
1593015930
F: include/asm-generic/syscall.h
1593115931
F: include/linux/ptrace.h
1593215932
F: include/linux/regset.h
15933-
F: include/linux/tracehook.h
1593415933
F: include/uapi/linux/ptrace.h
1593515934
F: include/uapi/linux/ptrace.h
1593615935
F: kernel/ptrace.c

arch/Kconfig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,8 @@ config TRACE_IRQFLAGS_SUPPORT
217217
# asm/syscall.h supplying asm-generic/syscall.h interface
218218
# linux/regset.h user_regset interfaces
219219
# CORE_DUMP_USE_REGSET #define'd in linux/elf.h
220-
# TIF_SYSCALL_TRACE calls tracehook_report_syscall_{entry,exit}
221-
# TIF_NOTIFY_RESUME calls tracehook_notify_resume()
222-
# signal delivery calls tracehook_signal_handler()
220+
# TIF_SYSCALL_TRACE calls ptrace_report_syscall_{entry,exit}
221+
# TIF_NOTIFY_RESUME calls resume_user_mode_work()
223222
#
224223
config HAVE_ARCH_TRACEHOOK
225224
bool

arch/alpha/kernel/ptrace.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <linux/user.h>
1616
#include <linux/security.h>
1717
#include <linux/signal.h>
18-
#include <linux/tracehook.h>
1918
#include <linux/audit.h>
2019

2120
#include <linux/uaccess.h>
@@ -323,7 +322,7 @@ asmlinkage unsigned long syscall_trace_enter(void)
323322
unsigned long ret = 0;
324323
struct pt_regs *regs = current_pt_regs();
325324
if (test_thread_flag(TIF_SYSCALL_TRACE) &&
326-
tracehook_report_syscall_entry(current_pt_regs()))
325+
ptrace_report_syscall_entry(current_pt_regs()))
327326
ret = -1UL;
328327
audit_syscall_entry(regs->r0, regs->r16, regs->r17, regs->r18, regs->r19);
329328
return ret ?: current_pt_regs()->r0;
@@ -334,5 +333,5 @@ syscall_trace_leave(void)
334333
{
335334
audit_syscall_exit(current_pt_regs());
336335
if (test_thread_flag(TIF_SYSCALL_TRACE))
337-
tracehook_report_syscall_exit(current_pt_regs(), 0);
336+
ptrace_report_syscall_exit(current_pt_regs(), 0);
338337
}

arch/alpha/kernel/signal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <linux/binfmts.h>
2323
#include <linux/bitops.h>
2424
#include <linux/syscalls.h>
25-
#include <linux/tracehook.h>
25+
#include <linux/resume_user_mode.h>
2626

2727
#include <linux/uaccess.h>
2828
#include <asm/sigcontext.h>
@@ -531,7 +531,7 @@ do_work_pending(struct pt_regs *regs, unsigned long thread_flags,
531531
do_signal(regs, r0, r19);
532532
r0 = 0;
533533
} else {
534-
tracehook_notify_resume(regs);
534+
resume_user_mode_work(regs);
535535
}
536536
}
537537
local_irq_disable();

arch/arc/kernel/ptrace.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
#include <linux/ptrace.h>
7-
#include <linux/tracehook.h>
87
#include <linux/sched/task_stack.h>
98
#include <linux/regset.h>
109
#include <linux/unistd.h>
@@ -258,13 +257,13 @@ long arch_ptrace(struct task_struct *child, long request,
258257

259258
asmlinkage int syscall_trace_entry(struct pt_regs *regs)
260259
{
261-
if (tracehook_report_syscall_entry(regs))
260+
if (ptrace_report_syscall_entry(regs))
262261
return ULONG_MAX;
263262

264263
return regs->r8;
265264
}
266265

267266
asmlinkage void syscall_trace_exit(struct pt_regs *regs)
268267
{
269-
tracehook_report_syscall_exit(regs, 0);
268+
ptrace_report_syscall_exit(regs, 0);
270269
}

arch/arc/kernel/signal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#include <linux/personality.h>
5050
#include <linux/uaccess.h>
5151
#include <linux/syscalls.h>
52-
#include <linux/tracehook.h>
52+
#include <linux/resume_user_mode.h>
5353
#include <linux/sched/task_stack.h>
5454

5555
#include <asm/ucontext.h>
@@ -438,5 +438,5 @@ void do_notify_resume(struct pt_regs *regs)
438438
* user mode
439439
*/
440440
if (test_thread_flag(TIF_NOTIFY_RESUME))
441-
tracehook_notify_resume(regs);
441+
resume_user_mode_work(regs);
442442
}

arch/arm/kernel/ptrace.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <linux/hw_breakpoint.h>
2323
#include <linux/regset.h>
2424
#include <linux/audit.h>
25-
#include <linux/tracehook.h>
2625
#include <linux/unistd.h>
2726

2827
#include <asm/syscall.h>
@@ -831,8 +830,7 @@ enum ptrace_syscall_dir {
831830
PTRACE_SYSCALL_EXIT,
832831
};
833832

834-
static void tracehook_report_syscall(struct pt_regs *regs,
835-
enum ptrace_syscall_dir dir)
833+
static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir)
836834
{
837835
unsigned long ip;
838836

@@ -844,8 +842,8 @@ static void tracehook_report_syscall(struct pt_regs *regs,
844842
regs->ARM_ip = dir;
845843

846844
if (dir == PTRACE_SYSCALL_EXIT)
847-
tracehook_report_syscall_exit(regs, 0);
848-
else if (tracehook_report_syscall_entry(regs))
845+
ptrace_report_syscall_exit(regs, 0);
846+
else if (ptrace_report_syscall_entry(regs))
849847
current_thread_info()->abi_syscall = -1;
850848

851849
regs->ARM_ip = ip;
@@ -856,7 +854,7 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
856854
int scno;
857855

858856
if (test_thread_flag(TIF_SYSCALL_TRACE))
859-
tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
857+
report_syscall(regs, PTRACE_SYSCALL_ENTER);
860858

861859
/* Do seccomp after ptrace; syscall may have changed. */
862860
#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
@@ -897,5 +895,5 @@ asmlinkage void syscall_trace_exit(struct pt_regs *regs)
897895
trace_sys_exit(regs, regs_return_value(regs));
898896

899897
if (test_thread_flag(TIF_SYSCALL_TRACE))
900-
tracehook_report_syscall(regs, PTRACE_SYSCALL_EXIT);
898+
report_syscall(regs, PTRACE_SYSCALL_EXIT);
901899
}

arch/arm/kernel/signal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <linux/signal.h>
1010
#include <linux/personality.h>
1111
#include <linux/uaccess.h>
12-
#include <linux/tracehook.h>
12+
#include <linux/resume_user_mode.h>
1313
#include <linux/uprobes.h>
1414
#include <linux/syscalls.h>
1515

@@ -627,7 +627,7 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
627627
} else if (thread_flags & _TIF_UPROBE) {
628628
uprobe_notify_resume(regs);
629629
} else {
630-
tracehook_notify_resume(regs);
630+
resume_user_mode_work(regs);
631631
}
632632
}
633633
local_irq_disable();

arch/arm64/kernel/ptrace.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <linux/perf_event.h>
2828
#include <linux/hw_breakpoint.h>
2929
#include <linux/regset.h>
30-
#include <linux/tracehook.h>
3130
#include <linux/elf.h>
3231

3332
#include <asm/compat.h>
@@ -1792,8 +1791,7 @@ enum ptrace_syscall_dir {
17921791
PTRACE_SYSCALL_EXIT,
17931792
};
17941793

1795-
static void tracehook_report_syscall(struct pt_regs *regs,
1796-
enum ptrace_syscall_dir dir)
1794+
static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir)
17971795
{
17981796
int regno;
17991797
unsigned long saved_reg;
@@ -1819,11 +1817,11 @@ static void tracehook_report_syscall(struct pt_regs *regs,
18191817
regs->regs[regno] = dir;
18201818

18211819
if (dir == PTRACE_SYSCALL_ENTER) {
1822-
if (tracehook_report_syscall_entry(regs))
1820+
if (ptrace_report_syscall_entry(regs))
18231821
forget_syscall(regs);
18241822
regs->regs[regno] = saved_reg;
18251823
} else if (!test_thread_flag(TIF_SINGLESTEP)) {
1826-
tracehook_report_syscall_exit(regs, 0);
1824+
ptrace_report_syscall_exit(regs, 0);
18271825
regs->regs[regno] = saved_reg;
18281826
} else {
18291827
regs->regs[regno] = saved_reg;
@@ -1833,7 +1831,7 @@ static void tracehook_report_syscall(struct pt_regs *regs,
18331831
* tracer modifications to the registers may have rewound the
18341832
* state machine.
18351833
*/
1836-
tracehook_report_syscall_exit(regs, 1);
1834+
ptrace_report_syscall_exit(regs, 1);
18371835
}
18381836
}
18391837

@@ -1842,7 +1840,7 @@ int syscall_trace_enter(struct pt_regs *regs)
18421840
unsigned long flags = read_thread_flags();
18431841

18441842
if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
1845-
tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
1843+
report_syscall(regs, PTRACE_SYSCALL_ENTER);
18461844
if (flags & _TIF_SYSCALL_EMU)
18471845
return NO_SYSCALL;
18481846
}
@@ -1870,7 +1868,7 @@ void syscall_trace_exit(struct pt_regs *regs)
18701868
trace_sys_exit(regs, syscall_get_return_value(current, regs));
18711869

18721870
if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP))
1873-
tracehook_report_syscall(regs, PTRACE_SYSCALL_EXIT);
1871+
report_syscall(regs, PTRACE_SYSCALL_EXIT);
18741872

18751873
rseq_syscall(regs);
18761874
}

arch/arm64/kernel/signal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <linux/uaccess.h>
1717
#include <linux/sizes.h>
1818
#include <linux/string.h>
19-
#include <linux/tracehook.h>
19+
#include <linux/resume_user_mode.h>
2020
#include <linux/ratelimit.h>
2121
#include <linux/syscalls.h>
2222

@@ -942,7 +942,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags)
942942
do_signal(regs);
943943

944944
if (thread_flags & _TIF_NOTIFY_RESUME)
945-
tracehook_notify_resume(regs);
945+
resume_user_mode_work(regs);
946946

947947
if (thread_flags & _TIF_FOREIGN_FPSTATE)
948948
fpsimd_restore_current_state();

arch/csky/kernel/ptrace.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/sched/task_stack.h>
1313
#include <linux/signal.h>
1414
#include <linux/smp.h>
15-
#include <linux/tracehook.h>
1615
#include <linux/uaccess.h>
1716
#include <linux/user.h>
1817

@@ -321,7 +320,7 @@ long arch_ptrace(struct task_struct *child, long request,
321320
asmlinkage int syscall_trace_enter(struct pt_regs *regs)
322321
{
323322
if (test_thread_flag(TIF_SYSCALL_TRACE))
324-
if (tracehook_report_syscall_entry(regs))
323+
if (ptrace_report_syscall_entry(regs))
325324
return -1;
326325

327326
if (secure_computing() == -1)
@@ -339,7 +338,7 @@ asmlinkage void syscall_trace_exit(struct pt_regs *regs)
339338
audit_syscall_exit(regs);
340339

341340
if (test_thread_flag(TIF_SYSCALL_TRACE))
342-
tracehook_report_syscall_exit(regs, 0);
341+
ptrace_report_syscall_exit(regs, 0);
343342

344343
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
345344
trace_sys_exit(regs, syscall_get_return_value(current, regs));

arch/csky/kernel/signal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <linux/signal.h>
44
#include <linux/uaccess.h>
55
#include <linux/syscalls.h>
6-
#include <linux/tracehook.h>
6+
#include <linux/resume_user_mode.h>
77

88
#include <asm/traps.h>
99
#include <asm/ucontext.h>
@@ -265,5 +265,5 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,
265265
do_signal(regs);
266266

267267
if (thread_info_flags & _TIF_NOTIFY_RESUME)
268-
tracehook_notify_resume(regs);
268+
resume_user_mode_work(regs);
269269
}

arch/h8300/kernel/ptrace.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/errno.h>
1313
#include <linux/ptrace.h>
1414
#include <linux/audit.h>
15-
#include <linux/tracehook.h>
1615
#include <linux/regset.h>
1716
#include <linux/elf.h>
1817

@@ -174,7 +173,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
174173
long ret = 0;
175174

176175
if (test_thread_flag(TIF_SYSCALL_TRACE) &&
177-
tracehook_report_syscall_entry(regs))
176+
ptrace_report_syscall_entry(regs))
178177
/*
179178
* Tracing decided this syscall should not happen.
180179
* We'll return a bogus call number to get an ENOSYS
@@ -196,5 +195,5 @@ asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
196195

197196
step = test_thread_flag(TIF_SINGLESTEP);
198197
if (step || test_thread_flag(TIF_SYSCALL_TRACE))
199-
tracehook_report_syscall_exit(regs, step);
198+
ptrace_report_syscall_exit(regs, step);
200199
}

arch/h8300/kernel/signal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <linux/personality.h>
4040
#include <linux/tty.h>
4141
#include <linux/binfmts.h>
42-
#include <linux/tracehook.h>
42+
#include <linux/resume_user_mode.h>
4343

4444
#include <asm/setup.h>
4545
#include <linux/uaccess.h>
@@ -283,5 +283,5 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
283283
do_signal(regs);
284284

285285
if (thread_info_flags & _TIF_NOTIFY_RESUME)
286-
tracehook_notify_resume(regs);
286+
resume_user_mode_work(regs);
287287
}

arch/hexagon/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <linux/tick.h>
1515
#include <linux/uaccess.h>
1616
#include <linux/slab.h>
17-
#include <linux/tracehook.h>
17+
#include <linux/resume_user_mode.h>
1818

1919
/*
2020
* Program thread launch. Often defined as a macro in processor.h,
@@ -177,7 +177,7 @@ int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
177177
}
178178

179179
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
180-
tracehook_notify_resume(regs);
180+
resume_user_mode_work(regs);
181181
return 1;
182182
}
183183

arch/hexagon/kernel/signal.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <linux/linkage.h>
99
#include <linux/syscalls.h>
10-
#include <linux/tracehook.h>
1110
#include <linux/sched/task_stack.h>
1211

1312
#include <asm/registers.h>

arch/hexagon/kernel/traps.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <linux/kdebug.h>
1515
#include <linux/syscalls.h>
1616
#include <linux/signal.h>
17-
#include <linux/tracehook.h>
17+
#include <linux/ptrace.h>
1818
#include <asm/traps.h>
1919
#include <asm/vm_fault.h>
2020
#include <asm/syscall.h>
@@ -348,7 +348,7 @@ void do_trap0(struct pt_regs *regs)
348348

349349
/* allow strace to catch syscall args */
350350
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE) &&
351-
tracehook_report_syscall_entry(regs)))
351+
ptrace_report_syscall_entry(regs)))
352352
return; /* return -ENOSYS somewhere? */
353353

354354
/* Interrupts should be re-enabled for syscall processing */
@@ -386,7 +386,7 @@ void do_trap0(struct pt_regs *regs)
386386

387387
/* allow strace to get the syscall return state */
388388
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE)))
389-
tracehook_report_syscall_exit(regs, 0);
389+
ptrace_report_syscall_exit(regs, 0);
390390

391391
break;
392392
case TRAP_DEBUG:

arch/ia64/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <linux/delay.h>
3333
#include <linux/kdebug.h>
3434
#include <linux/utsname.h>
35-
#include <linux/tracehook.h>
35+
#include <linux/resume_user_mode.h>
3636
#include <linux/rcupdate.h>
3737

3838
#include <asm/cpu.h>
@@ -179,7 +179,7 @@ do_notify_resume_user(sigset_t *unused, struct sigscratch *scr, long in_syscall)
179179

180180
if (test_thread_flag(TIF_NOTIFY_RESUME)) {
181181
local_irq_enable(); /* force interrupt enable */
182-
tracehook_notify_resume(&scr->pt);
182+
resume_user_mode_work(&scr->pt);
183183
}
184184

185185
/* copy user rbs to kernel rbs */

0 commit comments

Comments
 (0)