stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] cifs: check pointer before freeing" failed to apply to 5.4-stable tree
@ 2021-01-17 14:16 gregkh
  2021-01-18 21:43 ` Tom Rix
  0 siblings, 1 reply; 2+ messages in thread
From: gregkh @ 2021-01-17 14:16 UTC (permalink / raw)
  To: trix, natechancellor, stable, stfrench; +Cc: stable


The patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 77b6ec01c29aade01701aa30bf1469acc7f2be76 Mon Sep 17 00:00:00 2001
From: Tom Rix <trix@redhat.com>
Date: Tue, 5 Jan 2021 12:21:26 -0800
Subject: [PATCH] cifs: check pointer before freeing

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>

diff --git a/fs/cifs/dfs_cache.c b/fs/cifs/dfs_cache.c
index 6ad6ba5f6ebe..0fdb0de7ff86 100644
--- a/fs/cifs/dfs_cache.c
+++ b/fs/cifs/dfs_cache.c
@@ -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);
 }
 
 /**


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: FAILED: patch "[PATCH] cifs: check pointer before freeing" failed to apply to 5.4-stable tree
  2021-01-17 14:16 FAILED: patch "[PATCH] cifs: check pointer before freeing" failed to apply to 5.4-stable tree gregkh
@ 2021-01-18 21:43 ` Tom Rix
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rix @ 2021-01-18 21:43 UTC (permalink / raw)
  To: gregkh, natechancellor, stable, stfrench

I made a mistake on the fixes line, it should have been

Fixes: 06d57378bcc9 ("cifs: Fix potential deadlock when updating vol in cifs_reconnect()")

-       if (!IS_ERR(vi))
-               free_vol(vi);
-       mutex_unlock(&vol_lock);
+       spin_unlock(&vol_list_lock);
+
+       kref_put(&vi->refcnt, vol_release);

This change is not needed for 5.4 unless the deadlock change is also needed.

Tom


On 1/17/21 6:16 AM, gregkh@linuxfoundation.org wrote:
> The patch below does not apply to the 5.4-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.
>
> thanks,
>
> greg k-h
>
> ------------------ original commit in Linus's tree ------------------
>
> From 77b6ec01c29aade01701aa30bf1469acc7f2be76 Mon Sep 17 00:00:00 2001
> From: Tom Rix <trix@redhat.com>
> Date: Tue, 5 Jan 2021 12:21:26 -0800
> Subject: [PATCH] cifs: check pointer before freeing
>
> 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>
>
> diff --git a/fs/cifs/dfs_cache.c b/fs/cifs/dfs_cache.c
> index 6ad6ba5f6ebe..0fdb0de7ff86 100644
> --- a/fs/cifs/dfs_cache.c
> +++ b/fs/cifs/dfs_cache.c
> @@ -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);
>  }
>  
>  /**
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-18 21:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-17 14:16 FAILED: patch "[PATCH] cifs: check pointer before freeing" failed to apply to 5.4-stable tree gregkh
2021-01-18 21:43 ` Tom Rix

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).