* [PATCH] cifs: check pointer before freeing
@ 2021-01-05 20:21 trix
2021-01-05 22:25 ` Nathan Chancellor
0 siblings, 1 reply; 3+ messages in thread
From: trix @ 2021-01-05 20:21 UTC (permalink / raw)
To: sfrench, natechancellor, ndesaulniers, aaptel, palcantara
Cc: linux-cifs, samba-technical, linux-kernel, clang-built-linux, Tom Rix
From: Tom Rix <trix@redhat.com>
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>
---
fs/cifs/dfs_cache.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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);
}
/**
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cifs: check pointer before freeing
2021-01-05 20:21 [PATCH] cifs: check pointer before freeing trix
@ 2021-01-05 22:25 ` Nathan Chancellor
2021-01-06 4:11 ` Steve French
0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2021-01-05 22:25 UTC (permalink / raw)
To: trix
Cc: sfrench, ndesaulniers, aaptel, palcantara, linux-cifs,
samba-technical, linux-kernel, clang-built-linux
On Tue, Jan 05, 2021 at 12:21:26PM -0800, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
>
> 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>
> ---
> fs/cifs/dfs_cache.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> 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);
> }
>
> /**
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cifs: check pointer before freeing
2021-01-05 22:25 ` Nathan Chancellor
@ 2021-01-06 4:11 ` Steve French
0 siblings, 0 replies; 3+ messages in thread
From: Steve French @ 2021-01-06 4:11 UTC (permalink / raw)
To: Nathan Chancellor
Cc: trix, Steve French, Nick Desaulniers, Aurélien Aptel,
Paulo Alcantara, CIFS, samba-technical, LKML, clang-built-linux
merged into cifs-2.6.git for-next and added cc:stable
On Tue, Jan 5, 2021 at 5:08 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> On Tue, Jan 05, 2021 at 12:21:26PM -0800, trix@redhat.com wrote:
> > From: Tom Rix <trix@redhat.com>
> >
> > 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>
>
> > ---
> > fs/cifs/dfs_cache.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > 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);
> > }
> >
> > /**
> > --
> > 2.27.0
> >
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-06 4:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 20:21 [PATCH] cifs: check pointer before freeing trix
2021-01-05 22:25 ` Nathan Chancellor
2021-01-06 4:11 ` Steve French
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).