]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Add locking around __libdw_dieabbrev for dwarf_hasattr
authorHeather McIntyre <hsm2@rice.edu>
Tue, 10 Oct 2023 13:42:55 +0000 (15:42 +0200)
committerAaron Merey <amerey@redhat.com>
Tue, 4 Jun 2024 19:08:56 +0000 (15:08 -0400)
* libdw/dwarf_hasattr.c (dwarf_hasattr): Use die_abbrev_lock
around __libdw_dieabbrev call.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/dwarf_hasattr.c

index eca08394b72ecfaaedcea7207d2c0f531bfdf871..92f8de685f1b811ba9bca54ff453adf99671c258 100644 (file)
 #include <dwarf.h>
 #include "libdwP.h"
 
+/* dwarf_hasattr() calls __libdw_dieabbrev() in libdwP.h.
+   __libdw_dieabbrev() reads/writes "die->abbrev".
+   Mutual exclusion is enforced around the call to __libdw_dieabbrev to prevent a race. */
+rwlock_define(static, die_abbrev_lock);
 
 int
 dwarf_hasattr (Dwarf_Die *die, unsigned int search_name)
@@ -41,8 +45,13 @@ dwarf_hasattr (Dwarf_Die *die, unsigned int search_name)
   if (die == NULL)
     return 0;
 
+  rwlock_wrlock(die_abbrev_lock);
+
   /* Find the abbreviation entry.  */
   Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, NULL);
+
+  rwlock_unlock(die_abbrev_lock);
+
   if (unlikely (abbrevp == DWARF_END_ABBREV))
     {
       __libdw_seterrno (DWARF_E_INVALID_DWARF);