From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4HspI95zvWI5ZAkAWB0awg (envelope-from ) for ; Thu, 30 Jun 2022 05:58:54 -0400 Received: by simark.ca (Postfix, from userid 112) id 7E6C61E22B; Thu, 30 Jun 2022 05:58:54 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=noamfoCu; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id DBB461E227 for ; Thu, 30 Jun 2022 05:58:53 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 31BD43842AD0 for ; Thu, 30 Jun 2022 09:58:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31BD43842AD0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1656583133; bh=84+kiI1m1ke3EQOqbgI5clb0ogZMplQHeN+iw2DHWWM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=noamfoCufeNbhQnuoPtZxGdE7p8ez3B97oy1arsyDstW4VGvNpzqIn2WK09i9aJ6j ay+3zEBs1PS51dSTPzwzTISehy1Vm8P97+Fhbuf7Cwdh9NQon0vEcNONTJ11pzZn9+ x7712nndTKVVblpuInZkNlpv+5jhTrJgKsycOoQs= Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id CA1DC3841459 for ; Thu, 30 Jun 2022 09:58:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CA1DC3841459 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 00F3B1F9F3; Thu, 30 Jun 2022 09:58:33 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D893A13A5C; Thu, 30 Jun 2022 09:58:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fwbJM8hzvWJsbwAAMHmgww (envelope-from ); Thu, 30 Jun 2022 09:58:32 +0000 Date: Thu, 30 Jun 2022 11:58:31 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb] Block SIGTERM in worker threads Message-ID: <20220630095824.GA24025@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Cc: Tom Tromey , Pedro Alves Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, With gdb build with gcc-12 and -fsanitize=thread, and test-case gdb.base/gdb-sigterm.exp, I run into: ... WARNING: ThreadSanitizer: data race (pid=9722)^M Write of size 4 at 0x00000325bc68 by thread T1:^M #0 handle_sigterm(int) src/gdb/event-top.c:1211 (gdb+0x8ec01f)^M ... Previous read of size 4 at 0x00000325bc68 by main thread:^M [failed to restore the stack]^M ^M Location is global 'sync_quit_force_run' of size 4 at \ 0x00000325bc68 (gdb+0x325bc68)^M ... SUMMARY: ThreadSanitizer: data race gdb/event-top.c:1211 in \ handle_sigterm(int)^M ... and 3 more data races involving handle_sigterm and locations: - active_ext_lang - quit_flag - heap block of size 40 (XNEW (async_signal_handler) in create_async_signal_handler) This was reported in PR29297. The testcase executes a "kill -TERM $gdb_pid", which generates a process-directed signal. A process-directed signal can be delivered to any thread, and what we see here is the fallout of the signal being delivered to a worker thread rather than the main thread. Fix this by blocking SIGTERM in the worker threads. [ I have not been able to reproduce this after it occurred for the first time, so unfortunately I cannot confirm that the patch fixes the problem. ] Tested on x86_64-linux, with and without -fsanitize=thread. Any comments? Thanks, - Tom [gdb] Block SIGTERM in worker threads --- gdbsupport/block-signals.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gdbsupport/block-signals.h b/gdbsupport/block-signals.h index cf97208c750..4703690a4ec 100644 --- a/gdbsupport/block-signals.h +++ b/gdbsupport/block-signals.h @@ -42,6 +42,7 @@ class block_signals sigaddset (&mask, SIGCHLD); sigaddset (&mask, SIGALRM); sigaddset (&mask, SIGWINCH); + sigaddset (&mask, SIGTERM); gdb_sigmask (SIG_BLOCK, &mask, &m_old_mask); #endif }