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_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18478 invoked from network); 17 Nov 2021 14:33:51 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 17 Nov 2021 14:33:51 -0000 Received: (qmail 18304 invoked by uid 550); 17 Nov 2021 14:33:48 -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 3751 invoked from network); 17 Nov 2021 14:04:31 -0000 Message-ID: <27df10f8-c044-e960-350a-d0a40b774bed@unboiled.info> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=unboiled.info; s=mail; t=1637157857; bh=u5GY7YdVGRc+qri3BZbrjiaLZZRfyTw5lXUVchftito=; h=Date:From:Subject:To; b=Gjgb5haFXUzmcoLf3Iw7WR/USdhCh6XqAIjUxt64J4rsjpyaISkhyZ+neEQ5Aag+C Gj2tLUXo2uvSQ6x8eEZZBWCjG2b2Poyn4VprjJDXcxiSE/U/QdHkFAukIgKFtK5r6r gKwIOY0sIGyxQfeDfnThIQdYu/rxM0qSalQyKyzI= Date: Wed, 17 Nov 2021 15:04:15 +0100 MIME-Version: 1.0 Content-Language: en-US From: Alexander Sosedkin To: musl@lists.openwall.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: [musl] $ORIGIN rpath expansion without /proc: code looks wrong Hello, I've encountered a case of a binary with an rpath of /some/meaningful/lib:$ORIGIN/../lib not starting up due to not finding /some/meaningful/lib/libxyz.so. ldd'ing said it's there though. And the library was found alright when I patchelf'd rpath to just /some/meaningful/lib I dug into musl code and came across that bit that checks /proc. Sure enough, when I tried mounting /proc, it started working fine. Yet the error handling from accessing /proc puzzles me: ldso/dynlink.c, fixup_rpath(): l = readlink("/proc/self/exe", buf, buf_size); if (l == -1) switch (errno) { case ENOENT: case ENOTDIR: case EACCES: break; default: return -1; } if (l >= buf_size) return 0; buf[l] = 0; origin = buf; hitting that break like I had means zeroing buf[-1], right? Could somebody take a look at this and double-check that this codepath makes sense? My attempts at comprehending it fail irrecoverably at this line. (CC me on replies, please. No nice context to provide, building my own toolchain at https://github.com/t184256/bootstrap-from-tcc)