From: Nikolay Borisov Date: Thu, 13 Sep 2018 08:35:10 +0000 (+0300) Subject: btrfs: handle error of get_old_root X-Git-Tag: v5.4-rc1~2111^2~86 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=315bed43fea532650933e7bba316a7601d439edf;p=platform%2Fkernel%2Flinux-rpi.git btrfs: handle error of get_old_root 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 Reviewed-by: Lu Fengqi Reviewed-by: David Sterba Signed-off-by: David Sterba --- diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 6178fad..0a6c645 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -2960,6 +2960,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;