[PATCH] [bfd] Fix data race in bfd_check_format_matches
Tom de Vries
tdevries@suse.de
Mon Jan 26 12:44:43 GMT 2026
At the start of bfd_check_format_matches, we have this read of_bfd_section_id:
...
unsigned int initial_section_id = _bfd_section_id;
...
In order to access the variable, it is required to hold the global BFD lock.
The function already contains code acquiring the lock:
...
/* Locking is required here in order to manage _bfd_section_id. */
if (!bfd_lock ())
{
bfd_cache_set_uncloseable (abfd, old_in_format_matches, NULL);
free (matching_vector);
return false;
}
...
so fix this by moving the read after it.
Tested on x86_64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33826
---
bfd/format.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/bfd/format.c b/bfd/format.c
index f35230eb28b..2d35f59cd85 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -452,7 +452,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
const bfd_target *fail_targ;
int match_count, best_count, best_match;
int ar_match_index;
- unsigned int initial_section_id = _bfd_section_id;
+ unsigned int initial_section_id;
struct bfd_preserve preserve, preserve_match;
bfd_cleanup cleanup = NULL;
struct per_xvec_messages messages = { abfd, PER_XVEC_NO_TARGET, NULL, NULL };
@@ -492,6 +492,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
free (matching_vector);
return false;
}
+ initial_section_id = _bfd_section_id;
/* Presume the answer is yes. */
abfd->format = format;
base-commit: 449035c35f2169e0c690d83f28306275ab7f7463
--
2.51.0
More information about the Binutils
mailing list