diff options
author | Oleg Nesterov <oleg@redhat.com> | 2013-10-13 15:18:41 -0400 |
---|---|---|
committer | Oleg Nesterov <oleg@redhat.com> | 2013-10-29 13:02:53 -0400 |
commit | 248d3a7b2f100078c5f6878351177859380582e9 (patch) | |
tree | 68332322c85a53e47f3db1be0b2556d6c15b27b1 /kernel/events | |
parent | af0d95af79773f7637107cd3871aaabcb425f15a (diff) |
uprobes: Change uprobe_copy_process() to dup return_instances
uprobe_copy_process() assumes that the new child doesn't need
->utask, it should be allocated by demand.
But this is not true if the forking task has the pending ret-
probes, the child should report them as well and thus it needs
the copy of parent's ->return_instances chain. Otherwise the
child crashes when it returns from the probed function.
Alternatively we could cleanup the child's stack, but this needs
per-arch changes and this is not what we want. At least systemtap
expects a .return in the child too.
Note: this change alone doesn't fix the problem, see the next
change.
Reported-by: Martin Cermak <mcermak@redhat.com>
Reported-by: David Smith <dsmith@redhat.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Diffstat (limited to 'kernel/events')
-rw-r--r-- | kernel/events/uprobes.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 7d12a45842a7..1c6cda68a555 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c | |||
@@ -1366,12 +1366,55 @@ static struct uprobe_task *get_utask(void) | |||
1366 | return current->utask; | 1366 | return current->utask; |
1367 | } | 1367 | } |
1368 | 1368 | ||
1369 | static int dup_utask(struct task_struct *t, struct uprobe_task *o_utask) | ||
1370 | { | ||
1371 | struct uprobe_task *n_utask; | ||
1372 | struct return_instance **p, *o, *n; | ||
1373 | |||
1374 | n_utask = kzalloc(sizeof(struct uprobe_task), GFP_KERNEL); | ||
1375 | if (!n_utask) | ||
1376 | return -ENOMEM; | ||
1377 | t->utask = n_utask; | ||
1378 | |||
1379 | p = &n_utask->return_instances; | ||
1380 | for (o = o_utask->return_instances; o; o = o->next) { | ||
1381 | n = kmalloc(sizeof(struct return_instance), GFP_KERNEL); | ||
1382 | if (!n) | ||
1383 | return -ENOMEM; | ||
1384 | |||
1385 | *n = *o; | ||
1386 | atomic_inc(&n->uprobe->ref); | ||
1387 | n->next = NULL; | ||
1388 | |||
1389 | *p = n; | ||
1390 | p = &n->next; | ||
1391 | n_utask->depth++; | ||
1392 | } | ||
1393 | |||
1394 | return 0; | ||
1395 | } | ||
1396 | |||
1397 | static void uprobe_warn(struct task_struct *t, const char *msg) | ||
1398 | { | ||
1399 | pr_warn("uprobe: %s:%d failed to %s\n", | ||
1400 | current->comm, current->pid, msg); | ||
1401 | } | ||
1402 | |||
1369 | /* | 1403 | /* |
1370 | * Called in context of a new clone/fork from copy_process. | 1404 | * Called in context of a new clone/fork from copy_process. |
1371 | */ | 1405 | */ |
1372 | void uprobe_copy_process(struct task_struct *t) | 1406 | void uprobe_copy_process(struct task_struct *t) |
1373 | { | 1407 | { |
1408 | struct uprobe_task *utask = current->utask; | ||
1409 | struct mm_struct *mm = current->mm; | ||
1410 | |||
1374 | t->utask = NULL; | 1411 | t->utask = NULL; |
1412 | |||
1413 | if (mm == t->mm || !utask || !utask->return_instances) | ||
1414 | return; | ||
1415 | |||
1416 | if (dup_utask(t, utask)) | ||
1417 | return uprobe_warn(t, "dup ret instances"); | ||
1375 | } | 1418 | } |
1376 | 1419 | ||
1377 | /* | 1420 | /* |