)]}'
{
  "commit": "de6f51e1f55b9f879717b1e2f86dc4d4f814c6e0",
  "tree": "370e6152860a08700e15624074de22dcbf73e023",
  "parents": [
    "932059b7ed7e968968376e0c555d4ce400b3e413"
  ],
  "author": {
    "name": "Al Viro",
    "email": "viro@zeniv.linux.org.uk",
    "time": "Sun May 20 16:46:23 2018 -0400"
  },
  "committer": {
    "name": "Al Viro",
    "email": "viro@zeniv.linux.org.uk",
    "time": "Sun May 20 16:46:23 2018 -0400"
  },
  "message": "aio: fix io_destroy(2) vs. lookup_ioctx() race\n\nkill_ioctx() used to have an explicit RCU delay between removing the\nreference from -\u003eioctx_table and percpu_ref_kill() dropping the refcount.\nAt some point that delay had been removed, on the theory that\npercpu_ref_kill() itself contained an RCU delay.  Unfortunately, that was\nthe wrong kind of RCU delay and it didn\u0027t care about rcu_read_lock() used\nby lookup_ioctx().  As the result, we could get ctx freed right under\nlookup_ioctx().  Tejun has fixed that in a6d7cff472e (\"fs/aio: Add explicit\nRCU grace period when freeing kioctx\"); however, that fix is not enough.\n\nSuppose io_destroy() from one thread races with e.g. io_setup() from another;\nCPU1 removes the reference from current-\u003emm-\u003eioctx_table[...] just as CPU2\nhas picked it (under rcu_read_lock()).  Then CPU1 proceeds to drop the\nrefcount, getting it to 0 and triggering a call of free_ioctx_users(),\nwhich proceeds to drop the secondary refcount and once that reaches zero\ncalls free_ioctx_reqs().  That does\n        INIT_RCU_WORK(\u0026ctx-\u003efree_rwork, free_ioctx);\n        queue_rcu_work(system_wq, \u0026ctx-\u003efree_rwork);\nand schedules freeing the whole thing after RCU delay.\n\nIn the meanwhile CPU2 has gotten around to percpu_ref_get(), bumping the\nrefcount from 0 to 1 and returned the reference to io_setup().\n\nTejun\u0027s fix (that queue_rcu_work() in there) guarantees that ctx won\u0027t get\nfreed until after percpu_ref_get().  Sure, we\u0027d increment the counter before\nctx can be freed.  Now we are out of rcu_read_lock() and there\u0027s nothing to\nstop freeing of the whole thing.  Unfortunately, CPU2 assumes that since it\nhas grabbed the reference, ctx is *NOT* going away until it gets around to\ndropping that reference.\n\nThe fix is obvious - use percpu_ref_tryget_live() and treat failure as miss.\nIt\u0027s not costlier than what we currently do in normal case, it\u0027s safe to\ncall since freeing *is* delayed and it closes the race window - either\nlookup_ioctx() comes before percpu_ref_kill() (in which case ctx-\u003eusers\nwon\u0027t reach 0 until the caller of lookup_ioctx() drops it) or lookup_ioctx()\nfails, ctx-\u003eusers is unaffected and caller of lookup_ioctx() doesn\u0027t see\nthe object in question at all.\n\nCc: stable@kernel.org\nFixes: a6d7cff472e \"fs/aio: Add explicit RCU grace period when freeing kioctx\"\nSigned-off-by: Al Viro \u003cviro@zeniv.linux.org.uk\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "88d7927ffbc61910c8c47948157fccfa8e6f10ed",
      "old_mode": 33188,
      "old_path": "fs/aio.c",
      "new_id": "8061d9787e547d305ea6953a092d61df933b332a",
      "new_mode": 33188,
      "new_path": "fs/aio.c"
    }
  ]
}
