History

ptrace: Remove arch_ptrace_attach

The last remaining implementation of arch_ptrace_attach is ia64's ptrace_attach_sync_user_rbs which was added at the end of 2007 in commit aa91a2e90044 ("[IA64] Synchronize RBS on PTRACE_ATTACH"). Reading the comments and examining the code ptrace_attach_sync_user_rbs has the sole purpose of saving registers to the stack when ptrace_attach changes TASK_STOPPED to TASK_TRACED. In all other cases arch_ptrace_stop takes care of the register saving. In commit d79fdd6d96f4 ("ptrace: Clean transitions between TASK_STOPPED and TRACED") modified ptrace_attach to wake up the thread and enter ptrace_stop normally even when the thread starts out stopped. This makes ptrace_attach_sync_user_rbs completely unnecessary. So just remove it. I read through the code to verify that ptrace_attach_sync_user_rbs is unnecessary. What I found is that the code is quite dead. Reading ptrace_attach_sync_user_rbs it is easy to see that the it does nothing unless __state == TASK_STOPPED. Calling arch_ptrace_attach (aka ptrace_attach_sync_user_rbs) after ptrace_traceme it is easy to see that because we are talking about the current process the value of __state is TASK_RUNNING. Which means ptrace_attach_sync_user_rbs does nothing. The only other call of arch_ptrace_attach (aka ptrace_attach_sync_user_rbs) is after ptrace_attach. If the task is running (and PTRACE_SEIZE is not specified), a SIGSTOP is sent which results in do_signal_stop setting JOBCTL_TRAP_STOP on the target task (as it is ptraced) and the target task stopping in ptrace_stop with __state == TASK_TRACED. If the task was already stopped then ptrace_attach sets JOBCTL_TRAPPING and JOBCTL_TRAP_STOP, wakes it out of __TASK_STOPPED, and waits until the JOBCTL_TRAPPING_BIT is clear. At which point the task stops in ptrace_stop. In both cases there are a couple of funning excpetions such as if the traced task receiveds a SIGCONT, or is set a fatal signal. However in all of those cases the tracee never stops in __state TASK_STOPPED. Which is a long way of saying that ptrace_attach_sync_user_rbs is guaranteed never to do anything.

Eric W. Biederman committed 4 years ago

Commit 16cc1bc1 parent 4a3d2713 files · +0 −79Browse files

Showing the changes to kernel (1 of 3 files). Show all

Unified · Split

kernel/ptrace.c+0−18
@@ -1285,10 +1285,6 @@ int ptrace_request(struct task_struct *child, long request, · 1284 unmodified lines
12851285 return ret;
12861286 }
12871287
1288−#ifndef arch_ptrace_attach
1289−#define arch_ptrace_attach(child) do { } while (0)
1290−#endif
1291−
12921288 SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
12931289 unsigned long, data)
12941290 {
@@ -1297,8 +1293,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr, · 2 unmodified lines
12971293
12981294 if (request == PTRACE_TRACEME) {
12991295 ret = ptrace_traceme();
1300− if (!ret)
1301− arch_ptrace_attach(current);
13021296 goto out;
13031297 }
13041298
@@ -1310,12 +1304,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr, · 5 unmodified lines
13101304
13111305 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
13121306 ret = ptrace_attach(child, request, addr, data);
1313− /*
1314− * Some architectures need to do book-keeping after
1315− * a ptrace attach.
1316− */
1317− if (!ret)
1318− arch_ptrace_attach(child);
13191307 goto out_put_task_struct;
13201308 }
13211309
@@ -1455,12 +1443,6 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid, · 133 unmodified lines
14551443
14561444 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
14571445 ret = ptrace_attach(child, request, addr, data);
1458− /*
1459− * Some architectures need to do book-keeping after
1460− * a ptrace attach.
1461− */
1462− if (!ret)
1463− arch_ptrace_attach(child);
14641446 goto out_put_task_struct;
14651447 }
14661448

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t