Skip to content

Conversation

@RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Aug 11, 2025

A data race existed between libddwaf.Load() and libddwaf.Usable() as both access shared global state that is not managed through atomic pointers.

This PR adds a sync.Mutex to resolve the race condition between Load and Usable; as the use of a sync.Once in Load ensures there is no race condition in other places (all uses of the gWafLib are guaranteed to be preceded by a call to Load, which means the reads "synchronize after" the write).

A data race existed between `libddwaf.Load()` and `libddwaf.Usable()` as
both access shared global state that is not managed through atomic pointers.

This PR puts the shared state behind atomics so that the data race no longer
exists. We copy the `wafLib` pointer in the `Builder`, `Handle` and
`Context` structures to avoid having to load the atomic all the time,
which would have broad performance impact.
@RomainMuller RomainMuller requested a review from a team as a code owner August 11, 2025 13:35
@RomainMuller RomainMuller enabled auto-merge (squash) August 11, 2025 14:14
@RomainMuller RomainMuller disabled auto-merge August 11, 2025 14:14
@RomainMuller RomainMuller enabled auto-merge (squash) August 11, 2025 14:14
@RomainMuller RomainMuller merged commit f3b3d0c into main Aug 11, 2025
113 checks passed
@RomainMuller RomainMuller deleted the romain.marcadier/fix-data-race branch August 11, 2025 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants