)]}'
{
  "commit": "769d14abd35e0e153b5149c3e1e989a9d719e3ff",
  "tree": "d58db0a22405869f27ab248a334c8b74d61aa971",
  "parents": [
    "13c1bf43b6744fcf28387cdec6f5b5c24a32f20a"
  ],
  "author": {
    "name": "Xin Long",
    "email": "lucien.xin@gmail.com",
    "time": "Thu Dec 23 13:04:30 2021 -0500"
  },
  "committer": {
    "name": "Greg Kroah-Hartman",
    "email": "gregkh@linuxfoundation.org",
    "time": "Wed Jan 05 12:40:30 2022 +0100"
  },
  "message": "sctp: use call_rcu to free endpoint\n\n[ Upstream commit 5ec7d18d1813a5bead0b495045606c93873aecbb ]\n\nThis patch is to delay the endpoint free by calling call_rcu() to fix\nanother use-after-free issue in sctp_sock_dump():\n\n  BUG: KASAN: use-after-free in __lock_acquire+0x36d9/0x4c20\n  Call Trace:\n    __lock_acquire+0x36d9/0x4c20 kernel/locking/lockdep.c:3218\n    lock_acquire+0x1ed/0x520 kernel/locking/lockdep.c:3844\n    __raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]\n    _raw_spin_lock_bh+0x31/0x40 kernel/locking/spinlock.c:168\n    spin_lock_bh include/linux/spinlock.h:334 [inline]\n    __lock_sock+0x203/0x350 net/core/sock.c:2253\n    lock_sock_nested+0xfe/0x120 net/core/sock.c:2774\n    lock_sock include/net/sock.h:1492 [inline]\n    sctp_sock_dump+0x122/0xb20 net/sctp/diag.c:324\n    sctp_for_each_transport+0x2b5/0x370 net/sctp/socket.c:5091\n    sctp_diag_dump+0x3ac/0x660 net/sctp/diag.c:527\n    __inet_diag_dump+0xa8/0x140 net/ipv4/inet_diag.c:1049\n    inet_diag_dump+0x9b/0x110 net/ipv4/inet_diag.c:1065\n    netlink_dump+0x606/0x1080 net/netlink/af_netlink.c:2244\n    __netlink_dump_start+0x59a/0x7c0 net/netlink/af_netlink.c:2352\n    netlink_dump_start include/linux/netlink.h:216 [inline]\n    inet_diag_handler_cmd+0x2ce/0x3f0 net/ipv4/inet_diag.c:1170\n    __sock_diag_cmd net/core/sock_diag.c:232 [inline]\n    sock_diag_rcv_msg+0x31d/0x410 net/core/sock_diag.c:263\n    netlink_rcv_skb+0x172/0x440 net/netlink/af_netlink.c:2477\n    sock_diag_rcv+0x2a/0x40 net/core/sock_diag.c:274\n\nThis issue occurs when asoc is peeled off and the old sk is freed after\ngetting it by asoc-\u003ebase.sk and before calling lock_sock(sk).\n\nTo prevent the sk free, as a holder of the sk, ep should be alive when\ncalling lock_sock(). This patch uses call_rcu() and moves sock_put and\nep free into sctp_endpoint_destroy_rcu(), so that it\u0027s safe to try to\nhold the ep under rcu_read_lock in sctp_transport_traverse_process().\n\nIf sctp_endpoint_hold() returns true, it means this ep is still alive\nand we have held it and can continue to dump it; If it returns false,\nit means this ep is dead and can be freed after rcu_read_unlock, and\nwe should skip it.\n\nIn sctp_sock_dump(), after locking the sk, if this ep is different from\ntsp-\u003easoc-\u003eep, it means during this dumping, this asoc was peeled off\nbefore calling lock_sock(), and the sk should be skipped; If this ep is\nthe same with tsp-\u003easoc-\u003eep, it means no peeloff happens on this asoc,\nand due to lock_sock, no peeloff will happen either until release_sock.\n\nNote that delaying endpoint free won\u0027t delay the port release, as the\nport release happens in sctp_endpoint_destroy() before calling call_rcu().\nAlso, freeing endpoint by call_rcu() makes it safe to access the sk by\nasoc-\u003ebase.sk in sctp_assocs_seq_show() and sctp_rcv().\n\nThanks Jones to bring this issue up.\n\nv1-\u003ev2:\n  - improve the changelog.\n  - add kfree(ep) into sctp_endpoint_destroy_rcu(), as Jakub noticed.\n\nReported-by: syzbot+9276d76e83e3bcde6c99@syzkaller.appspotmail.com\nReported-by: Lee Jones \u003clee.jones@linaro.org\u003e\nFixes: d25adbeb0cdb (\"sctp: fix an use-after-free issue in sctp_sock_dump\")\nSigned-off-by: Xin Long \u003clucien.xin@gmail.com\u003e\nSigned-off-by: David S. Miller \u003cdavem@davemloft.net\u003e\nSigned-off-by: Sasha Levin \u003csashal@kernel.org\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "4fc747b778eb636b1ee477548d316da65143a525",
      "old_mode": 33188,
      "old_path": "include/net/sctp/sctp.h",
      "new_id": "33475d061823e8c572036dfc26ddb5810afeffca",
      "new_mode": 33188,
      "new_path": "include/net/sctp/sctp.h"
    },
    {
      "type": "modify",
      "old_id": "51d698f2656fc17ac6d376fc8ca1eee99b3d0b46",
      "old_mode": 33188,
      "old_path": "include/net/sctp/structs.h",
      "new_id": "be9ff0422c16265a6c30eeefecae8de887eaad22",
      "new_mode": 33188,
      "new_path": "include/net/sctp/structs.h"
    },
    {
      "type": "modify",
      "old_id": "493fc01e5d2b7c6c5a00918bd8bd4baf80dde563",
      "old_mode": 33188,
      "old_path": "net/sctp/diag.c",
      "new_id": "babadd6720a2be1f4d7c5c0840c677f588a01023",
      "new_mode": 33188,
      "new_path": "net/sctp/diag.c"
    },
    {
      "type": "modify",
      "old_id": "48c9c2c7602f78a099be61c93fe170ed3fc13574",
      "old_mode": 33188,
      "old_path": "net/sctp/endpointola.c",
      "new_id": "efffde7f2328e4e954bbcf8c1942fb650a590166",
      "new_mode": 33188,
      "new_path": "net/sctp/endpointola.c"
    },
    {
      "type": "modify",
      "old_id": "e872bc50bbe61f61073e601e14f7eb88495a15ae",
      "old_mode": 33188,
      "old_path": "net/sctp/socket.c",
      "new_id": "0a9e2c7d8e5f535485f1bc1d319237f0fc06fc1f",
      "new_mode": 33188,
      "new_path": "net/sctp/socket.c"
    }
  ]
}
