From nobody Mon Aug 05 00:32:42 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 4Wccpf45dCz5S8SJ; Mon, 05 Aug 2024 00:32:42 +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 4Wccpf2Rfjz4DHH; Mon, 5 Aug 2024 00:32:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722817962; 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=P0BtX8PzPZqXtpcrGNck/esyisMx4DrGfzKjvTp3wbk=; b=YwBfWS4W2IgR4ECKgq4XJR9k+WCFplDP/gYdzFK1IOGImjaUplPcxqiTnhcIlQjPCJ6wna L/K7NCCilO/aguJuWMfJSzrd4WJBfbX6tUhssjwg8/a5BsefmJK6u9gX8kGX/ReIhZS3wU SNtcOGFt1ZjFbUDeRqfWSH0cnDT5IvXWTY8xeLfaiWvUeLpiPcrgMSHK7pTRJ2q9GmDI9/ DdJmhUlDWtHC1BymmSQp7KuuAmKqvFxUmUoyA1sgT11D2uYkaxejxq7O/zeVSevDQHlQIq eyKE2wubmQhxsoWYL6e24VQG4nOCSuj9lsgj4/vqPq5t+go/kx0OFB24fsLCVw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722817962; a=rsa-sha256; cv=none; b=nZTA64e2oUX+jq2c2SlIf5dMN2Uj29t1m3Tn6a6mXbrayM2hPVhg5m2tVHmOIeDI3CCD3X ddtIbCRpR5RXezNn1sIL/MKRDr198O8o+8WTYXzwfYzhkO3e9NWxdb34T8raybOYaCEnAR H4x1d9tAOOmNFt0L/fRrj7m3OIBkUR2AZaZ6+BMckHJMvrCDGmMDvDEk6ETBBJWidpZxzR o0y59G8bQm2i7GTlrV/FBEtfB+nrc3jhMzIdjekGsUuu0S+MEWCwywP3TYtckGnzp9Zx+c 0G8jgHBVh0DtFKN3fGh+Pryl39WGb0DfiQQ7Hea3iDCCF5WGlWkXX85K2gmXbQ== 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=1722817962; 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=P0BtX8PzPZqXtpcrGNck/esyisMx4DrGfzKjvTp3wbk=; b=nvzCeRlLzW1Nbc87froh7JpowGFHZH7guuNOjae8buaawlm9cIPNu+rrgTf1jgifnDSyBS zKnK17bGRuPWGFqJ7Db2Bbkdx1Ph6UqOwRRCuCjH41JjJBaKwx4gUaFwlnj1g87X0l8bIp +yUcP5jR86sK3VgnOSqgVzzAOfAGikRmgqFsuV3KrICHpq8+Z2PzclRDworMK071h4dxtp 3LQvzQn8tds8kfbvIh/0+1/YaCMwrEyeVHBKlBrUP9suiZtAceeN6OhLgNE1Tct6yOc1HY YfhAMW+ec0u4butmxLRY99JLiu2PsPcMfh+n+YjPdYBoxXCOwyygqc8mOlxYuQ== 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 4Wccpf23P7z1Ghq; Mon, 5 Aug 2024 00:32:42 +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 4750WgYB003158; Mon, 5 Aug 2024 00:32:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4750WgOb003155; Mon, 5 Aug 2024 00:32:42 GMT (envelope-from git) Date: Mon, 5 Aug 2024 00:32:42 GMT Message-Id: <202408050032.4750WgOb003155@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 279e543dc707 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 279e543dc707ee19b28cee8a00deafea1f8b8d8e Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=279e543dc707ee19b28cee8a00deafea1f8b8d8e commit 279e543dc707ee19b28cee8a00deafea1f8b8d8e Author: Konstantin Belousov AuthorDate: 2024-07-17 04:05:33 +0000 Commit: Konstantin Belousov CommitDate: 2024-08-05 00:32:11 +0000 rtld: add LD_NO_DL_ITERATE_PHDR_AFTER_FORK env var PR: 280318 (cherry picked from commit 860c4d94ac46cee35a678cf3c9cdbd437dfed75e) --- 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 411fe7956873..e7fcfde8f474 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -376,6 +376,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 96a9da3c4ea3..97187b24ce84 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -383,6 +383,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]); }