Page MenuHomeFreeBSD

libc/locale: Fix races between localeconv(3) and setlocale(3)
ClosedPublic

Authored by markj on Sep 10 2021, 2:32 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 10:28 AM
Unknown Object (File)
Fri, Apr 19, 8:07 PM
Unknown Object (File)
Fri, Apr 19, 11:18 AM
Unknown Object (File)
Fri, Mar 29, 7:22 AM
Unknown Object (File)
Mar 8 2024, 12:04 AM
Unknown Object (File)
Feb 9 2024, 6:56 PM
Unknown Object (File)
Dec 23 2023, 3:01 AM
Unknown Object (File)
Dec 13 2023, 4:58 AM
Subscribers

Details

Summary

Each locale embeds a lazily initialized lconv which is populated by
localeconv(3) and localeconv_l(3). When setlocale(3) updates the global
locale, the lconv needs to be (lazily) reinitialized. To signal this,
we set flag variables in the locale structure. There are two problems:

- The flags are set before the locale is fully updated, so a concurrent
  localeconv() call can observe partially initialized locale data.
- No barriers ensure that localeconv() observes a fully initialized
  locale if a flag is set.

So, move the flag update appropriately, and use acq/rel barriers to
provide some synchronization.

Thanks to Henry Hu <henry.hu.sh@gmail.com> for providing a test case
demonstrating the race.

PR: 258360
MFC after: 2 weeks

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 41457
Build 38346: arc lint + arc unit

Event Timeline

markj requested review of this revision.Sep 10 2021, 2:32 PM
This revision was not accepted when it landed; it landed in state Needs Review.Sep 17 2021, 3:00 PM
This revision was automatically updated to reflect the committed changes.