cifs: check pointer before freeing
Subsystems (2)
PATCH 1/1 cifs: check pointer before freeing
From: Tom Rix <[email protected]>
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().
--- fs/cifs/dfs_cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/cifs/dfs_cache.c +2 -1
@@ -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); }/**
Signature · 1 line
2.27.0
Quoted 13 lines · On Tue, Jan 05, 2021 at 12:21:26PM -0800, [email protected] wrote:
From: Tom Rix <[email protected]>
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 bymalloc()kfree(vi); ^~~~~~~~~In
dfs_cache_del_vol()the volume info pointer 'vi' being freed is the return of a call tofind_vol(). The large constant address isfind_vol()returning an error.
Quoted 5 lines
Add an error check to
dfs_cache_del_vol()similar to the one done indfs_cache_update_vol().Fixes 54be1f6c1c37 ("cifs: Add DFS cache routines")Signed-off-by Tom Rix <[email protected]>
Quoted 21 lines
--- fs/cifs/dfs_cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/cifs/dfs_cache.c +2
-1@@ -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); }/** Signature · 1 line
2.27.0
Steve French
Appliedmerged into cifs-2.6.git for-next and added cc:stable
Quoted 44 lines · Nathan Chancellor
Quoted 13 lines · On Tue, Jan 05, 2021 at 12:21:26PM -0800, [email protected] wrote:
From: Tom Rix <[email protected]>
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 bymalloc()kfree(vi); ^~~~~~~~~In
dfs_cache_del_vol()the volume info pointer 'vi' being freed is the return of a call tofind_vol(). The large constant address isfind_vol()returning an error.Quoted 5 lines
Add an error check to
dfs_cache_del_vol()similar to the one done indfs_cache_update_vol().Fixes 54be1f6c1c37 ("cifs: Add DFS cache routines")Signed-off-by Tom Rix <[email protected]>Reviewed-by Nathan Chancellor <[email protected]>Quoted 21 lines
--- fs/cifs/dfs_cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/cifs/dfs_cache.c +2
-2@@ -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); }/** -- 2.27.0
Signature · 3 lines
Thanks, Steve