)]}'
{
  "commit": "d79fdd6d96f46fabb779d86332e3677c6f5c2a4f",
  "tree": "2797e34888c687b47997b7c7ea3150468bcbb737",
  "parents": [
    "5224fa3660ad3881d2f2ad726d22614117963f10"
  ],
  "author": {
    "name": "Tejun Heo",
    "email": "tj@kernel.org",
    "time": "Wed Mar 23 10:37:00 2011 +0100"
  },
  "committer": {
    "name": "Tejun Heo",
    "email": "tj@kernel.org",
    "time": "Wed Mar 23 10:37:00 2011 +0100"
  },
  "message": "ptrace: Clean transitions between TASK_STOPPED and TRACED\n\nCurrently, if the task is STOPPED on ptrace attach, it\u0027s left alone\nand the state is silently changed to TRACED on the next ptrace call.\nThe behavior breaks the assumption that arch_ptrace_stop() is called\nbefore any task is poked by ptrace and is ugly in that a task\nmanipulates the state of another task directly.\n\nWith GROUP_STOP_PENDING, the transitions between TASK_STOPPED and\nTRACED can be made clean.  The tracer can use the flag to tell the\ntracee to retry stop on attach and detach.  On retry, the tracee will\nenter the desired state in the correct way.  The lower 16bits of\ntask-\u003egroup_stop is used to remember the signal number which caused\nthe last group stop.  This is used while retrying for ptrace attach as\nthe original group_exit_code could have been consumed with wait(2) by\nthen.\n\nAs the real parent may wait(2) and consume the group_exit_code\nanytime, the group_exit_code needs to be saved separately so that it\ncan be used when switching from regular sleep to ptrace_stop().  This\nis recorded in the lower 16bits of task-\u003egroup_stop.\n\nIf a task is already stopped and there\u0027s no intervening SIGCONT, a\nptrace request immediately following a successful PTRACE_ATTACH should\nalways succeed even if the tracer doesn\u0027t wait(2) for attach\ncompletion; however, with this change, the tracee might still be\nTASK_RUNNING trying to enter TASK_TRACED which would cause the\nfollowing request to fail with -ESRCH.\n\nThis intermediate state is hidden from the ptracer by setting\nGROUP_STOP_TRAPPING on attach and making ptrace_check_attach() wait\nfor it to clear on its signal-\u003ewait_chldexit.  Completing the\ntransition or getting killed clears TRAPPING and wakes up the tracer.\n\nNote that the STOPPED -\u003e RUNNING -\u003e TRACED transition is still visible\nto other threads which are in the same group as the ptracer and the\nreverse transition is visible to all.  Please read the comments for\ndetails.\n\nOleg:\n\n* Spotted a race condition where a task may retry group stop without\n  proper bookkeeping.  Fixed by redoing bookkeeping on retry.\n\n* Spotted that the transition is visible to userland in several\n  different ways.  Most are fixed with GROUP_STOP_TRAPPING.  Unhandled\n  corner case is documented.\n\n* Pointed out not setting GROUP_STOP_SIGMASK on an already stopped\n  task would result in more consistent behavior.\n\n* Pointed out that calling ptrace_stop() from do_signal_stop() in\n  TASK_STOPPED can race with group stop start logic and then confuse\n  the TRAPPING wait in ptrace_check_attach().  ptrace_stop() is now\n  called with TASK_RUNNING.\n\n* Suggested using signal-\u003ewait_chldexit instead of bit wait.\n\n* Spotted a race condition between TRACED transition and clearing of\n  TRAPPING.\n\nSigned-off-by: Tejun Heo \u003ctj@kernel.org\u003e\nAcked-by: Oleg Nesterov \u003coleg@redhat.com\u003e\nCc: Roland McGrath \u003croland@redhat.com\u003e\nCc: Jan Kratochvil \u003cjan.kratochvil@redhat.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "b2a17dfbdbad5da0af6866045cfefd6b029d8294",
      "old_mode": 33188,
      "old_path": "include/linux/sched.h",
      "new_id": "456d80ed3b784e0638b6b9265b14103f72b607cc",
      "new_mode": 33188,
      "new_path": "include/linux/sched.h"
    },
    {
      "type": "modify",
      "old_id": "6acf8954017ce92f3f8b23c5b34888c0eb0088bd",
      "old_mode": 33188,
      "old_path": "kernel/ptrace.c",
      "new_id": "745fc2dd00c591e24f7cae10afe2017e77d48a76",
      "new_mode": 33188,
      "new_path": "kernel/ptrace.c"
    },
    {
      "type": "modify",
      "old_id": "418776c41d24a0d061b8545bd7b54896edba1e1f",
      "old_mode": 33188,
      "old_path": "kernel/signal.c",
      "new_id": "1e199919ae0931856bec4db5f4ecd7dc90743b7f",
      "new_mode": 33188,
      "new_path": "kernel/signal.c"
    }
  ]
}
