From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14365 invoked from network); 5 Apr 2022 03:19:19 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 5 Apr 2022 03:19:19 -0000 Received: (qmail 31830 invoked by uid 550); 5 Apr 2022 03:19:16 -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 31793 invoked from network); 5 Apr 2022 03:19:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=b+xNmWDl/s2kMnys0sBOM/wBpmZFBYW5Aymdvf5m6j8=; b=DiDZZRbq8zsMOx/pTdTKIUzLoRu1klwr864skIU8siBTAm5k2Z3XHvBD2n6nLVToel VCBKZ3KLMavQ2DcLY5PVeAvixqrzzeoXNy5Ql19W4EJs1trg1rr2qYW6J7FZLNiEFQgv /pKj1v8+lV6ipWnLdpC+ERGIpA7Y8nkQVPxgRF2qL3CMo0fsft+o6cqBx1o+dYsGmVxc 1dPS1e+VJvadVICCWyEY7HuAebNuD6ZnJwN668GSBp7/D9tSA954On5p/gn2nxohX+QQ O0xmkzyy6cnz6juI0Lv7jzOzqMjIyckZo/ZSvLIwLab8JNjstikQPbPoeIrFRrDgcLnM znTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=b+xNmWDl/s2kMnys0sBOM/wBpmZFBYW5Aymdvf5m6j8=; b=PLqU1emItj2b/2PzTQJGA+Q26TGML7birk1W0MLf6nGsIjzM8+MgsaIkA1eYIZW60Z GLLAjap7WswuChon6UVz4HusaPV3PRaA0ruvrddafotoBkaRaRWVUuySvSDlQ0GC3ZFI P6SyDoDWPj7FNLh2gfezXS/ILNXNBUZY8Wb170phLtpgA+7P4sD81xnE4usI54mpwOXG SS3gwGViKLF2jlD0dZpje/lJXDZJ9BJkF6hbHHlXSruLbStyYn0Vtncmf7O0hfF+RpWU 89UzpxoRynlj5Nmq1aSuoNPPC4QkE4H9GGYDH4gBqp+2UB3JVWkqlspxniX0hTbSgZ88 cXUA== X-Gm-Message-State: AOAM530zMc/dO9w+icW5eIVB6E/xpWyBCA4eOYyjAWv/2IqxqgF56IYn IxPDfdaQxYIvA2ItaM0Mj5eDvGyx2KPBl+ftjBF/r+YSYNQw5fKXcSSi4lnbiNK7Edr9TVW95NH lZySKn6ek5Qsc1j/xhtcpTcDA7wbE54igMT09AxNtQXxrMCwxZsSgLJvS45/IHvw= X-Google-Smtp-Source: ABdhPJwUbsDmqoYUf+e16NBrAhcb7uxWVZrHkW0tFSzqc3GQv3YLAn3uF5LLm4n5oz9BaiGGLwrgbsrcAUU= X-Received: from walnut.mtv.corp.google.com ([2620:15c:211:202:2b46:44ce:fb25:105e]) (user=ccross job=sendgmr) by 2002:a81:6fc5:0:b0:2eb:57fc:2742 with SMTP id k188-20020a816fc5000000b002eb57fc2742mr1076839ywc.216.1649128744407; Mon, 04 Apr 2022 20:19:04 -0700 (PDT) Date: Mon, 4 Apr 2022 20:18:59 -0700 Message-Id: <20220405031859.17673-1-ccross@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog From: Colin Cross To: musl@lists.openwall.com Cc: Colin Cross Content-Type: text/plain; charset="UTF-8" Subject: [musl] [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