[openssl/openssl] 4e43bc: crypto: thread: serialize concurrent joins

ckalina noreply at github.com
Fri Oct 21 10:47:51 UTC 2022


  Branch: refs/heads/master
  Home:   https://github.com/openssl/openssl
  Commit: 4e43bc06f7673597a99f61325543449e72070c8c
      https://github.com/openssl/openssl/commit/4e43bc06f7673597a99f61325543449e72070c8c
  Author: Čestmír Kalina <ckalina at redhat.com>
  Date:   2022-10-21 (Fri, 21 Oct 2022)

  Changed paths:
    M crypto/thread/arch.c
    M crypto/thread/arch/thread_none.c
    M crypto/thread/arch/thread_posix.c
    M crypto/thread/arch/thread_win.c
    M include/internal/thread_arch.h
    M test/threadstest.c

  Log Message:
  -----------
  crypto: thread: serialize concurrent joins

Multiple concurrent joins with a running thread suffer from a race
condition that allows concurrent join calls to perform concurrent arch
specific join calls, which is UB on POSIX, or to concurrently execute
join and terminate calls.

As soon as a thread T1 exists, one of the threads that joins with T1
is selected to perform the join, the remaining ones await completion.
Once completed, the remaining calls immediately return. If the join
failed, another thread is selected to attempt the join operation.

Forcefully terminating a thread that is in the process of joining
another thread is not supported.

Common code from thread_posix and thread_win was refactored to use
common wrapper that handles synchronization.

Signed-off-by: Čestmír Kalina <ckalina at redhat.com>

Reviewed-by: Hugo Landau <hlandau at openssl.org>
Reviewed-by: Tomas Mraz <tomas at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19433)


  Commit: 6ca4bd2e4c92531e74acba3e1ff08e6fbb664b20
      https://github.com/openssl/openssl/commit/6ca4bd2e4c92531e74acba3e1ff08e6fbb664b20
  Author: Čestmír Kalina <ckalina at redhat.com>
  Date:   2022-10-21 (Fri, 21 Oct 2022)

  Changed paths:
    M test/threadstest.c

  Log Message:
  -----------
  test: threads: replace test_thread_noreturn

While POSIX threads are cancellable and may be asynchronously cancelled,
their cancellation is not guaranteed by the POSIX standard.

test_thread_noreturn, which simulates a long-running possibly
unresponsive thread:

	THREAD #1		THREAD #2
	LOCK L1
	SPAWN #2
				LOCK L1

On MacOS, cancelling such thread only queues cancellation request, but
the following pthread_join hangs.

Replace this implementation by an unbounded sequence of sleeps instead.

Signed-off-by: Čestmír Kalina <ckalina at redhat.com>

Reviewed-by: Hugo Landau <hlandau at openssl.org>
Reviewed-by: Tomas Mraz <tomas at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19433)


Compare: https://github.com/openssl/openssl/compare/ec1d5970be59...6ca4bd2e4c92


More information about the openssl-commits mailing list