From nobody Sat Apr 19 10:38:44 2025 X-Original-To: current@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 4Zfp5S5HZZz5tBdF for ; Sat, 19 Apr 2025 10:38:52 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4Zfp5R69qfz3nFg; Sat, 19 Apr 2025 10:38:51 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 53JAciZd046573; Sat, 19 Apr 2025 13:38:47 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 53JAciZd046573 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 53JAcieq046572; Sat, 19 Apr 2025 13:38:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 19 Apr 2025 13:38:44 +0300 From: Konstantin Belousov To: Andriy Gapon Cc: FreeBSD Current Subject: Re: RTLD_DEEPBIND question Message-ID: References: <0b3dda4e-53e4-40e5-9484-8b5ffb84e658@FreeBSD.org> <900c8521-559a-47b5-acaa-ae941f6852c4@freebsd.org> <7c4e1682-d797-493c-8326-08d51dde3359@FreeBSD.org> List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on tom.home X-Spamd-Result: default: False [2.83 / 15.00]; NEURAL_SPAM_LONG(0.99)[0.986]; NEURAL_SPAM_SHORT(0.93)[0.932]; NEURAL_SPAM_MEDIUM(0.91)[0.912]; MIME_GOOD(-0.10)[text/plain]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; R_DKIM_NA(0.00)[]; MLMMJ_DEST(0.00)[current@freebsd.org]; RCPT_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_ALL(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; RCVD_TLS_LAST(0.00)[]; HAS_XAW(0.00)[] X-Rspamd-Queue-Id: 4Zfp5R69qfz3nFg X-Spamd-Bar: ++ On Sat, Apr 19, 2025 at 01:29:15PM +0300, Konstantin Belousov wrote: > On Sat, Apr 19, 2025 at 01:25:28PM +0300, Andriy Gapon wrote: > > On 19/04/2025 12:39, Andriy Gapon wrote: > > > On 19/04/2025 12:25, Andriy Gapon wrote: > > > > On 19/04/2025 02:41, Konstantin Belousov wrote: > > > > > RTLD_DEEPBIND works by first iterating over all (recursive) DT_NEEEDED > > > > > object for the object where the symbol is resolved, then by looking at > > > > > the global list of loaded objects. > > > > > Non-deepbind resolution is performed by looking at the global list. > > > > > > > > > > You can see it in the rtld.c:symlook_default(). > > > > > > From a quick look at the code, should we try to resolve the symbol in > > > refobj itself when it's marked with deepbind? > > Oh, and it looks like objects loaded under the "deepbind" object (e.g., > > needed objects) may not be aware that they are in the deepbind sub-tree? > > But should they? > > Lets start with some minimal intrusive change: > And there is the version with the recursive marking by deepbind: diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 2346c6eae9f6..9767c8e7016c 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -3824,27 +3824,26 @@ dlopen_object(const char *name, int fd, Obj_Entry *refobj, int lo_flags, if ((lo_flags & (RTLD_LO_EARLY | RTLD_LO_IGNSTLS)) == 0 && obj->static_tls && !allocate_tls_offset(obj)) { - _rtld_error("%s: No space available " - "for static Thread Local Storage", + _rtld_error( + "%s: No space available for static Thread Local Storage", obj->path); result = -1; } if (result != -1) result = load_needed_objects(obj, - lo_flags & - (RTLD_LO_DLOPEN | RTLD_LO_EARLY | - RTLD_LO_IGNSTLS | RTLD_LO_TRACE)); + lo_flags & (RTLD_LO_DLOPEN | RTLD_LO_EARLY | + RTLD_LO_IGNSTLS | RTLD_LO_TRACE | + RTLD_LO_DEEPBIND)); init_dag(obj); ref_dag(obj); if (result != -1) result = rtld_verify_versions(&obj->dagmembers); if (result != -1 && ld_tracing) goto trace; - if (result == -1 || - relocate_object_dag(obj, - (mode & RTLD_MODEMASK) == RTLD_NOW, &obj_rtld, - (lo_flags & RTLD_LO_EARLY) ? SYMLOOK_EARLY : 0, - lockstate) == -1) { + if (result == -1 || relocate_object_dag(obj, + (mode & RTLD_MODEMASK) == RTLD_NOW, &obj_rtld, + (lo_flags & RTLD_LO_EARLY) ? SYMLOOK_EARLY : 0, + lockstate) == -1) { dlopen_cleanup(obj, lockstate); obj = NULL; } else if (lo_flags & RTLD_LO_EARLY) { @@ -4679,12 +4678,13 @@ symlook_default(SymLook *req, const Obj_Entry *refobj) */ res = symlook_obj(&req1, refobj); if (res == 0 && (refobj->symbolic || - ELF_ST_VISIBILITY(req1.sym_out->st_other) == STV_PROTECTED)) { + ELF_ST_VISIBILITY(req1.sym_out->st_other) == STV_PROTECTED || + refobj->deepbind)) { req->sym_out = req1.sym_out; req->defobj_out = req1.defobj_out; assert(req->defobj_out != NULL); } - if (refobj->symbolic || req->defobj_out != NULL) + if (refobj->symbolic || req->defobj_out != NULL || refobj->deepbind) donelist_check(&donelist, refobj); if (!refobj->deepbind)