Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3236179imu; Sat, 24 Nov 2018 00:46:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ww9bYKdrbG4nz67PKd4CWOGqxOTM3uSmpWPg6ZbFppvN2eR3BgwRmbQ0k65dzjG3aiRdLm X-Received: by 2002:a63:78cd:: with SMTP id t196mr17255253pgc.62.1543049165874; Sat, 24 Nov 2018 00:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543049165; cv=none; d=google.com; s=arc-20160816; b=Vu1UB1JExlfaL9AsIdw71a5ywpm6egXq1qXlB+hhIV4g/31vFfX04+zlbbEEmNohOy leQN0bwgldulj1kmvgBjSgXgqtRq9QgHnLGyJpgd5RQHEglyn/hUOwTAAfBQFEY/1+eA /EN1c+6NxJEmQVGeuGM1SQ4ePBq/gEDB5xxRR8yGFxPF8B0YbQzFFU6eE4yVNNkTe5QK VdphC8+oZBOFSq0/Raoepz5wkPOsxmyn0uB0ltk5AHI3t7iT0Lqnqgu7AXyeva8bstSO Zff0Cq+IOeZjhjh4JsFzAnqNWtDiXmqr09N/KXahp1MeaPrIjFujWnjwdyfhKxhKYMPn JZxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=W3C9jppVpnmK0YZX4i7gGbENo5LXaJ+HUqqmIA0Yc4M=; b=ZC8DHEgx+oEQq1zlpWWc55ymaKHVbqo4N1bUZVjhRxW6ef8c1vQlBxjzZU/Iet9/Io Ysc3JwgY1LVDdrDWmO/rCCssvoWBML6jYCSns1vtHAiwEnojkGoqkDFiyMtwjY/N0oR4 cHvMQZ0Qmg9roHpjEcNe+5HIQqBhSJpXZpc6i5buNaOXq1eUzDamdqJqDf/ASw6ncawH +oQ3DCmg4jksd1g3iHvZQC4ht/pihA52vuRATO6NkwmhySLcw3xPA//7u6ZxCLoqHe4S 6MvtLh9G+WzwIYKaS0rczmyKuF9qWnbi5X5FC/IY5ooYZ/r4SFD/jOGymVUsol3V8vJP 7ssg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=fXXuDk4U; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1-v6si60038024plb.153.2018.11.24.00.45.51; Sat, 24 Nov 2018 00:46:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=fXXuDk4U; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2441014AbeKXEhj (ORCPT + 99 others); Fri, 23 Nov 2018 23:37:39 -0500 Received: from mail.efficios.com ([167.114.142.138]:44994 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730951AbeKXEhj (ORCPT ); Fri, 23 Nov 2018 23:37:39 -0500 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 5B70380DC6; Fri, 23 Nov 2018 12:52:22 -0500 (EST) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id hYq9d5zcCxay; Fri, 23 Nov 2018 12:52:21 -0500 (EST) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 8FB6D80DBF; Fri, 23 Nov 2018 12:52:21 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 8FB6D80DBF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1542995541; bh=W3C9jppVpnmK0YZX4i7gGbENo5LXaJ+HUqqmIA0Yc4M=; h=Date:From:To:Message-ID:MIME-Version; b=fXXuDk4UvA8Nw+IwMMUyaeEqpqIfe/tJR2gKZFKuktSYEMUxl/a+334j0kD1vHmS5 942AiS8p2nrd6PzpJ8ZMcZKIuUxvRniSIyIdzPFjRro9blAIXG+DPSpscF37O3Fj8y NSqBIRQzAF2nE+aAednF+bWoegIoYINzkQpnCNtMwnjQXV+hmow8mYGCqlYn0ZHFoS n3xO4gg8Za10IhmrliQYuP7Jp3521mh75r7VVwtEjFQ1Do3LjHaryX/XiuoCEzObcJ ggLQMN64UrVsMqcVHHhOICH5kiwfzMUZlk1iJ1nkQrtc3HWdzuAzVQF22W13EuAIC1 +FfS6zkMe6iLQ== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id gR0nWQ2QjrrA; Fri, 23 Nov 2018 12:52:21 -0500 (EST) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 6F5EB80DB7; Fri, 23 Nov 2018 12:52:21 -0500 (EST) Date: Fri, 23 Nov 2018 12:52:21 -0500 (EST) From: Mathieu Desnoyers To: Rich Felker Cc: Florian Weimer , carlos , Joseph Myers , Szabolcs Nagy , libc-alpha , Thomas Gleixner , Ben Maurer , Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Will Deacon , Dave Watson , Paul Turner , linux-kernel , linux-api Message-ID: <865273158.11687.1542995541389.JavaMail.zimbra@efficios.com> In-Reply-To: <20181123173019.GK23599@brightrain.aerifal.cx> References: <20181121183936.8176-1-mathieu.desnoyers@efficios.com> <1045257294.10291.1542905262086.JavaMail.zimbra@efficios.com> <87k1l5xd33.fsf@oldenburg.str.redhat.com> <20181122171010.GH23599@brightrain.aerifal.cx> <871s7cvt1l.fsf@oldenburg.str.redhat.com> <20181123142843.GJ23599@brightrain.aerifal.cx> <1150466925.11664.1542992720871.JavaMail.zimbra@efficios.com> <20181123173019.GK23599@brightrain.aerifal.cx> Subject: Re: [RFC PATCH v4 1/5] glibc: Perform rseq(2) registration at nptl init and thread creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.10_GA_3047 (ZimbraWebClient - FF52 (Linux)/8.8.10_GA_3041) Thread-Topic: glibc: Perform rseq(2) registration at nptl init and thread creation Thread-Index: +tP/nHsSVTVHcfxkwhXbP9/nYqpEyA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Nov 23, 2018, at 12:30 PM, Rich Felker dalias@libc.org wrote: > On Fri, Nov 23, 2018 at 12:05:20PM -0500, Mathieu Desnoyers wrote: >> ----- On Nov 23, 2018, at 9:28 AM, Rich Felker dalias@libc.org wrote: >> [...] >> > >> > Absolutely. As long as it's in libc, implicit destruction will happen. >> > Actually I think the glibc code shound unconditionally unregister the >> > rseq address at exit (after blocking signals, so no application code >> > can run) in case a third-party rseq library was linked and failed to >> > do so before thread exit (e.g. due to mismatched ref counts) rather >> > than respecting the reference count, since it knows it's the last >> > user. This would make potentially-buggy code safer. >> >> OK, let me go ahead with a few ideas/questions along that path. > ^^^^^^^^^^^^^^^ >> >> Let's say our stated goal is to let the "exit" system call from the >> glibc thread exit path perform rseq unregistration (without explicit >> unregistration beforehand). Let's look at what we need. > > This is not "along that path". The above-quoted text is not about > assuming it's safe to make SYS_exit without unregistering the rseq > object, but rather about glibc being able to perform the > rseq-unregister syscall without caring about reference counts, since > it knows no other code that might depend on rseq can run after it. When saying "along that path", what I mean is: if we go in that direction, then we should look into going all the way there, and rely on thread exit to implicitly unregister the TLS area. Do you see any reason for doing an explicit unregistration at thread exit rather than simply rely on the exit system call ? > >> First, we need the TLS area to be valid until the exit system call >> is invoked by the thread. If glibc defines __rseq_abi as a weak symbol, >> I'm not entirely sure we can guarantee the IE model if another library >> gets its own global-dynamic weak symbol elected at execution time. Would >> it be better to switch to a "strong" symbol for the glibc __rseq_abi >> rather than weak ? > > This doesn't help; still whichever comes first in link order would > override. Either way __rseq_abi would be in static TLS, though, > because any dynamically-loaded library is necessarily loaded after > libc, which is loaded at initial exec time. OK, AFAIU so you argue for leaving the __rseq_abi symbol "weak". Just making sure I correctly understand your position. Something can be technically correct based on the current implementation, but fragile with respect to future changes. We need to carefully distinguish between the two when exposing ABIs. > >> There has been presumptions about signals being blocked when the thread >> exits throughout this email thread. Out of curiosity, what code is >> responsible for disabling signals in this situation ? This question is still open. > Related to this, >> is it valid to access a IE model TLS variable from a signal handler at >> _any_ point where the signal handler nests over thread's execution ? >> This includes early start and just before invoking the exit system call. > > It should be valid to access *any* TLS object like this, but the > standards don't cover it well. Right now access to dynamic TLS from > signal handlers is unsafe in glibc, but static is safe. Which is a shame for the lttng-ust tracer, which needs global-dynamic TLS variables so it can be dlopen'd, but aims at allowing tracing from signal handlers. It looks like due to limitations of global-dynamic TLS, tracing from instrumented signal handlers with lttng-ust tracepoints could crash the process if the signal handler nests early at thread start or late before thread exit. One way out of this would be to ensure signals are blocked at thread start/exit, but I can't find the code responsible for doing this within glibc. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com