dns: fix recursive locking 92/43292/2
authorBenoît Ganne <[email protected]>
Wed, 25 Jun 2025 14:39:54 +0000 (16:39 +0200)
committerFan Zhang <[email protected]>
Thu, 26 Jun 2025 19:32:12 +0000 (19:32 +0000)
All callers to delete_random_entry() are already holding the lock to
the DNS cache. Thanks to Rain for the report.

Type: fix

Change-Id: Id051427016f9b7444b812019ccc0f5085fd3e469
Signed-off-by: Benoît Ganne <[email protected]>
src/plugins/dns/dns.c

index de01474..b73d18a 100644 (file)
@@ -654,7 +654,8 @@ delete_random_entry (dns_main_t * dm)
     return VNET_API_ERROR_UNSPECIFIED;
 #endif
 
-  dns_cache_lock (dm, 3);
+  CLIB_SPINLOCK_ASSERT_LOCKED (&dm->cache_lock);
+
   limit = pool_elts (dm->entries);
   start_index = random_u32 (&dm->random_seed) % limit;
 
@@ -670,12 +671,10 @@ delete_random_entry (dns_main_t * dm)
              && ((ep->flags & DNS_CACHE_ENTRY_FLAG_STATIC) == 0))
            {
              rv = vnet_dns_delete_entry_by_index_nolock (dm, victim_index);
-             dns_cache_unlock (dm);
              return rv;
            }
        }
     }
-  dns_cache_unlock (dm);
 
   clib_warning ("Couldn't find an entry to delete?");
   return VNET_API_ERROR_UNSPECIFIED;