提交 d7600c44 编写于 作者: Y Yihao Wu 提交者: Yang Yingliang

SUNRPC/cache: Fix unsafe traverse caused double-free in cache_purge

mainline inclusion
from mainline-5.7-rc3
commit 43e33924
category: bugfix
bugzilla: 51810
CVE: NA

-------------------------------------------------

Deleting list entry within hlist_for_each_entry_safe is not safe unless
next pointer (tmp) is protected too. It's not, because once hash_lock
is released, cache_clean may delete the entry that tmp points to. Then
cache_purge can walk to a deleted entry and tries to double free it.

Fix this bug by holding only the deleted entry's reference.
Suggested-by: NNeilBrown <neilb@suse.de>
Signed-off-by: NYihao Wu <wuyihao@linux.alibaba.com>
Reviewed-by: NNeilBrown <neilb@suse.de>
[ cel: removed unused variable ]
Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
(cherry picked from commit 43e33924)
Signed-off-by: NYufen Wang <wangyufen@huawei.com>
Reviewed-by: NYue Haibing <yuehaibing@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 7c2443e4
...@@ -487,7 +487,6 @@ void cache_purge(struct cache_detail *detail) ...@@ -487,7 +487,6 @@ void cache_purge(struct cache_detail *detail)
{ {
struct cache_head *ch = NULL; struct cache_head *ch = NULL;
struct hlist_head *head = NULL; struct hlist_head *head = NULL;
struct hlist_node *tmp = NULL;
int i = 0; int i = 0;
write_lock(&detail->hash_lock); write_lock(&detail->hash_lock);
...@@ -499,7 +498,9 @@ void cache_purge(struct cache_detail *detail) ...@@ -499,7 +498,9 @@ void cache_purge(struct cache_detail *detail)
dprintk("RPC: %d entries in %s cache\n", detail->entries, detail->name); dprintk("RPC: %d entries in %s cache\n", detail->entries, detail->name);
for (i = 0; i < detail->hash_size; i++) { for (i = 0; i < detail->hash_size; i++) {
head = &detail->hash_table[i]; head = &detail->hash_table[i];
hlist_for_each_entry_safe(ch, tmp, head, cache_list) { while (!hlist_empty(head)) {
ch = hlist_entry(head->first, struct cache_head,
cache_list);
hlist_del_init(&ch->cache_list); hlist_del_init(&ch->cache_list);
detail->entries--; detail->entries--;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册