From nobody Wed Aug 09 05:28:47 2023 X-Original-To: dev-commits-src-main@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 4RLJWN0K1hz4mBl9; Wed, 9 Aug 2023 05:28:48 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RLJWM6qBBz4D3x; Wed, 9 Aug 2023 05:28:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691558928; 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=CZ+lWiN94gkiScEtCo5n39PfwKA0U0S4pb8NpyFOq3M=; b=vsIkUFOBu+Xw1e0EqagqU6JE5UCuhXd2YEiQU6Ra7VnwjntMozMPI8fjoZqVKsSfb4wuFo DH8i55bMAaaQDYNn3JY+OPODSbPx5Cd40DLryb4YEK0rxOVzbRnXcIyYgRQzxhyF9WK31n ycYEQ8ZghFT8TXGNJcCJaMMGZk7B2l1iPSLv2y5oJc+KV45IIzMOCGpqK/FVNDIy9Ti5Ns viSmHPDRjCrure0wd/YE0Mm4gGOdOqUsUtlz3E/6riNaHKPb3FaWicS4c6IJBlDtVqydfV KGXEc1S3ApfYeJ9kX9flIJCxVyhODjQCRsAO2G/+pYp5MeV8BKYbfPcusUahEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691558928; 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=CZ+lWiN94gkiScEtCo5n39PfwKA0U0S4pb8NpyFOq3M=; b=HWdbBTB9ROG0uSpEjRDCLkAw/xDfLjW75JnvDUDc2Yp2Jz7sTRe+4zNdtWHFldzdQusWQ5 dD3G+6b6oYxAmJdeANHaCrsHEYA15iMarVT9Nt9jI2zwoFI3G/bNx+w9rqhwBQhOLBIB+6 ujNRklYlZQl7kgsCmKsYOts90drcJx4X+r0pIVkV0jlEOUPzZuBpje13L2tgEy0caj28vN w4icDKAiiK973mEmSE6wRqodGLgeXx0DTqV9oUBvjhMJpD+vyUi8x7rN1kf35OfkFB56s+ 6bQfQSVfZFBGUrSKQUsbroTBEC85l28XIBJm39txgKf/sQArZde/6uyEm/EAXA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691558928; a=rsa-sha256; cv=none; b=UV+VHg1nq3G+cBxMW+am4Oo/492jWhT3/NuYb8M6/KQBAAgNSOyluQh0yMnpiFx0q7Coqj Q+pRoK0jHBoFgKSp2J9UyyMRp8UBm6MpG/6aQt5kdHfDyoWq06Lv691fT/5V7X05yHbZzb +8+2eQxq1aMGIWhbq09+HhDFqOYHhTwg79arhC+N2S6ru0LvZ4JFJg5uOA5DRjfTp2LM5X MjRHxjSwLVqKpWedVIJOm3CyqI6NFy0JturrKHEe0jx1wFzjGoie5OunAdsaw9KLhohQdB oj+mbcbY4tiQyaZ5mQuiWiaZCG/r+HlEFt5k8cEXinDO+PrJW6X7cJq2IQqenQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RLJWM5tVCz13j2; Wed, 9 Aug 2023 05:28:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3795SlwE023334; Wed, 9 Aug 2023 05:28:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3795SlFA023331; Wed, 9 Aug 2023 05:28:47 GMT (envelope-from git) Date: Wed, 9 Aug 2023 05:28:47 GMT Message-Id: <202308090528.3795SlFA023331@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: 21a52f99440c - main - libc dlfcn.c: make dl_iterate_phdr() from libc more useful List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 21a52f99440c9bec7679f3b0c5c9d888901c3694 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=21a52f99440c9bec7679f3b0c5c9d888901c3694 commit 21a52f99440c9bec7679f3b0c5c9d888901c3694 Author: Konstantin Belousov AuthorDate: 2023-08-09 05:07:05 +0000 Commit: Konstantin Belousov CommitDate: 2023-08-09 05:07:05 +0000 libc dlfcn.c: make dl_iterate_phdr() from libc more useful Apparently there are applications that resolve dl_iterate_phdr from libc and try to call the symbol. Our libc only provides stubs for dl* to satisfy static linker or statically linked binaries, and is not prepared to this situation. Add a code to dso libc to find real dl_iterate_phdr and redirect the call to it. Reported by: yuri PR: 272992 Sponsored by: The FreeBSD Foundation MFC after: 1 week --- lib/libc/gen/dlfcn.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c index 61984e2fe86c..f1ee86ec1934 100644 --- a/lib/libc/gen/dlfcn.c +++ b/lib/libc/gen/dlfcn.c @@ -169,7 +169,9 @@ _rtld_thread_init(void *li __unused) #ifndef IN_LIBDL static pthread_once_t dl_phdr_info_once = PTHREAD_ONCE_INIT; static struct dl_phdr_info phdr_info; +#ifndef PIC static mutex_t dl_phdr_info_lock = MUTEX_INITIALIZER; +#endif static void dl_init_phdr_info(void) @@ -208,7 +210,16 @@ int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *) __unused, void *data __unused) { -#ifndef IN_LIBDL +#if defined IN_LIBDL + return (0); +#elif defined PIC + int (*r)(int (*)(struct dl_phdr_info *, size_t, void *), void *); + + r = dlsym(RTLD_DEFAULT, "dl_iterate_phdr"); + if (r == NULL) + return (0); + return (r(callback, data)); +#else tls_index ti; int ret; @@ -223,8 +234,6 @@ dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *) __unused, ret = callback(&phdr_info, sizeof(phdr_info), data); mutex_unlock(&dl_phdr_info_lock); return (ret); -#else - return (0); #endif }