nfsd: when reusing an existing repcache entry, unhash it first
authorJeff Layton <jlayton@redhat.com>
Mon, 2 Dec 2013 20:26:19 +0000 (15:26 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 20 Dec 2013 15:48:54 +0000 (07:48 -0800)
commit99391a829fb2045a3f3d159a66a438fa4cd70bb2
tree304f29f2bcc90e58878ac23c38abeea46247516d
parent60820b2b4fb34a19075ce3562fe948ee9a5b366f
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>
fs/nfsd/nfscache.c