Patch "SUNRPC/cache: Fix unsafe traverse caused double-free in cache_purge" has been added to the 5.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

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

to the 5.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     sunrpc-cache-fix-unsafe-traverse-caused-double-free-.patch
and it can be found in the queue-5.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 631584af655ab2c95c18910feb6140c58700fc02
Author: Yihao Wu <wuyihao@xxxxxxxxxxxxxxxxx>
Date:   Mon Apr 6 01:57:22 2020 +0800

    SUNRPC/cache: Fix unsafe traverse caused double-free in cache_purge
    
    [ Upstream commit 43e33924c38e8faeb0c12035481cb150e602e39d ]
    
    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: NeilBrown <neilb@xxxxxxx>
    Signed-off-by: Yihao Wu <wuyihao@xxxxxxxxxxxxxxxxx>
    Reviewed-by: NeilBrown <neilb@xxxxxxx>
    [ cel: removed unused variable ]
    Signed-off-by: Chuck Lever <chuck.lever@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index bd843a81afa0b..d36cea4e270de 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -521,7 +521,6 @@ void cache_purge(struct cache_detail *detail)
 {
 	struct cache_head *ch = NULL;
 	struct hlist_head *head = NULL;
-	struct hlist_node *tmp = NULL;
 	int i = 0;
 
 	spin_lock(&detail->hash_lock);
@@ -533,7 +532,9 @@ void cache_purge(struct cache_detail *detail)
 	dprintk("RPC: %d entries in %s cache\n", detail->entries, detail->name);
 	for (i = 0; i < detail->hash_size; 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);
 			sunrpc_begin_cache_remove_entry(ch, detail);
 			spin_unlock(&detail->hash_lock);
 			sunrpc_end_cache_remove_entry(ch, detail);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux