aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/ptrace.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 9acd07a6f5bb..4661c5bc07e5 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -231,6 +231,7 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
231} 231}
232 232
233static int ptrace_attach(struct task_struct *task, long request, 233static int ptrace_attach(struct task_struct *task, long request,
234 unsigned long addr,
234 unsigned long flags) 235 unsigned long flags)
235{ 236{
236 bool seize = (request == PTRACE_SEIZE); 237 bool seize = (request == PTRACE_SEIZE);
@@ -238,19 +239,29 @@ static int ptrace_attach(struct task_struct *task, long request,
238 239
239 /* 240 /*
240 * SEIZE will enable new ptrace behaviors which will be implemented 241 * SEIZE will enable new ptrace behaviors which will be implemented
241 * gradually. SEIZE_DEVEL is used to prevent applications 242 * gradually. SEIZE_DEVEL bit is used to prevent applications
242 * expecting full SEIZE behaviors trapping on kernel commits which 243 * expecting full SEIZE behaviors trapping on kernel commits which
243 * are still in the process of implementing them. 244 * are still in the process of implementing them.
244 * 245 *
245 * Only test programs for new ptrace behaviors being implemented 246 * Only test programs for new ptrace behaviors being implemented
246 * should set SEIZE_DEVEL. If unset, SEIZE will fail with -EIO. 247 * should set SEIZE_DEVEL. If unset, SEIZE will fail with -EIO.
247 * 248 *
248 * Once SEIZE behaviors are completely implemented, this flag and 249 * Once SEIZE behaviors are completely implemented, this flag
249 * the following test will be removed. 250 * will be removed.
250 */ 251 */
251 retval = -EIO; 252 retval = -EIO;
252 if (seize && !(flags & PTRACE_SEIZE_DEVEL)) 253 if (seize) {
253 goto out; 254 if (addr != 0)
255 goto out;
256 if (!(flags & PTRACE_SEIZE_DEVEL))
257 goto out;
258 flags &= ~(unsigned long)PTRACE_SEIZE_DEVEL;
259 if (flags & ~(unsigned long)PTRACE_O_MASK)
260 goto out;
261 flags = PT_PTRACED | PT_SEIZED | (flags << PT_OPT_FLAG_SHIFT);
262 } else {
263 flags = PT_PTRACED;
264 }
254 265
255 audit_ptrace(task); 266 audit_ptrace(task);
256 267
@@ -282,11 +293,11 @@ static int ptrace_attach(struct task_struct *task, long request,
282 if (task->ptrace) 293 if (task->ptrace)
283 goto unlock_tasklist; 294 goto unlock_tasklist;
284 295
285 task->ptrace = PT_PTRACED;
286 if (seize) 296 if (seize)
287 task->ptrace |= PT_SEIZED; 297 flags |= PT_SEIZED;
288 if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE)) 298 if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
289 task->ptrace |= PT_PTRACE_CAP; 299 flags |= PT_PTRACE_CAP;
300 task->ptrace = flags;
290 301
291 __ptrace_link(task, current); 302 __ptrace_link(task, current);
292 303
@@ -879,7 +890,7 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
879 } 890 }
880 891
881 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) { 892 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
882 ret = ptrace_attach(child, request, data); 893 ret = ptrace_attach(child, request, addr, data);
883 /* 894 /*
884 * Some architectures need to do book-keeping after 895 * Some architectures need to do book-keeping after
885 * a ptrace attach. 896 * a ptrace attach.
@@ -1022,7 +1033,7 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
1022 } 1033 }
1023 1034
1024 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) { 1035 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
1025 ret = ptrace_attach(child, request, data); 1036 ret = ptrace_attach(child, request, addr, data);
1026 /* 1037 /*
1027 * Some architectures need to do book-keeping after 1038 * Some architectures need to do book-keeping after
1028 * a ptrace attach. 1039 * a ptrace attach.