btrfs: handle error of get_old_root
authorNikolay Borisov <nborisov@suse.com>
Thu, 13 Sep 2018 08:35:10 +0000 (11:35 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 1 Dec 2019 08:13:22 +0000 (09:13 +0100)
commit67631651aa75387a578329cca3b62d1d083439a8
treec3032d796300d7b0219912087005b72ecc2fdc10
parent6e7515fb82f9080109509b85186d1d433b9d4cb4
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>
fs/btrfs/ctree.c