freebsd-nq/lib/libc/locale
Mark Johnston 7eb138a9e5 libc/locale: Fix races between localeconv(3) and setlocale(3)
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.  Note that this is inadequate in the face
of multiple concurrent calls to setlocale(3), but this is not expected
to work regardless.

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

PR:		258360
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31899
2021-09-17 10:47:46 -04:00
..
ascii.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
big5.5 Use proper mdoc(7) macros for literal text and do not use Tn 2020-04-01 09:01:35 +00:00
big5.c
btowc.3
btowc.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
c16rtomb_iconv.c
c16rtomb.c Fix WITHOUT_ICONV build after r340276. 2018-11-14 09:06:15 +00:00
c32rtomb_iconv.c
c32rtomb.c Fix WITHOUT_ICONV build after r340276. 2018-11-14 09:06:15 +00:00
collate.c libc/locale: Use O_CLOEXEC when opening locale tables 2021-07-29 09:14:50 -04:00
collate.h Add collation version support to querylocale(3). 2020-11-08 02:50:34 +00:00
collcmp.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
ctype_l.3
ctype.3
ctype.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
cXXrtomb_iconv.h Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
DESIGN.xlocale
digittoint.3
duplocale.3
euc.5 In FreeBSD 11 localedef(1) has replaced the mklocale(1) and colldef(1) 2019-09-10 07:47:52 +00:00
euc.c SPDX: Fix some License ID tags for libc. 2017-12-27 21:21:03 +00:00
fix_grouping.c localeconv: correct grouping and mon_grouping per C/POSIX 2019-12-19 17:01:25 +00:00
freelocale.3
gb2312.5
gb2312.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
gb18030.5
gb18030.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
gbk.5
gbk.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
isalnum.3
isalpha.3
isascii.3
isblank.3
iscntrl.3
isctype.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
isdigit.3 Don't put multiple names on a single .Nm line. This fixes apropos(1) 2018-04-17 09:05:46 +00:00
isgraph.3
isideogram.3
islower.3
isphonogram.3
isprint.3
ispunct.3
isrune.3
isspace.3
isspecial.3
isupper.3
iswalnum_l.3
iswalnum.3
iswctype.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
isxdigit.3 Don't put multiple names on a single .Nm line. This fixes apropos(1) 2018-04-17 09:05:46 +00:00
ldpart.c Add hybrid C.UTF-8 locale being identical to default C locale except 2018-11-04 22:13:22 +00:00
ldpart.h libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
lmessages.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
lmessages.h libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
lmonetary.c libc/locale: Fix races between localeconv(3) and setlocale(3) 2021-09-17 10:47:46 -04:00
lmonetary.h libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
lnumeric.c libc/locale: Fix races between localeconv(3) and setlocale(3) 2021-09-17 10:47:46 -04:00
lnumeric.h libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
localeconv.3
localeconv.c libc/locale: Fix races between localeconv(3) and setlocale(3) 2021-09-17 10:47:46 -04:00
Makefile.inc
mblen.3
mblen.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
mblocal.h Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
mbrlen.3
mbrlen.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
mbrtoc16_iconv.c
mbrtoc16.c Fix WITHOUT_ICONV build after r340276. 2018-11-14 09:06:15 +00:00
mbrtoc32_iconv.c
mbrtoc32.c Fix WITHOUT_ICONV build after r340276. 2018-11-14 09:06:15 +00:00
mbrtocXX_iconv.h Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
mbrtowc.3
mbrtowc.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
mbsinit.3
mbsinit.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
mbsnrtowcs.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
mbsrtowcs.3 mbsrtowcs(3): Clarify the RETURN VALUES section 2020-08-07 16:56:43 +00:00
mbsrtowcs.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
mbstowcs.3
mbstowcs.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
mbtowc.3
mbtowc.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
mskanji.5
mskanji.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
multibyte.3 In FreeBSD 11 localedef(1) has replaced the mklocale(1) and colldef(1) 2019-09-10 07:47:52 +00:00
newlocale.3 newlocale(3): Fix a memory leak. 2020-10-02 18:35:55 +00:00
nextwctype.3
nextwctype.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
nl_langinfo.3 nl_langinfo(3): document recognized item names 2020-12-17 02:33:52 +00:00
nl_langinfo.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
nomacros.c
none.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
querylocale.3 Add collation version support to querylocale(3). 2020-11-08 02:50:34 +00:00
rpmatch.3
rpmatch.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
rune.c libc/locale: Use O_CLOEXEC when opening locale tables 2021-07-29 09:14:50 -04:00
runefile.h libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
runetype.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
setlocale.3 libc: Fix most issues reported by mandoc 2020-12-19 14:54:28 +00:00
setlocale.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
setlocale.h libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
setrunelocale.c Remove __NO_TLS. 2021-02-23 20:08:10 +02:00
Symbol.map
table.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
toascii.3
tolower.3
tolower.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
toupper.3
toupper.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
towlower.3
towupper.3
uselocale.3
utf8.5
utf8.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcrtomb.3
wcrtomb.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
wcsftime.3
wcsftime.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcsnrtombs.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
wcsrtombs.3
wcsrtombs.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
wcstod.3
wcstod.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcstof.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcstoimax.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcstol.3
wcstol.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcstold.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcstoll.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcstombs.3
wcstombs.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcstoul.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcstoull.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wcstoumax.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
wctob.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wctomb.3
wctomb.c Reset persistent mbstates when rune locale encoding changes. 2018-11-09 03:32:53 +00:00
wctrans.3
wctrans.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wctype.3
wctype.c libc: further adoption of SPDX licensing ID tags. 2017-11-25 17:12:48 +00:00
wcwidth.3
wcwidth.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
xlocale_private.h Remove __NO_TLS. 2021-02-23 20:08:10 +02:00
xlocale.3
xlocale.c Remove __NO_TLS. 2021-02-23 20:08:10 +02:00