From 04520da77b08e788a830dba8f1b2dc7528581989 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 18 Aug 2021 17:33:14 -0400 Subject: [PATCH] btrfs-progs: check: do not infinite loop on corrupt keys with lowmem mode By enabling the lowmem checks properly I uncovered the case where test fsck/007 will infinite loop at the detection stage. This is because when checking the inode item we will just btrfs_next_item(), and because we ignore check tree block failures at read time we don't get an -EIO from btrfs_next_leaf. Generally what check usually does is validate the leaves/nodes as we hit them, but in this case we're not doing that. Fix this by checking the leaf if we move to the next one and if it fails bail. This allows us to pass the fsck/007 test with lowmem. Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- check/mode-lowmem.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index c800aadb..b88b2b19 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -2676,6 +2676,15 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path) while (1) { btrfs_item_key_to_cpu(path->nodes[0], &last_key, path->slots[0]); ret = btrfs_next_item(root, path); + + /* + * New leaf, we need to check it and see if it's valid, if not + * we need to bail otherwise we could end up stuck. + */ + if (path->slots[0] == 0 && + btrfs_check_leaf(gfs_info, NULL, path->nodes[0])) + ret = -EIO; + if (ret < 0) { /* out will fill 'err' rusing current statistics */ goto out;