public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug locale/28206] New: Data race in implementation of glibc functions newlocale() and/or freelocale()
@ 2021-08-07 13:48 kristian.spangsege at gmail dot com
  2021-08-07 13:52 ` [Bug locale/28206] " kristian.spangsege at gmail dot com
  2021-08-07 13:55 ` kristian.spangsege at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: kristian.spangsege at gmail dot com @ 2021-08-07 13:48 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28206

            Bug ID: 28206
           Summary: Data race in implementation of glibc functions
                    newlocale() and/or freelocale()
           Product: glibc
           Version: 2.31
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: locale
          Assignee: unassigned at sourceware dot org
          Reporter: kristian.spangsege at gmail dot com
  Target Milestone: ---

Created attachment 13597
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13597&action=edit
Demonstrate using C, then C++

According to the thread sanitizer, there is a data race in the implementation
of newlocale() and/or freelocale() in glibc 2.31 (Linux Mint 20).

As demonstrated by the attached C program (locale_1.c), when more than one
thread creates and destroys a locale using locale name `C.UTF-8`, the program
will sometimes crash.

Here is the first part of the output from the thread sanitizer:

==================
WARNING: ThreadSanitizer: data race (pid=165699)
  Write of size 8 at 0x7b0400000000 by thread T2:
    #0 free ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:711
(libtsan.so.0+0x37ab8)
    #1 <null> <null> (libc.so.6+0x34f0c)
    #2 thread <null> (a.out+0x12ea)

  Previous write of size 8 at 0x7b0400000000 by thread T1:
    [failed to restore the stack]

  Thread T2 (tid=165702, running) created by main thread at:
    #0 pthread_create
../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:969
(libtsan.so.0+0x605f8)
    #1 main <null> (a.out+0x1366)

  Thread T1 (tid=165701, running) created by main thread at:
    #0 pthread_create
../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:969
(libtsan.so.0+0x605f8)
    #1 main <null> (a.out+0x1366)

SUMMARY: ThreadSanitizer: data race (/lib/x86_64-linux-gnu/libc.so.6+0x34f0c) 
==================


Presumable, the C++ locale system is built on top of newlocale() and
freelocale(), and therefore, as expected, similar reports of data races occur
when using the C++ locale system. This is demonstrated by the attached C++
program (locale_2.cpp).

Compilation:
gcc -pthread -D_XOPEN_SOURCE=700 -fsanitize=thread locale_1.c
g++ -pthread -std=c++17 -fsanitize=thread locale_2.cpp

I also tried with GCC 7 and GCC 11 specifically, but that didn't change
anything.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug locale/28206] Data race in implementation of glibc functions newlocale() and/or freelocale()
  2021-08-07 13:48 [Bug locale/28206] New: Data race in implementation of glibc functions newlocale() and/or freelocale() kristian.spangsege at gmail dot com
@ 2021-08-07 13:52 ` kristian.spangsege at gmail dot com
  2021-08-07 13:55 ` kristian.spangsege at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: kristian.spangsege at gmail dot com @ 2021-08-07 13:52 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28206

--- Comment #1 from kristian.spangsege at gmail dot com <kristian.spangsege at gmail dot com> ---
(In reply to kristian.spangsege@gmail.com from comment #0)
> 
> As demonstrated by the attached C program (locale_1.c), when more than one
> thread creates and destroys a locale using locale name `C.UTF-8`, the
> program will sometimes crash.

Oops, I mean to say, "data races will be reported" rather than "the program
will sometimes crash". It doesn't seem to ever crash. Sorry about the
confusion.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug locale/28206] Data race in implementation of glibc functions newlocale() and/or freelocale()
  2021-08-07 13:48 [Bug locale/28206] New: Data race in implementation of glibc functions newlocale() and/or freelocale() kristian.spangsege at gmail dot com
  2021-08-07 13:52 ` [Bug locale/28206] " kristian.spangsege at gmail dot com
@ 2021-08-07 13:55 ` kristian.spangsege at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: kristian.spangsege at gmail dot com @ 2021-08-07 13:55 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28206

--- Comment #2 from kristian.spangsege at gmail dot com <kristian.spangsege at gmail dot com> ---
By the way, here is a godbolt link that demonstrates the problem:
https://godbolt.org/z/bxW8E7oTx

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-07 13:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-07 13:48 [Bug locale/28206] New: Data race in implementation of glibc functions newlocale() and/or freelocale() kristian.spangsege at gmail dot com
2021-08-07 13:52 ` [Bug locale/28206] " kristian.spangsege at gmail dot com
2021-08-07 13:55 ` kristian.spangsege at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).