From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 0454A2A712 for ; Wed, 7 Feb 2024 02:23:20 +0100 (CET) Received: (qmail 26184 invoked by uid 550); 7 Feb 2024 01:20:33 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 26129 invoked from network); 7 Feb 2024 01:20:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1707268985; x=1707873785; darn=lists.openwall.com; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=suOm4nBZPg0IFE+UvvColBMoxUVB2twd/mlh0VkV1tQ=; b=V0KefvGSNU3fEwFk2Kl6ebQElCFF30Ljj+4VuNDUJBuiTVoXSutyKqPKeq3AVBFHIf IHyIZ2svUApoFQwR+sc6SYRDn8oWgSGOHeZcM7mtXKM5x/dZqyNHhqBN5U7gZGugjxpT QWMfVH+vqQ4UPGIAL/JIkFtK8Iyo8nwSXKFr4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707268985; x=1707873785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=suOm4nBZPg0IFE+UvvColBMoxUVB2twd/mlh0VkV1tQ=; b=btnMcFbewVT5LhNzb5uKBJFwAQgfGgTw/JzuBUA+HQ/bBlXbCVBzxEYGhfYkuqyF4o cPtvgLBymf3cJ9Cu7bMm4//W/xionW5/Ho8RiYj4pDa+a8yeMyUx3mxlyhaP2Tjj20rT HR234kCgoWiBv0OF9pm2cpBZc6R6TU1v0a0+jdyzlIb4qRYMY06XzIXwij/4lhkh2yOz JmNRyVsUXZU0oGtYlgzsLD2lYj0bHq/LsTb5+sFQH9RChNGZ9bkrcFn09YhYY5+8PneY 58uKDC5GpkylD88UrKvb45K+ojeLGK8mBn8LTJQZ7K/AVld3oXPIs4nNOw6aNrurl756 34Kw== X-Gm-Message-State: AOJu0Yx8kyJfFHZIPH7A6Q/y/i7qPnyV5U9VYSqp7LeKRQuvtILf/H9v eGO9Y0e4mpXWLvztdJtx0xqwItzO3Fh+nJ0awkg5/ZanKCG7cEwQTCCEdVA3Cis0BdZGpNU+rwk Ccw== X-Google-Smtp-Source: AGHT+IHmHRh11UpfEyT79nN06Ls5BYswJrY7jZjXgxsx8uxwY45AIgumFpLgzS1Rf9MqUkeM7/8F7w== X-Received: by 2002:a05:6214:1886:b0:68c:b0f6:924 with SMTP id cx6-20020a056214188600b0068cb0f60924mr3744247qvb.6.1707268984657; Tue, 06 Feb 2024 17:23:04 -0800 (PST) From: Markus Mayer To: Musl Mailing List Cc: Markus Mayer Date: Tue, 6 Feb 2024 17:22:43 -0800 Message-ID: <20240207012247.1121273-2-mmayer@broadcom.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207012247.1121273-1-mmayer@broadcom.com> References: <20240207012247.1121273-1-mmayer@broadcom.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH 1/1] ldso: continue searching if wrong architecture is found first 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 --- 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