www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/05/24/09:19:43

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 54ODJgvb1731855
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 54ODJgvb1731855
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=WIWDrCMP
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E07C3858CDA
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1748092780;
bh=Adc0/Sd09YxGHsRRsMqRSr669f5tykE676aB1QAsrA8=;
h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post:
List-Help:List-Subscribe:From:Reply-To:Cc:From;
b=WIWDrCMPPYelxjKB9HQkFLACWkiebk82Q5YDtkSfX1VOltAHTyxyM2SWctXVKRLlZ
rFf3+hrjjnOH62VfwjyC2P7mx0HSMPTzYtWda7iFaZjDx5iXiZ5zOgCsLvcC5xaYJi
RIIWHtERKgVM+n7IwjJsdiAyF2fZfHFbGHGyurro=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CB353858D38
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4CB353858D38
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748092756; cv=none;
b=Ro35+NNtVDbLsJW7YDJVYrJEsyW9Lq38VmeW641KD/2SyCv+8HaIUXanFK/ssD47YiTWyMuicyhYunG00E/C5XmH4PS37uX9l6oQEM77NMPHvYZUIle+2zfEmhgs2XfwivuA+lfxb/QqbjYNh+IdyHDhx0kgnMdEJKIJ2dFdV6o=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1748092756; c=relaxed/simple;
bh=qg5pYTYClZsVzUE2rhyFa7EDwmWPJcBjRjAlY7K6C1M=;
h=From:Subject:To:Message-ID:Date:MIME-Version;
b=ttqQRZy2r3eznsH2aZ4paaBm51g75jrovz05AT5RXA7pDpggvsgyRZ2pmvXyW3XY/Xar5YV8ysW070IuJVQL3hmYbICve+E62DRXBBQWQcHPkABKQS7dE6YVwlMev2QEACmdYoQ+489+9zBaE45qYFLNZR9k9SPYTN7p6reRdKs=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CB353858D38
Subject: Segfault if /proc/PID/maps is opened in parallel threads
To: cygwin AT cygwin DOT com
Message-ID: <2f7ae08b-80c9-4497-f07c-5d527bbb7ec2@t-online.de>
Date: Sat, 24 May 2025 15:19:10 +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
X-TOI-EXPURGATEID: 150726::1748092748-517F858E-05556E8E/0/0 CLEAN NORMAL
X-TOI-MSGID: a27fb66e-e1fc-4700-84a0-eab52020f195
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-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>
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 54ODJgvb1731855

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.

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