cifs: fix double free error on share and prefix
authorColin Ian King <colin.king@canonical.com>
Fri, 31 Jul 2020 17:13:42 +0000 (18:13 +0100)
committerSteve French <stfrench@microsoft.com>
Sun, 2 Aug 2020 23:00:26 +0000 (18:00 -0500)
Currently if the call dfs_cache_get_tgt_share fails we cannot
fully guarantee that share and prefix are set to NULL and the
next iteration of the loop can end up potentially double freeing
these pointers. Since the semantics of dfs_cache_get_tgt_share
are ambiguous for failure cases with the setting of share and
prefix (currently now and the possibly the future), it seems
prudent to set the pointers to NULL when the objects are
free'd to avoid any double frees.

Addresses-Coverity: ("Double free")
Fixes: 96296c946a2a ("cifs: handle RESP_GET_DFS_REFERRAL.PathConsumed in reconnect")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
fs/cifs/connect.c

index 48b5133..aae9095 100644 (file)
@@ -5574,6 +5574,8 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru
 
                kfree(share);
                kfree(prefix);
+               share = NULL;
+               prefix = NULL;
 
                rc = dfs_cache_get_tgt_share(tcon->dfs_path + 1, it, &share, &prefix);
                if (rc) {