summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2018-09-13 11:35:10 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-12-01 09:16:22 +0100
commitcc08097f261966ad18071383f01c16f0ce1d839c (patch)
treee5d2d7cc963e22d66c8e93d4f5de2432d823a18a /fs
parent1b49c453a5645f483cd6b7733919a36f9c492f98 (diff)
downloadlinux-stable-cc08097f261966ad18071383f01c16f0ce1d839c.tar.gz
linux-stable-cc08097f261966ad18071383f01c16f0ce1d839c.tar.bz2
linux-stable-cc08097f261966ad18071383f01c16f0ce1d839c.zip
btrfs: handle error of get_old_root
[ Upstream commit 315bed43fea532650933e7bba316a7601d439edf ] In btrfs_search_old_slot get_old_root is always used with the assumption it cannot fail. However, this is not true in rare circumstance it can fail and return null. This will lead to null point dereference when the header is read. Fix this by checking the return value and properly handling NULL by setting ret to -EIO and returning gracefully. Coverity-id: 1087503 Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 9fd383285f0e..fc764f350f05 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -3031,6 +3031,10 @@ int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
again:
b = get_old_root(root, time_seq);
+ if (!b) {
+ ret = -EIO;
+ goto done;
+ }
level = btrfs_header_level(b);
p->locks[level] = BTRFS_READ_LOCK;