)]}'
{
  "commit": "62fdaa52a3d00a875da771719b6dc537ca79fce1",
  "tree": "6218a11f3119eb814cfd0c81eee8e26eb505555b",
  "parents": [
    "ebc87351e5fc43022f687c01daca7e013837ae11"
  ],
  "author": {
    "name": "Qu Wenruo",
    "email": "wqu@suse.com",
    "time": "Thu Aug 22 10:14:15 2019 +0800"
  },
  "committer": {
    "name": "David Sterba",
    "email": "dsterba@suse.com",
    "time": "Mon Sep 09 14:59:14 2019 +0200"
  },
  "message": "btrfs: Detect unbalanced tree with empty leaf before crashing btree operations\n\n[BUG]\nWith crafted image, btrfs will panic at btree operations:\n\n  kernel BUG at fs/btrfs/ctree.c:3894!\n  invalid opcode: 0000 [#1] SMP PTI\n  CPU: 0 PID: 1138 Comm: btrfs-transacti Not tainted 5.0.0-rc8+ #9\n  RIP: 0010:__push_leaf_left+0x6b6/0x6e0\n  RSP: 0018:ffffc0bd4128b990 EFLAGS: 00010246\n  RAX: 0000000000000000 RBX: ffffa0a4ab8f0e38 RCX: 0000000000000000\n  RDX: ffffa0a280000000 RSI: 0000000000000000 RDI: ffffa0a4b3814000\n  RBP: ffffc0bd4128ba38 R08: 0000000000001000 R09: ffffc0bd4128b948\n  R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000240\n  R13: ffffa0a4b556fb60 R14: ffffa0a4ab8f0af0 R15: ffffa0a4ab8f0af0\n  FS: 0000000000000000(0000) GS:ffffa0a4b7a00000(0000) knlGS:0000000000000000\n  CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033\n  CR2: 00007f2461c80020 CR3: 000000022b32a006 CR4: 00000000000206f0\n  Call Trace:\n  ? _cond_resched+0x1a/0x50\n  push_leaf_left+0x179/0x190\n  btrfs_del_items+0x316/0x470\n  btrfs_del_csums+0x215/0x3a0\n  __btrfs_free_extent.isra.72+0x5a7/0xbe0\n  __btrfs_run_delayed_refs+0x539/0x1120\n  btrfs_run_delayed_refs+0xdb/0x1b0\n  btrfs_commit_transaction+0x52/0x950\n  ? start_transaction+0x94/0x450\n  transaction_kthread+0x163/0x190\n  kthread+0x105/0x140\n  ? btrfs_cleanup_transaction+0x560/0x560\n  ? kthread_destroy_worker+0x50/0x50\n  ret_from_fork+0x35/0x40\n  Modules linked in:\n  ---[ end trace c2425e6e89b5558f ]---\n\n[CAUSE]\nThe offending csum tree looks like this:\n\n  checksum tree key (CSUM_TREE ROOT_ITEM 0)\n  node 29741056 level 1 items 14 free 107 generation 19 owner CSUM_TREE\n\t  ...\n\t  key (EXTENT_CSUM EXTENT_CSUM 85975040) block 29630464 gen 17\n\t  key (EXTENT_CSUM EXTENT_CSUM 89911296) block 29642752 gen 17 \u003c\u003c\u003c\n\t  key (EXTENT_CSUM EXTENT_CSUM 92274688) block 29646848 gen 17\n\t  ...\n\n  leaf 29630464 items 6 free space 1 generation 17 owner CSUM_TREE\n\t  item 0 key (EXTENT_CSUM EXTENT_CSUM 85975040) itemoff 3987 itemsize 8\n\t\t  range start 85975040 end 85983232 length 8192\n\t  ...\n  leaf 29642752 items 0 free space 3995 generation 17 owner 0\n\t\t      ^ empty leaf            invalid owner ^\n\n  leaf 29646848 items 1 free space 602 generation 17 owner CSUM_TREE\n\t  item 0 key (EXTENT_CSUM EXTENT_CSUM 92274688) itemoff 627 itemsize 3368\n\t\t  range start 92274688 end 95723520 length 3448832\n\nSo we have a corrupted csum tree where one tree leaf is completely\nempty, causing unbalanced btree, thus leading to unexpected btree\nbalance error.\n\n[FIX]\nFor this particular case, we handle it in two directions to catch it:\n- Check if the tree block is empty through btrfs_verify_level_key()\n  So that invalid tree blocks won\u0027t be read out through\n  btrfs_search_slot() and its variants.\n\n- Check 0 tree owner in tree checker\n  NO tree is using 0 as its tree owner, detect it and reject at tree\n  block read time.\n\nBugzilla: https://bugzilla.kernel.org/show_bug.cgi?id\u003d202821\nReviewed-by: Nikolay Borisov \u003cnborisov@suse.com\u003e\nSigned-off-by: Qu Wenruo \u003cwqu@suse.com\u003e\nSigned-off-by: David Sterba \u003cdsterba@suse.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "99dfd889b9f73748c4a18f92e57cd9e302253308",
      "old_mode": 33188,
      "old_path": "fs/btrfs/disk-io.c",
      "new_id": "044981cf6df9149cd28d0f3c89cbe05b3be39e12",
      "new_mode": 33188,
      "new_path": "fs/btrfs/disk-io.c"
    },
    {
      "type": "modify",
      "old_id": "9645389a1187b6813f726a4dc79e8e8d4524b33d",
      "old_mode": 33188,
      "old_path": "fs/btrfs/tree-checker.c",
      "new_id": "43e488f5d06314645440318519e4021c7a4d1657",
      "new_mode": 33188,
      "new_path": "fs/btrfs/tree-checker.c"
    }
  ]
}
