]> git.baikalelectronics.ru Git - kernel.git/commitdiff
cifs: check pointer before freeing
authorTom Rix <trix@redhat.com>
Tue, 5 Jan 2021 20:21:26 +0000 (12:21 -0800)
committerSteve French <stfrench@microsoft.com>
Wed, 13 Jan 2021 18:55:29 +0000 (12:55 -0600)
clang static analysis reports this problem

dfs_cache.c:591:2: warning: Argument to kfree() is a constant address
  (18446744073709551614), which is not memory allocated by malloc()
        kfree(vi);
        ^~~~~~~~~

In dfs_cache_del_vol() the volume info pointer 'vi' being freed
is the return of a call to find_vol().  The large constant address
is find_vol() returning an error.

Add an error check to dfs_cache_del_vol() similar to the one done
in dfs_cache_update_vol().

Fixes: 54be1f6c1c37 ("cifs: Add DFS cache routines")
Signed-off-by: Tom Rix <trix@redhat.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
CC: <stable@vger.kernel.org> # v5.0+
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/dfs_cache.c

index 6ad6ba5f6ebeef20bcf68f2d3ae27e432dcd4d04..0fdb0de7ff861b89e90ebc43b40921f79411eef2 100644 (file)
@@ -1260,7 +1260,8 @@ void dfs_cache_del_vol(const char *fullpath)
        vi = find_vol(fullpath);
        spin_unlock(&vol_list_lock);
 
-       kref_put(&vi->refcnt, vol_release);
+       if (!IS_ERR(vi))
+               kref_put(&vi->refcnt, vol_release);
 }
 
 /**