Commit 6bab93f8 authored by J. Bruce Fields's avatar J. Bruce Fields

svcrpc: take lock on turning entry NEGATIVE in cache_check

We attempt to turn a cache entry negative in place.  But that entry may
already have been filled in by some other task since we last checked
whether it was valid, so we could be modifying an already-valid entry.
If nothing else there's a likely leak in such a case when the entry is
eventually put() and contents are not freed because it has
CACHE_NEGATIVE set.

So, take the cache_lock just as sunrpc_cache_update() does.
Reviewed-by: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent da165dd6
...@@ -213,6 +213,23 @@ static inline int cache_is_valid(struct cache_detail *detail, struct cache_head ...@@ -213,6 +213,23 @@ static inline int cache_is_valid(struct cache_detail *detail, struct cache_head
} }
} }
static int try_to_negate_entry(struct cache_detail *detail, struct cache_head *h)
{
int rv;
write_lock(&detail->hash_lock);
rv = cache_is_valid(detail, h);
if (rv != -EAGAIN) {
write_unlock(&detail->hash_lock);
return rv;
}
set_bit(CACHE_NEGATIVE, &h->flags);
cache_fresh_locked(h, seconds_since_boot()+CACHE_NEW_EXPIRY);
write_unlock(&detail->hash_lock);
cache_fresh_unlocked(h, detail);
return -ENOENT;
}
/* /*
* This is the generic cache management routine for all * This is the generic cache management routine for all
* the authentication caches. * the authentication caches.
...@@ -251,14 +268,8 @@ int cache_check(struct cache_detail *detail, ...@@ -251,14 +268,8 @@ int cache_check(struct cache_detail *detail,
case -EINVAL: case -EINVAL:
clear_bit(CACHE_PENDING, &h->flags); clear_bit(CACHE_PENDING, &h->flags);
cache_revisit_request(h); cache_revisit_request(h);
if (rv == -EAGAIN) { rv = try_to_negate_entry(detail, h);
set_bit(CACHE_NEGATIVE, &h->flags);
cache_fresh_locked(h, seconds_since_boot()+CACHE_NEW_EXPIRY);
cache_fresh_unlocked(h, detail);
rv = -ENOENT;
}
break; break;
case -EAGAIN: case -EAGAIN:
clear_bit(CACHE_PENDING, &h->flags); clear_bit(CACHE_PENDING, &h->flags);
cache_revisit_request(h); cache_revisit_request(h);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment