* [PATCH] netfs, fscache: Prevent Oops in fscache_put_cache()
@ 2024-01-10 18:54 Dan Carpenter
2024-01-10 19:01 ` David Howells
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2024-01-10 18:54 UTC (permalink / raw)
To: David Howells
Cc: Jeff Layton, linux-cachefs, linux-fsdevel, linux-kernel,
kernel-janitors
This function dereferences "cache" and then checks if it's
IS_ERR_OR_NULL(). Check first, then dereference.
Fixes: 9549332df4ed ("fscache: Implement cache registration")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
fs/netfs/fscache_cache.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/netfs/fscache_cache.c b/fs/netfs/fscache_cache.c
index d645f8b302a2..f0722cc2eae5 100644
--- a/fs/netfs/fscache_cache.c
+++ b/fs/netfs/fscache_cache.c
@@ -179,7 +179,6 @@ EXPORT_SYMBOL(fscache_acquire_cache);
void fscache_put_cache(struct fscache_cache *cache,
enum fscache_cache_trace where)
{
- unsigned int debug_id = cache->debug_id;
bool zero;
int ref;
@@ -187,7 +186,7 @@ void fscache_put_cache(struct fscache_cache *cache,
return;
zero = __refcount_dec_and_test(&cache->ref, &ref);
- trace_fscache_cache(debug_id, ref - 1, where);
+ trace_fscache_cache(cache->debug_id, ref - 1, where);
if (zero) {
down_write(&fscache_addremove_sem);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] netfs, fscache: Prevent Oops in fscache_put_cache()
2024-01-10 18:54 [PATCH] netfs, fscache: Prevent Oops in fscache_put_cache() Dan Carpenter
@ 2024-01-10 19:01 ` David Howells
2024-01-10 19:07 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: David Howells @ 2024-01-10 19:01 UTC (permalink / raw)
To: Dan Carpenter
Cc: dhowells, Jeff Layton, linux-cachefs, linux-fsdevel, linux-kernel,
kernel-janitors
Dan Carpenter <dan.carpenter@linaro.org> wrote:
> zero = __refcount_dec_and_test(&cache->ref, &ref);
> - trace_fscache_cache(debug_id, ref - 1, where);
> + trace_fscache_cache(cache->debug_id, ref - 1, where);
You can't do that if !zero. cache may be deallocated between the two lines.
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] netfs, fscache: Prevent Oops in fscache_put_cache()
2024-01-10 19:01 ` David Howells
@ 2024-01-10 19:07 ` Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-01-10 19:07 UTC (permalink / raw)
To: David Howells
Cc: Jeff Layton, linux-cachefs, linux-fsdevel, linux-kernel,
kernel-janitors
On Wed, Jan 10, 2024 at 07:01:40PM +0000, David Howells wrote:
> Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> > zero = __refcount_dec_and_test(&cache->ref, &ref);
> > - trace_fscache_cache(debug_id, ref - 1, where);
> > + trace_fscache_cache(cache->debug_id, ref - 1, where);
>
> You can't do that if !zero. cache may be deallocated between the two lines.
Ah... Right. I misread what was going on in the latter part of the
function. Sorry, I'll resend.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-10 19:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-10 18:54 [PATCH] netfs, fscache: Prevent Oops in fscache_put_cache() Dan Carpenter
2024-01-10 19:01 ` David Howells
2024-01-10 19:07 ` Dan Carpenter
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).