Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Mon,  4 Apr 2022 20:18:59 -0700
From: Colin Cross <ccross@...gle.com>
To: musl@...ts.openwall.com
Cc: Colin Cross <ccross@...gle.com>
Subject: [PATCH] dl_iterate_phdr: return empty string for the name of the main program

The glibc man page for dl_iterate_phdr states:
The first object visited by callback is the main program.   For  the  main  program,  the
dlpi_name field will be an empty string.

This is relied upon by the LLVM ASAN runtime:
https://github.com/llvm/llvm-project/blob/72ec2f76396fe5de5397bfb898993fdb22e2b0da/compiler-rt/lib/asan/asan_linux.cpp#L135

Without this patch, running a binary that has been instrumented with
ASAN fails with:
==4156919==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.

Use a constant empty string instead of the DSO name field for the first
entry in the DSO list.

---

This has come up previously on the mailing list at
https://www.openwall.com/lists/musl/2018/05/28/1.

 ldso/dynlink.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index fd0d38e9..d2e22a0b 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -2323,12 +2323,15 @@ no_redir:
 
 int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
 {
+	static const char* empty_string = "";
 	struct dso *current;
 	struct dl_phdr_info info;
 	int ret = 0;
 	for(current = head; current;) {
 		info.dlpi_addr      = (uintptr_t)current->base;
-		info.dlpi_name      = current->name;
+                /* glibc uses an empty string for the main program */
+		info.dlpi_name      = (current == head) ? empty_string :
+			current->name;
 		info.dlpi_phdr      = current->phdr;
 		info.dlpi_phnum     = current->phnum;
 		info.dlpi_adds      = gencnt;
-- 
2.35.1.1094.g7c7d902a7c-goog

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.