www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/05/25/10:47:23

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 54PElNN02383298
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 54PElNN02383298
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=C6Qh4uZo
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0BEE3858D20
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1748184440;
bh=Dudly4C90XQp0DhdauoZjIhjyVdYE4fOedCesl1I3mQ=;
h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=C6Qh4uZoOuKyV6SpgBgP8akW86Y8KrW31m4A3Z/VFoZBwLjDKyXNdiMAdKW1F0+Nw
gHknDIygvxQPC/ZgSAYqYoZpDI01JLzuNYQx81RYM9DAGylGoLZIA1gzP0cdY74XJG
whKUDaA2COuxVlJKtuPv0dBiGSoz3M0pf1ILREmc=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8BC893858D21
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8BC893858D21
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748184415; cv=none;
b=qRxL+vsAEpL0iCSyJrQ+kNjHyfWy3+3vFQa1Phkl4M4M0/C+D9ryYQktWS5yzCqpfCL6p4rzqEbtO1A12JX0MMhmiC9xZTo2qV1ABBNMq0v0fpVy5Pm7EeMTMhIXfQmxRZyOR2OjXEdqYUg7G4tNuZP8wdkwe/UcNuuSbkKMfBk=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1748184415; c=relaxed/simple;
bh=/cZxp4vPXR206KvN3zJWUa7XEygTbdvaEhUNBLtCZF8=;
h=From:Subject:To:Message-ID:Date:MIME-Version;
b=m6FoCxoUDGZTnAC2/Rm4AYcP6gqhnZtQO6soVSscnVHrAULTlmBHCpIze/ASe+gRHsB4mXfrYWORT5buSnPzL0uXEibIScKRf0Xir9C3StBrRaZ0slpoVHMMyjy62s4S9dKHhmHr2GUUu4KvEjUsAlE5iRE+gM6U+7c37EUgUw8=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8BC893858D21
Subject: Re: Segfault if /proc/PID/maps is opened in parallel threads
To: cygwin AT cygwin DOT com
References: <2f7ae08b-80c9-4497-f07c-5d527bbb7ec2 AT t-online DOT de>
Message-ID: <17bba06c-4bdd-01df-8477-235aff98b2cb@t-online.de>
Date: Sun, 25 May 2025 16:46:49 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101
SeaMonkey/2.53.20
MIME-Version: 1.0
In-Reply-To: <2f7ae08b-80c9-4497-f07c-5d527bbb7ec2@t-online.de>
X-TOI-EXPURGATEID: 150726::1748184409-D0FEF517-7DE1658C/0/0 CLEAN NORMAL
X-TOI-MSGID: 956120d4-683a-4449-9cc6-0bfa5f0b4134
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Christian Franke via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Christian Franke <Christian DOT Franke AT t-online DOT de>
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 54PElNN02383298

On Sat, 24 May 2025 15:19:10 +0200, Christian Franke wrote:
> If /proc/PID/maps is opened in parallel threads, the process PID may 
> segfault.
>
> Testcase:
>
> $ uname -r
> 3.7.0-0.98.gb39b510c1ce6.x86_64
>
> $ cat thrdopen.c
> #include <fcntl.h>
> #include <pthread.h>
> #include <stdio.h>
> #include <unistd.h>
>
> static const char * name;
>
> static void *worker(void *arg)
> {
>   for (int i = 0; i < 10000; i++) {
>     putchar((int)(intptr_t)arg); fflush(stdout);
>     int fd = open(name, O_RDONLY);
>     if (fd < 0) {
>       perror(name); break;
>     }
>     close(fd);
>   }
>   return NULL;
> }
>
> int main(int argc, char **argv)
> {
>   if (argc != 2)
>     return 1;
>   name = argv[1];
>   pthread_t t;
>   if (pthread_create(&t, NULL, worker, (void*)'-'))
>     return 2;
>   worker((void*)'+');
>   pthread_join(t, NULL);
>   return 0;
> }
>
> $ gcc -o thrdopen thrdopen.c
>
> $ cygstart mintty - # start 2nd terminal
>
> $ pstree -p
> ?(1)─┬─mintty(1146)───bash(1147)
>      └─mintty(992)───bash(993)───pstree(1152)
>
> $ ./thrdopen /proc/1147/maps # 2nd terminal closes
> +-+-+-+-+--+-++--+-+-+-+-+-++-+-+-+-+-+-+-+/proc/1147/maps: No such 
> file or directory
> -/proc/1147/maps: No such file or directory
>
> $ pstree -p
> ?(1)───mintty(992)───bash(993)───pstree(1154)
>
>
> If the bash is run in strace, output is like this:
> ...
>   155  536982 [main] bash 1179 select_stuff::wait: m 3, us 
> 18446744073709551615, wmfo_timeout -1
> [testcase run here]
> --- Process 14992 (pid: 1179) thread 15200 exited with status 0xc0000005
> --- Process 14992 thread 15024 exited with status 0xc0000005
> --- Process 14992 thread 9340 exited with status 0xc0000005
> --- Process 14992 thread 2504 exited with status 0xc0000005
> --- Process 14992 thread 2136 exited with status 0xc0000005
> --- Process 14992 thread 880 exited with status 0xc0000005
> --- Process 14992 thread 6484 exited with status 0xc0000005
> --- Process 14992 thread 16516 exited with status 0xc0000005
> --- Process 14992 exited with status 0xc0000005
>
> The last line may not appear and strace hangs then.
>
> Problem is not reproducible with any of the other /proc/PID/* files.
>

A closer look shows that the problem is unrelated to thread safety. The 
segfault also occurs when the following command is run simultaneously in 
two terminals:

$ while cat /proc/1234/maps > /dev/null; do printf .; done
.............cat: /proc/1234/maps: No such file or directory

-- 
Regards,
Christian


-- 
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019