mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Mayer <mmayer@broadcom.com>
To: Musl Mailing List <musl@lists.openwall.com>
Cc: Markus Mayer <mmayer@broadcom.com>
Subject: [musl] [PATCH 1/1] ldso: continue searching if wrong architecture is found first
Date: Tue,  6 Feb 2024 17:22:43 -0800	[thread overview]
Message-ID: <20240207012247.1121273-2-mmayer@broadcom.com> (raw)
In-Reply-To: <20240207012247.1121273-1-mmayer@broadcom.com>

When LD_LIBRARY_PATH is being used, the shared library loader may end up
finding a shared library with the correct name but from a wrong
architecture. This primarily happens when a 32-bit / 64-bit mismatch
occurs.

Rather than giving up immediately and aborting, the shared library
loader should continue to look in all known locations for a matching
library that may work.

Signed-off-by: Markus Mayer <mmayer@broadcom.com>
---
 ldso/dynlink.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index fd09ca69932c..d7f085b0a212 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1019,6 +1019,7 @@ static struct dso *load_library(const char *name, struct dso *needed_by)
 	size_t alloc_size;
 	int n_th = 0;
 	int is_self = 0;
+	int is_using_env_path = 0;
 
 	if (!*name) {
 		errno = EINVAL;
@@ -1072,7 +1073,11 @@ static struct dso *load_library(const char *name, struct dso *needed_by)
 		}
 		if (strlen(name) > NAME_MAX) return 0;
 		fd = -1;
-		if (env_path) fd = path_open(name, env_path, buf, sizeof buf);
+		if (env_path) {
+			fd = path_open(name, env_path, buf, sizeof buf);
+			is_using_env_path = (fd >= 0);
+		}
+retry:
 		for (p=needed_by; fd == -1 && p; p=p->needed_by) {
 			if (fixup_rpath(p, buf, sizeof buf) < 0)
 				fd = -2; /* Inhibit further search. */
@@ -1138,7 +1143,16 @@ static struct dso *load_library(const char *name, struct dso *needed_by)
 	}
 	map = noload ? 0 : map_library(fd, &temp_dso);
 	close(fd);
-	if (!map) return 0;
+	if (!map) {
+		if (is_using_env_path) {
+			/* If LD_LIBARY_PATH resulted in a library that couldn't
+			 * be loaded, let's try the default locations. */
+			fd = -1;
+			is_using_env_path = 0;
+			goto retry;
+		}
+		return 0;
+	}
 
 	/* Avoid the danger of getting two versions of libc mapped into the
 	 * same process when an absolute pathname was used. The symbols
-- 
2.43.0


  reply	other threads:[~2024-02-07  1:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07  1:22 [musl] [PATCH 0/1] ldso: continue searching if wrong architecture is found Markus Mayer
2024-02-07  1:22 ` Markus Mayer [this message]
2024-02-07 17:30   ` [musl] [PATCH 1/1] ldso: continue searching if wrong architecture is found first Rich Felker
2024-02-07 19:10     ` i262jq
2024-02-07 19:51       ` Thorsten Glaser
2024-02-08 15:52         ` i262jq
2024-02-07 20:59     ` Markus Mayer
2024-02-07  8:26 ` [musl] [PATCH 0/1] ldso: continue searching if wrong architecture is found i262jq
2024-02-07 16:45   ` enh
2024-02-07 17:07     ` Thorsten Glaser
2024-02-07 17:54       ` enh
2024-02-07 18:09 ` Colin Cross
2024-04-02 20:59   ` Markus Mayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240207012247.1121273-2-mmayer@broadcom.com \
    --to=mmayer@broadcom.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).