You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@apr.apache.org by bu...@apache.org on 2019/06/18 17:40:51 UTC

[Bug 63515] New: Data race in apr_thread_create, apr_os_thread_current may leak thread handle on Windows

https://bz.apache.org/bugzilla/show_bug.cgi?id=63515

            Bug ID: 63515
           Summary: Data race in apr_thread_create, apr_os_thread_current
                    may leak thread handle on Windows
           Product: APR
           Version: HEAD
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: APR
          Assignee: bugs@apr.apache.org
          Reporter: paul.groke@dynatrace.com
  Target Milestone: ---

The Windows code for `apr_thread_create` first creates the new thread and then
sets the `td` variable in the `apr_thread_t` struct.

If the newly created thread manages to start and execute the `dummy_worker`
function up to the `TlsSetValue` call before the `td` member is set, it will
load the initial zero value and store that in the TLS slot.

If `apr_os_thread_current` is called after that, `apr_os_thread_current` will
find a zero in the TLS slot and create a new handle by duplicating
`GetCurrentThread()`. Which will then leak.

This will also have the effect of `apr_os_thread_current` and
`apr_os_thread_get` returning different values for the same thread.

----

There are two "usual" fixes for this:
a) Create the new thread suspended, then copy the handle into the struct, then
resume the thread.
b) Use a retry-loop in the `dummy_worker` function that spins (+ ideally sleeps
a little) until the handle is non-zero.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


[Bug 63515] Data race in apr_thread_create, apr_os_thread_current may leak thread handle on Windows

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63515

paul.groke@dynatrace.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All
                 CC|                            |paul.groke@dynatrace.com

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


[Bug 63515] Data race in apr_thread_create, apr_os_thread_current may leak thread handle on Windows

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63515

ivan@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #1 from ivan@apache.org ---
Fixed in r1902277.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org