From nobody Mon Jul 29 23:58:59 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WXwLW6G6Vz5SDtD; Mon, 29 Jul 2024 23:58:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WXwLW47z0z4DCp; Mon, 29 Jul 2024 23:58:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722297539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qfAQyFna3iZiBLvFRHOdb7qDanz6FqEJtFkdVpipKuA=; b=rAWU6m12DuJxlfEyD3lCYDJyQynRx1M547P6M+zfboTWcLChXX1q1YUEgugA4qs7/F47Kl l6F2JHAfKRqWK+3xGERCf1ZACPl3zEnax2w533RX+G4SAKtmUE6Wjv5JkkDsUBmrMPJqXR wHAKWfK0AhIh6jd9GObKZPLG7hF9qSTaeKUAu3h/W1TBSUBpiVXGsTuauE8IqgR2gbsgrp 3Pc8nZ2JEp014YLIDzkLyiqBs+agkMDaaEv1uegPYi65qro84Tom3VfXYQ1D06uTrwd+Ce Zjj8bfjgPFxPGGje+9vHsJAYgYmw83ok+7qg/rGJ/Z/b2a2OjnabbVXCbRHrfQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722297539; a=rsa-sha256; cv=none; b=wBPsIvK3KpyIwMo27/z50JU6jzo1/pyIkpaG4Gxino42IRrlDoUhWmd3cZW6NGOqW8aDMZ 7/uYPHZKQNP3Mex6sZ0kWWKVHIM9BvvB2tbWFg7wwOcOKzcOOsjQWVRr9F5skeiyv4uPMR gZF5YUKeObemBIaxuPcHgau1XCjd3Wu/SRfZwqgY0WWUsSRo57vmowjPMYKQ6uGX07Wckh axXIcajz7PUo0znEmCSqsFgs0DViNyHkYh3nF50uMNc59+9YPwDE1jN8yfq2EojZKtvbxL 08iYXPxrrY+gTf+uzvxpsyHDEAoaXrptAlBVd8+UeTaLWpCAk181iaDe+Z3mjg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722297539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qfAQyFna3iZiBLvFRHOdb7qDanz6FqEJtFkdVpipKuA=; b=RTsV8NAlnVubaVXOn1z4ghnrHY/T4CB8gskFPlNF1DKDnezpQW09LYPUpOkxcQk/077gTn 2TdikNeK/l51ith3VL+WZKRJ7qgocQp+tX0V/NeJxeRkQ/n6LrgA8+nzZGVFhLdQDDeHOy +5DoQzqiIEKiBbkj2RoBKKNT4mXYJsRLcIj87O9t49bXM928GXhbJuHRgmiNOfNvMAw3tX W0VDrgan6Jm6GdUGOq/VXW0MB5rP7ag9E2YJbfaLjYyObOcRHXWQWnRx7uxxHMzB1si4j1 AFczZIQ82gsOmu03wu6cfTKYQ7AQAxJDQPxzRl7XariZBHBHK4YJ31FIrQyQdg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WXwLW3YYLzvgK; Mon, 29 Jul 2024 23:58:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46TNwxj4051711; Mon, 29 Jul 2024 23:58:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46TNwx6r051708; Mon, 29 Jul 2024 23:58:59 GMT (envelope-from git) Date: Mon, 29 Jul 2024 23:58:59 GMT Message-Id: <202407292358.46TNwx6r051708@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 860c4d94ac46 - main - rtld: add LD_NO_DL_ITERATE_PHDR_AFTER_FORK env var List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 860c4d94ac46cee35a678cf3c9cdbd437dfed75e Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=860c4d94ac46cee35a678cf3c9cdbd437dfed75e commit 860c4d94ac46cee35a678cf3c9cdbd437dfed75e Author: Konstantin Belousov AuthorDate: 2024-07-17 04:05:33 +0000 Commit: Konstantin Belousov CommitDate: 2024-07-29 23:57:33 +0000 rtld: add LD_NO_DL_ITERATE_PHDR_AFTER_FORK env var which makes threaded fork ignore the phdr rtld lock, in particular allowing the dl_iterate_phdr() to block in callback. The cost is that the image started in this mode cannot use dl_iterate_phdr() after fork. PR: 280318 Sponsored by: The FreeBSD Foundation MFC after: 1 week --- libexec/rtld-elf/rtld.1 | 10 +++++++++- libexec/rtld-elf/rtld.c | 1 + libexec/rtld-elf/rtld.h | 1 + libexec/rtld-elf/rtld_lock.c | 7 +++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libexec/rtld-elf/rtld.1 b/libexec/rtld-elf/rtld.1 index 992138b1ffc0..31e046a5cdc4 100644 --- a/libexec/rtld-elf/rtld.1 +++ b/libexec/rtld-elf/rtld.1 @@ -26,7 +26,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 28, 2024 +.Dd July 24, 2025 .Dt RTLD 1 .Os .Sh NAME @@ -329,6 +329,14 @@ The static TLS extra space is used when loading objects compiled for initial-exec TLS code model with .Xr dlopen 3 . The minimum value that can be specified is \'128\'. +.It Ev LD_NO_DL_ITERATE_PHDR_AFTER_FORK +Allow +.Xr dl_iterate_phdr 3 +to block in callback, without causing deadlock with the +.Xr fork 2 . +The drawback is that the image started in this mode cannot use +.Xr dl_iterate_phdr 3 +after fork. .El .Sh DIRECT EXECUTION MODE .Nm diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index f49c429d0061..1f0c59722ac6 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -375,6 +375,7 @@ static struct ld_env_var_desc ld_env_vars[] = { LD_ENV_DESC(TRACE_LOADED_OBJECTS_ALL, false), LD_ENV_DESC(SHOW_AUXV, false), LD_ENV_DESC(STATIC_TLS_EXTRA, false), + LD_ENV_DESC(NO_DL_ITERATE_PHDR_AFTER_FORK, false), }; const char * diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index fcd42f3841b3..656e980c6261 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -376,6 +376,7 @@ enum { LD_TRACE_LOADED_OBJECTS_ALL, LD_SHOW_AUXV, LD_STATIC_TLS_EXTRA, + LD_NO_DL_ITERATE_PHDR_AFTER_FORK, }; void _rtld_error(const char *, ...) __printflike(1, 2) __exported; diff --git a/libexec/rtld-elf/rtld_lock.c b/libexec/rtld-elf/rtld_lock.c index 0c790450dcec..323bb7494c32 100644 --- a/libexec/rtld-elf/rtld_lock.c +++ b/libexec/rtld-elf/rtld_lock.c @@ -463,6 +463,7 @@ _rtld_atfork_pre(int *locks) if (locks == NULL) return; + bzero(ls, sizeof(ls)); /* * Warning: this did not worked well with the rtld compat @@ -472,7 +473,8 @@ _rtld_atfork_pre(int *locks) * _rtld_atfork_pre() must provide the working implementation * of the locks anyway, and libthr locks are fine. */ - wlock_acquire(rtld_phdr_lock, &ls[0]); + if (ld_get_env_var(LD_NO_DL_ITERATE_PHDR_AFTER_FORK) == NULL) + wlock_acquire(rtld_phdr_lock, &ls[0]); wlock_acquire(rtld_bind_lock, &ls[1]); /* XXXKIB: I am really sorry for this. */ @@ -492,5 +494,6 @@ _rtld_atfork_post(int *locks) ls[0].lockstate = locks[2]; ls[1].lockstate = locks[0]; lock_release(rtld_bind_lock, &ls[1]); - lock_release(rtld_phdr_lock, &ls[0]); + if (ld_get_env_var(LD_NO_DL_ITERATE_PHDR_AFTER_FORK) == NULL) + lock_release(rtld_phdr_lock, &ls[0]); }