From 5aa4adc8e58aa795b8776301a32eb7fb23e3ee97 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Thu, 11 Aug 2022 15:06:34 -0700 Subject: [PATCH] Lock the address entry bucket when dumping ADB namehook When dumping an ADB address entry associated with a name, the name bucket lock was held, but the entry bucket lock was not; this could cause data races when other threads were updating address entry info. (These races are probably not operationally harmful, but they triggered TSAN error reports.) (cherry picked from commit f841f545b792ac91af48dff3ea96bd40dc426648) --- lib/dns/adb.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/dns/adb.c b/lib/dns/adb.c index f86e5125e5..3a51163ef3 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -3675,7 +3675,13 @@ print_namehook_list(FILE *f, const char *legend, dns_adb_t *adb, if (debug) { fprintf(f, ";\tHook(%s) %p\n", legend, nh); } +#ifdef __SANITIZE_THREAD__ + LOCK(&adb->entrylocks[nh->entry->lock_bucket]); +#endif dump_entry(f, adb, nh->entry, debug, now); +#ifdef __SANITIZE_THREAD__ + UNLOCK(&adb->entrylocks[nh->entry->lock_bucket]); +#endif } }