From owner-svn-src-all@freebsd.org Tue May 26 19:22:47 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 828422F1EE4; Tue, 26 May 2020 19:22:47 +0000 (UTC) (envelope-from kib@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49WkPg2zg5z3X86; Tue, 26 May 2020 19:22:47 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 60D288894; Tue, 26 May 2020 19:22:47 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04QJMlOZ006945; Tue, 26 May 2020 19:22:47 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04QJMk5q006943; Tue, 26 May 2020 19:22:46 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202005261922.04QJMk5q006943@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 26 May 2020 19:22:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361537 - head/libexec/rtld-elf X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/libexec/rtld-elf X-SVN-Commit-Revision: 361537 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 May 2020 19:22:47 -0000 Author: kib Date: Tue May 26 19:22:46 2020 New Revision: 361537 URL: https://svnweb.freebsd.org/changeset/base/361537 Log: Add version indicators to rtld. It is wrong to relate on __FreeBSD_version, either from include/param.h, kernel, or libc, to check for rtld features. Rtld might be from newer world than the running userspace. Add special private symbols exported by rtld itself, to indicate the changes in runtime behavior, and features that cannot be otherwise detected or deduced at runtime. Note that the symbols are not exported from libc, so they intentionally cannot be linked against, and exported from the private namespace from rtld. Consumers are required to use dlsym(3). For instance, for _rtld_version_laddr_offset, user should do ptr = dlsym(RTLD_DEFAULT, "_rtld_version_laddr_offset") or even ptr = dlvsym(RTLD_DEFAULT, "_rtld_version_laddr_offset", "FBSDprivate_1.0"); Non-null ptr means that the change is present. Also add _rtld_version__FreeBSD_version indicator to report the headers version used at time of the rtld build. Reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24982 Modified: head/libexec/rtld-elf/Symbol.map head/libexec/rtld-elf/rtld.1 head/libexec/rtld-elf/rtld.c Modified: head/libexec/rtld-elf/Symbol.map ============================================================================== --- head/libexec/rtld-elf/Symbol.map Tue May 26 19:09:19 2020 (r361536) +++ head/libexec/rtld-elf/Symbol.map Tue May 26 19:22:46 2020 (r361537) @@ -32,4 +32,6 @@ FBSDprivate_1.0 { _rtld_get_stack_prot; _rtld_is_dlopened; _r_debug_postinit; + _rtld_version__FreeBSD_version; + _rtld_version_laddr_offset; }; Modified: head/libexec/rtld-elf/rtld.1 ============================================================================== --- head/libexec/rtld-elf/rtld.1 Tue May 26 19:09:19 2020 (r361536) +++ head/libexec/rtld-elf/rtld.1 Tue May 26 19:22:46 2020 (r361537) @@ -355,6 +355,54 @@ ignores and is naturally prone to race conditions. Environments which rely on such restrictions are weak and breakable on their own. +.Sh VERSIONING +Newer +.Nm +might provide some features or changes in runtime behavior that cannot be +easily detected at runtime by checking of the normal exported symbols. +Note that it is almost always wrong to verify +.Dv __FreeBSD_version +in userspace to detect features, either at compile or at run time, +because either kernel, or libc, or environment variables could not +match the running +.Nm . +.Pp +To solve the problem, +.Nm +exports some feature indicators in the +.Fx +private symbols namespace +.Dv FBSDprivate_1.0 . +Symbols start with the +.Dv _rtld_version +prefix. +Current list of defined symbols and corresponding features is: +.Bl -tag -width indent +.It Dv _rtld_version__FreeBSD_version +Symbol exports the value of the +.Dv __FreeBSD_version +definition as it was provided during the +.Nm +build. +The symbol is always present since the +.Dv _rtld_version +facility was introduced. +.It Dv _rtld_version_laddr_offset +The +.Va l_addr +member of the +.Vt link_map +structure contains the load offset of the shared object. +Before that, +.Va l_addr +contained the base address of the library. +See +.Xr dlinfo 3 . +.Pp +Also it indicates the presence of +.Va l_refname +member of the structure. +.El .Sh FILES .Bl -tag -width ".Pa /var/run/ld-elf32.so.hints" -compact .It Pa /var/run/ld-elf.so.hints @@ -369,6 +417,7 @@ The libmap configuration file for 32-bit binaries on 6 .Sh SEE ALSO .Xr ld 1 , .Xr ldd 1 , +.Xr dlinfo 3 , .Xr capsicum 4 , .Xr elf 5 , .Xr libmap.conf 5 , Modified: head/libexec/rtld-elf/rtld.c ============================================================================== --- head/libexec/rtld-elf/rtld.c Tue May 26 19:09:19 2020 (r361536) +++ head/libexec/rtld-elf/rtld.c Tue May 26 19:22:46 2020 (r361537) @@ -5785,3 +5785,9 @@ realloc(void *cp, size_t nbytes) return (__crt_realloc(cp, nbytes)); } + +extern int _rtld_version__FreeBSD_version __exported; +int _rtld_version__FreeBSD_version = __FreeBSD_version; + +extern char _rtld_version_laddr_offset __exported; +char _rtld_version_laddr_offset;