DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 44JLUBd7978363
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=sdzAE7z7
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76A603858C52
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1716154209;
	bh=909VmAXCulejgJpwJw0KCVK2IIk5NrOhM0/ht7Mjyx8=;
	h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:
	 List-Help:List-Subscribe:From:Reply-To:From;
	b=sdzAE7z7/p4V3xDQ7YF4QIo4MbLCBpgi1OmX+ohGpT1BwHdCkhN8oKc79oMlp/4XO
	 5YSZmQCnF9pyO+rA2hrxjpDNNUu5kNbYhmTLifkAo91m0a4gooz4SYoC7Ncty5X2aq
	 RGWQJ8nb9KASjzoidXSYSM9qR7k+CJAAwj5jK1TI=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A4A33858D1E
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8A4A33858D1E
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716154156; cv=none;
 b=t3I0V0CG+3as6NVhkgN3tIwKbl55OU+Ryq6nycZG1VVIEvpDYTuhc2EDS7K97WvVw7n2Eyo1wX6TZUMDbJl0bz0hWa6muZn4QngQe0Mvuc0m1vNFTTH8TuaBY1caO5IaWpsFxJC8jA3exbPvH0dLbyllSyzCo8BwqZMULBSQ/Rs=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1716154156; c=relaxed/simple;
 bh=Vfw97byiaQabCInsVCjUPkWsln2YrgL8XYvwmvbYlJ0=;
 h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;
 b=lJruTjRZ8giaIY1HiF2ZaEwnS/P5lPnbwf4n3xVx5VOxIUJjS9Xi6IbxGJj//YJrSG9pkWLya4CK/fY0zRWjmLi5XvmfA+B9H9yOkorHVvbZCRYKdlrDjKGoWn49IZJxSsOUOK4GgVlUrFjGnNHLpenz23J1WUmVWObDmPDsVyE=
ARC-Authentication-Results: i=1; server2.sourceware.org
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1716154152; x=1716758952;
 h=user-agent:content-disposition:mime-version:message-id:subject:to
 :from:date:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=YyrqJhrk+1Oc+qUKFoOiu1ZUQISKdqK/yGgZkalzXYk=;
 b=gwFkyRar6ZBdGuz3wTGcakEG6+H2+lgsKT224y6Y5x2v/IeC13fGI4rQCTzVyiUreg
 kRM0sb11/BBsBhsGW74NJ3Oz7IxHbs5l93S4HA9LNKPGfGMzQCnUhbHii8sWL/sIUiwI
 KzPV7oHcv2g/PHo9uGXLlm3Ixp0v4QSbXCy6YHTzhnfu0+PCeB2caIYwlMQZqRE1aZvZ
 wmFM9DLPrdVOuo3dF/hQjkYjck2JkvrD9pD3LAVchFw0xS5xo4NKkoHC4KaxKrAgcrP+
 GraU0rZNwmizqXgcBwUDzlI8vZH9OPDPfZCuJnZdXmPc2BmicEIO+jLyU+HQES//L/03
 7hwg==
X-Gm-Message-State: AOJu0Yy23e1Efix16yg7VVRNa6lDwuTfheaPpF15/U5/gLUiINYcTDKD
 1GR9L6nU9PAXFUj4wdFQcD7SBfYPetN95AQrqQ6kM6W1y9dlSM8PyED2pg==
X-Google-Smtp-Source: AGHT+IF9Kg/T7u4NLB0PFCvP9zx3BM/dCxTcktYpEKa727Iy1vBF7AfTq4H+91fyE2U3VAZPpJjF3A==
X-Received: by 2002:a5d:53c8:0:b0:343:f3d9:a9d5 with SMTP id
 ffacd0b85a97d-3504a61d418mr18226376f8f.10.1716154151932; 
 Sun, 19 May 2024 14:29:11 -0700 (PDT)
Date: Sun, 19 May 2024 23:29:10 +0200
To: cygwin@cygwin.com
Subject: Segfault with detached threads and OpenSSL
Message-ID: <ZkpvJpruE486MnRp@hop.home>
MIME-Version: 1.0
Content-Disposition: inline
User-Agent: Mutt/2.2.13 (00d56288) (2024-03-09)
X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, DKIM_SIGNED,
 DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT,
 RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS,
 TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Rodrigo Arias via Cygwin <cygwin@cygwin.com>
Reply-To: Rodrigo Arias <rodarima@gmail.com>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

Hi,

(Sent to cygwin-developers by mistake).

When debugging a segfault in the Dillo browser[1] with the DNS threaded 
resolver and OpenSSL 3.0.13 I managed to isolate a reproducer.

[1]: https://github.com/dillo-browser/dillo/issues/172

It seems to be caused when both the SSL_library_init() is present and the 
PTHREAD_CREATE_DETACHED flag is set.

Steps to reproduce:

$ cat p.c
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>

#include <openssl/ssl.h>

#define N 4

static void *foo(void *data)
{
         printf("hello th %d\n", (int) data);
         return NULL;
}

int main()
{
         SSL_library_init();
         pthread_t th[N];
         pthread_attr_t attr;
         pthread_attr_init(&attr);
         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

         for (int i = 0; i < N; i++)
                 pthread_create(&th[i], &attr, foo, (void *) i);

         sleep(5);
}

$ gcc p.c -lssl -pthread -o p

$ gdb ./p
GNU gdb (GDB) (Cygwin 13.2-1) 13.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
     <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./p...
(gdb) r
Starting program: /home/PC/dillo/build-openssl/p
[New Thread 7332.0x1f2c]
[New Thread 7332.0x99c]
[New Thread 7332.0x27d4]
[New Thread 7332.0x35e0]
[New Thread 7332.0x21dc]
[New Thread 7332.0x3170]
[New Thread 7332.0x1ea4]
[New Thread 7332.0x3180]
hello th 0
hello th 1
hello th 2
[Thread 7332.0x3170 exited with code 0]
hello th 3

Thread 6 "p" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 7332.0x21dc]
0x0000000000000000 in ?? ()

Thanks,
Rodrigo.

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
