NFSD: WARN when freeing an item still linked via nf_lru
[ Upstream commit 668ed92e651d3c25f9b6e8cb7ceca54d00daa96d ] Add a guardrail to prevent freeing memory that is still on a list. This includes either a dispose list or the LRU list. This is the sign of a bug, but this class of bugs can be detected so that they don't endanger system stability, especially while debugging. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
2310e47e13
commit
2e3445246e
1 changed files with 10 additions and 2 deletions
|
@ -213,6 +213,14 @@ nfsd_file_free(struct nfsd_file *nf)
|
||||||
fput(nf->nf_file);
|
fput(nf->nf_file);
|
||||||
flush = true;
|
flush = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If this item is still linked via nf_lru, that's a bug.
|
||||||
|
* WARN and leak it to preserve system stability.
|
||||||
|
*/
|
||||||
|
if (WARN_ON_ONCE(!list_empty(&nf->nf_lru)))
|
||||||
|
return flush;
|
||||||
|
|
||||||
call_rcu(&nf->nf_rcu, nfsd_file_slab_free);
|
call_rcu(&nf->nf_rcu, nfsd_file_slab_free);
|
||||||
return flush;
|
return flush;
|
||||||
}
|
}
|
||||||
|
@ -342,7 +350,7 @@ nfsd_file_dispose_list(struct list_head *dispose)
|
||||||
|
|
||||||
while(!list_empty(dispose)) {
|
while(!list_empty(dispose)) {
|
||||||
nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
|
nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
|
||||||
list_del(&nf->nf_lru);
|
list_del_init(&nf->nf_lru);
|
||||||
nfsd_file_flush(nf);
|
nfsd_file_flush(nf);
|
||||||
nfsd_file_put_noref(nf);
|
nfsd_file_put_noref(nf);
|
||||||
}
|
}
|
||||||
|
@ -356,7 +364,7 @@ nfsd_file_dispose_list_sync(struct list_head *dispose)
|
||||||
|
|
||||||
while(!list_empty(dispose)) {
|
while(!list_empty(dispose)) {
|
||||||
nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
|
nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
|
||||||
list_del(&nf->nf_lru);
|
list_del_init(&nf->nf_lru);
|
||||||
nfsd_file_flush(nf);
|
nfsd_file_flush(nf);
|
||||||
if (!refcount_dec_and_test(&nf->nf_ref))
|
if (!refcount_dec_and_test(&nf->nf_ref))
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue