aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2013-12-02 15:26:19 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-12-20 10:45:08 -0500
commitfbaa929d862503b59110081efb57a40213193a6d (patch)
treefcef4b9bea3943e6ed5d0099d9c2e003c8a7dbd3 /fs/nfsd
parent13bb709cbe791f2d0218f29f1390a0d5e206edc3 (diff)
nfsd: when reusing an existing repcache entry, unhash it first
commit 781c2a5a5f75eacc04663aced0f0f1a648d4f308 upstream. The DRC code will attempt to reuse an existing, expired cache entry in preference to allocating a new one. It'll then search the cache, and if it gets a hit it'll then free the cache entry that it was going to reuse. The cache code doesn't unhash the entry that it's going to reuse however, so it's possible for it end up designating an entry for reuse and then subsequently freeing the same entry after it finds it. This leads it to a later use-after-free situation and usually some list corruption warnings or an oops. Fix this by simply unhashing the entry that we intend to reuse. That will mean that it's not findable via a search and should prevent this situation from occurring. Reported-by: Christoph Hellwig <hch@infradead.org> Reported-by: g. artim <gartim@gmail.com> Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/nfsd')
-rw-r--r--fs/nfsd/nfscache.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index e76244edd748..ec8d97ddc635 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -129,6 +129,13 @@ nfsd_reply_cache_alloc(void)
129} 129}
130 130
131static void 131static void
132nfsd_reply_cache_unhash(struct svc_cacherep *rp)
133{
134 hlist_del_init(&rp->c_hash);
135 list_del_init(&rp->c_lru);
136}
137
138static void
132nfsd_reply_cache_free_locked(struct svc_cacherep *rp) 139nfsd_reply_cache_free_locked(struct svc_cacherep *rp)
133{ 140{
134 if (rp->c_type == RC_REPLBUFF && rp->c_replvec.iov_base) { 141 if (rp->c_type == RC_REPLBUFF && rp->c_replvec.iov_base) {
@@ -403,7 +410,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp)
403 rp = list_first_entry(&lru_head, struct svc_cacherep, c_lru); 410 rp = list_first_entry(&lru_head, struct svc_cacherep, c_lru);
404 if (nfsd_cache_entry_expired(rp) || 411 if (nfsd_cache_entry_expired(rp) ||
405 num_drc_entries >= max_drc_entries) { 412 num_drc_entries >= max_drc_entries) {
406 lru_put_end(rp); 413 nfsd_reply_cache_unhash(rp);
407 prune_cache_entries(); 414 prune_cache_entries();
408 goto search_cache; 415 goto search_cache;
409 } 416 }