All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nfsd: when reusing an existing repcache entry, unhash it first
@ 2013-12-02 20:26 Jeff Layton
  2013-12-03 10:25 ` Christoph Hellwig
  2013-12-03 15:50 ` J. Bruce Fields
  0 siblings, 2 replies; 16+ messages in thread
From: Jeff Layton @ 2013-12-02 20:26 UTC (permalink / raw)
  To: bfields; +Cc: hch, gartim, linux-nfs

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.

Cc: stable@vger.kernel.org # v3.10+
Reported-by: Christoph Hellwig <hch@infradead.org>
Reported-by: g. artim <gartim@gmail.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/nfsd/nfscache.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 9186c7c..b6af150 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -132,6 +132,13 @@ nfsd_reply_cache_alloc(void)
 }
 
 static void
+nfsd_reply_cache_unhash(struct svc_cacherep *rp)
+{
+	hlist_del_init(&rp->c_hash);
+	list_del_init(&rp->c_lru);
+}
+
+static void
 nfsd_reply_cache_free_locked(struct svc_cacherep *rp)
 {
 	if (rp->c_type == RC_REPLBUFF && rp->c_replvec.iov_base) {
@@ -417,7 +424,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp)
 		rp = list_first_entry(&lru_head, struct svc_cacherep, c_lru);
 		if (nfsd_cache_entry_expired(rp) ||
 		    num_drc_entries >= max_drc_entries) {
-			lru_put_end(rp);
+			nfsd_reply_cache_unhash(rp);
 			prune_cache_entries();
 			goto search_cache;
 		}
-- 
1.8.4.2


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

end of thread, other threads:[~2013-12-04 18:41 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-02 20:26 [PATCH] nfsd: when reusing an existing repcache entry, unhash it first Jeff Layton
2013-12-03 10:25 ` Christoph Hellwig
2013-12-03 18:21   ` Jeff Layton
2013-12-04  8:33     ` Christoph Hellwig
2013-12-04 12:54       ` Jeff Layton
2013-12-04 13:09         ` Christoph Hellwig
2013-12-04 13:31           ` Jeff Layton
2013-12-04 13:40             ` Christoph Hellwig
2013-12-04 13:45               ` Jeff Layton
2013-12-04 13:54                 ` Christoph Hellwig
2013-12-04 14:15                   ` Jeff Layton
2013-12-04 14:25           ` J. Bruce Fields
2013-12-04 17:06             ` Jeff Layton
2013-12-04 17:06               ` Christoph Hellwig
2013-12-04 18:43                 ` Jeff Layton
2013-12-03 15:50 ` J. Bruce Fields

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.