From nobody Tue Feb 13 00:58:09 2024 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 4TYjcV0CTsz59Mmg for ; Tue, 13 Feb 2024 00:58:18 +0000 (UTC) (envelope-from kib@freebsd.org) 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 4TYjcS6LYxz4kPM for ; Tue, 13 Feb 2024 00:58:16 +0000 (UTC) (envelope-from kib@freebsd.org) Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=freebsd.org (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kib@freebsd.org) smtp.mailfrom=kib@freebsd.org 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 41D0w9l0093933; Tue, 13 Feb 2024 02:58:12 +0200 (EET) (envelope-from kib@freebsd.org) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 41D0w9l0093933 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 41D0w9Kh093932; Tue, 13 Feb 2024 02:58:09 +0200 (EET) (envelope-from kib@freebsd.org) X-Authentication-Warning: tom.home: kostik set sender to kib@freebsd.org using -f Date: Tue, 13 Feb 2024 02:58:09 +0200 From: Konstantin Belousov To: Alexander Leidinger Cc: current@freebsd.org Subject: Re: segfault in ld-elf.so.1 Message-ID: References: <1707730081-90734-mlmmj-4d88f1fd@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=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on tom.home X-Spamd-Bar: -- X-Spamd-Result: default: False [-2.34 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.34)[-0.340]; DMARC_POLICY_SOFTFAIL(0.10)[freebsd.org : No valid SPF, No valid DKIM,none]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_TWO(0.00)[2]; HAS_XAW(0.00)[]; ARC_NA(0.00)[]; FREEFALL_USER(0.00)[kib]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_TO(0.00)[gmail.com]; R_DKIM_NA(0.00)[]; MLMMJ_DEST(0.00)[current@freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_LAST(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MISSING_XM_UA(0.00)[] X-Rspamd-Queue-Id: 4TYjcS6LYxz4kPM On Mon, Feb 12, 2024 at 11:54:02AM +0200, Konstantin Belousov wrote: > On Mon, Feb 12, 2024 at 10:35:56AM +0100, Alexander Leidinger wrote: > > Hi, > > > > dovecot (and no other program I use on this machine... at least not that I > > notice it) segfaults in ld-elf.so.1 after an update from 2024-01-18-092730 > > to 2024-02-10-144617 (and now 2024-02-11-212006 in the hope the issue would > > have been fixed by changes to libc/libsys since 2024-02-10-144617). The > > issue shows up when I try to do an IMAP login. A successful authentication > > starts the imap process which immediately segfaults. > > > > I didn't recompile dovecot for the initial update, but I did now to rule > > out a regression in this area (and to get access via imap do my normal mail > > account). > > > > > > Backtrace: > The backtrace looks incomplete. It might be the case of infinite recursion, > but I cannot claim it from the trace. > > Does the program segfault if you run it manually? If yes, please provide > me with the tarball of the binary and all required shared libs, including > base system libraries, from your machine. Regardless of my request, you might try the following. Note that I did not tested the patch, ensure that you have a way to recover ld-elf.so.1 if something goes wrong. diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 24abc4580f53..2ff6455c87fc 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -2583,7 +2583,7 @@ static void load_filtees(Obj_Entry *obj, int flags, RtldLockState *lockstate) { - if (!obj->filtees_loaded) { + if (!obj->filtees_loaded && (flags & RTLD_LO_NOFILTEES) == 0) { lock_restart_for_upgrade(lockstate); load_filtee1(obj, obj->needed_filtees, flags, lockstate); load_filtee1(obj, obj->needed_aux_filtees, flags, lockstate); @@ -4479,6 +4479,7 @@ get_program_var_addr(const char *name, RtldLockState *lockstate) symlook_init(&req, name); req.lockstate = lockstate; + req.flags |= SYMLOOK_VAR; donelist_init(&donelist); if (symlook_global(&req, &donelist) != 0) return (NULL); @@ -4690,6 +4691,22 @@ symlook_needed(SymLook *req, const Needed_Entry *needed, DoneList *dlp) return (ESRCH); } +static int +symlook_obj_load_filtees(SymLook *req, SymLook *req1, const Obj_Entry *obj, + Needed_Entry *needed) +{ + DoneList donelist; + int flags, res; + + flags = (req->flags & SYMLOOK_EARLY) != 0 ? RTLD_LO_EARLY : 0; + flags |= (req->flags & SYMLOOK_VAR) != 0 ? RTLD_LO_NOFILTEES : 0; + load_filtees(__DECONST(Obj_Entry *, obj), flags, req->lockstate); + donelist_init(&donelist); + symlook_init_from_req(req1, req); + res = symlook_needed(req1, needed, &donelist); + return (res); +} + /* * Search the symbol table of a single shared object for a symbol of * the given name and version, if requested. Returns a pointer to the @@ -4702,9 +4719,8 @@ symlook_needed(SymLook *req, const Needed_Entry *needed, DoneList *dlp) int symlook_obj(SymLook *req, const Obj_Entry *obj) { - DoneList donelist; SymLook req1; - int flags, res, mres; + int res, mres; /* * If there is at least one valid hash at this point, we prefer to @@ -4719,11 +4735,8 @@ symlook_obj(SymLook *req, const Obj_Entry *obj) if (mres == 0) { if (obj->needed_filtees != NULL) { - flags = (req->flags & SYMLOOK_EARLY) ? RTLD_LO_EARLY : 0; - load_filtees(__DECONST(Obj_Entry *, obj), flags, req->lockstate); - donelist_init(&donelist); - symlook_init_from_req(&req1, req); - res = symlook_needed(&req1, obj->needed_filtees, &donelist); + res = symlook_obj_load_filtees(req, &req1, obj, + obj->needed_filtees); if (res == 0) { req->sym_out = req1.sym_out; req->defobj_out = req1.defobj_out; @@ -4731,11 +4744,8 @@ symlook_obj(SymLook *req, const Obj_Entry *obj) return (res); } if (obj->needed_aux_filtees != NULL) { - flags = (req->flags & SYMLOOK_EARLY) ? RTLD_LO_EARLY : 0; - load_filtees(__DECONST(Obj_Entry *, obj), flags, req->lockstate); - donelist_init(&donelist); - symlook_init_from_req(&req1, req); - res = symlook_needed(&req1, obj->needed_aux_filtees, &donelist); + res = symlook_obj_load_filtees(req, &req1, obj, + obj->needed_aux_filtees); if (res == 0) { req->sym_out = req1.sym_out; req->defobj_out = req1.defobj_out; diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index e8b15095812b..77776f241290 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -298,6 +298,7 @@ TAILQ_HEAD(obj_entry_q, Struct_Obj_Entry); #define SYMLOOK_EARLY 0x04 /* Symlook is done during initialization. */ #define SYMLOOK_IFUNC 0x08 /* Allow IFUNC processing in reloc_non_plt(). */ +#define SYMLOOK_VAR 0x10 /* Flags for load_object(). */ #define RTLD_LO_NOLOAD 0x01 /* dlopen() specified RTLD_NOLOAD. */ @@ -309,6 +310,8 @@ TAILQ_HEAD(obj_entry_q, Struct_Obj_Entry); initialization during the image start. */ #define RTLD_LO_IGNSTLS 0x40 /* Do not allocate static TLS */ #define RTLD_LO_DEEPBIND 0x80 /* Force symbolic for this object */ +#define RTLD_LO_NOFILTEES 0x100 /* Skip loading filtees, sym resolution + from dlopen() */ /* * Symbol cache entry used during relocation to avoid multiple lookups