Page MenuHomeFreeBSD

random: Fix synchronization of hc_source_mask
ClosedPublic

Authored by markj on Aug 28 2025, 9:47 PM.
Tags
None
Referenced Files
F131989369: D52230.id161180.diff
Sun, Oct 12, 6:18 PM
Unknown Object (File)
Sat, Oct 11, 10:39 PM
Unknown Object (File)
Sat, Oct 11, 10:39 PM
Unknown Object (File)
Sat, Oct 11, 10:39 PM
Unknown Object (File)
Sat, Oct 11, 10:39 PM
Unknown Object (File)
Sat, Oct 11, 1:19 PM
Unknown Object (File)
Thu, Oct 9, 9:19 PM
Unknown Object (File)
Fri, Oct 3, 6:20 PM
Subscribers

Details

Summary

This variable provides a mask of all registered entropy sources and is
updated when drivers attach and detach (or by sysctl). However, nothing
was synchronizing accesses to it. Use the harvest lock to provide
mutual exclusion for updates, and use atomic_load_int() to mark unlocked
reads.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Aug 28 2025, 9:47 PM
cem added a subscriber: cem.

Should we add a comment on the hc_source_mask definition about its locking/access protocol? LGTM.

sys/dev/random/random_harvestq.c
616

We could probably just do a single atomic load on line ~607.

680

Ditto.

This revision is now accepted and ready to land.Aug 28 2025, 11:00 PM
In D52230#1193071, @cem wrote:

Should we add a comment on the hc_source_mask definition about its locking/access protocol? LGTM.

Yeah, I should have done that. Added.

  • Add a comment above hc_source_mask.
  • Load the mask once before looping over its bits.
This revision now requires review to proceed.Aug 29 2025, 1:40 PM
This revision is now accepted and ready to land.Aug 29 2025, 4:37 PM
This revision was automatically updated to reflect the committed changes.