From patchwork Thu Sep 17 09:56:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stian Halseth X-Patchwork-Id: 144053 X-Patchwork-Delegate: fweimer@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67D434BA79B6 for ; Thu, 17 Sep 2026 09:57:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67D434BA79B6 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, secure) header.d=itx.no header.i=@itx.no header.a=rsa-sha256 header.s=mx.itx.no header.b=G7/DDfU+ X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx.itxnorge.no (itx-kvm-14.itxnorge.no [91.189.121.228]) by sourceware.org (Postfix) with ESMTPS id 2D28C4BA23FA for ; Thu, 17 Sep 2026 09:56:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D28C4BA23FA Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=itx.no Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=itx.no ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2D28C4BA23FA Authentication-Results: sourceware.org; arc=none smtp.remote-ip=91.189.121.228 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789639019; cv=none; b=uLBA/jELIC651T01guFVl5jF72ebn8d+icvT08Cb3TrZZ8n/E0mM8OBdPi3cuRaANSnbixsM+3Y59MgoHT9fOeNiOyU/f1qy6223tPiUqqIlrsUzifeQUAhb/vOqtP9eTJRd2SP7OMU6/A9B4VrtyEAMRlvv9JR4KiqLKhcS+3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789639019; c=relaxed/simple; bh=Uie5T9TMleuTerHkH2Jp5893O+J3pJ8JK5eX79AzoXI=; h=From:DKIM-Signature:To:Subject:Date:Message-ID:MIME-Version; b=BoEX9dkLJYwzJJv0ZNii/gfjVnQp8EBpIUmyj9Cb4kyHDXz3PL/bUVRDZSxDEQX8IbU2j2rgM+zaTPBROOrtkkSV0z7Na/tu9ZeMnyE4mQmXoWtQ/nU5LgyW1mqTvHgq+vLbJcD+XPOu0P6dnUH3ncoii9P2hlc8nQIQKDe6ZjU= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, secure) header.d=itx.no header.i=@itx.no header.a=rsa-sha256 header.s=mx.itx.no header.b=G7/DDfU+ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D28C4BA23FA From: Stian Halseth DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itx.no; s=mx.itx.no; t=1789639015; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HUmAajKWDQ+Y575rp474u7KWp+b/6i1aoBdC1/9x4us=; b=G7/DDfU+6CiMxONYGulZoHm4i4ZhFAHQXrHJ9+m/S/oz8Tk5GaNF6VOXZmUP1DfYdK3NyW nDyJk7lW0E4YFHb9RGTIxl4fmko5N0MGiFSvA58skWzmXpf+0Z46MTsuiD70HYf6UQHI1k HVFhsoitK5/n/yuGxYJ3AyOrJfDWyAw= To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, Stian Halseth Subject: [PATCH v2] elf: fix pldd on targets that map objects above 2^63 [BZ #34641] Date: Thu, 17 Sep 2026 11:56:47 +0200 Message-ID: <20260917095647.284940-1-stian@itx.no> In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org pldd reads target's memory with pread on /proc/PID/mem. The offset argument of pread is signed, and ksys_pread64 rejects a negative position. On sparc64 the dynamic linker and the shared objects are mapped at 0xfff8000100000000 and above, so every such read fails with EINVAL and pldd exits with "cannot read r_debug". elf/tst-pldd fails as a result. This is not visible on x86_64, where objects are mapped low. Read the memory with lseek and read instead. lseek on /proc/PID/mem accepts the high offset that pread rejects, and read has no such limit. gdb had the same bug and fixed it the same way, avoiding pread for high addresses (PR gdb/30525, commit 31a56a22c45d). Tested on sparc64: pldd fails on every process before this change and lists them correctly after it. Full make check shows no test that passed before failing after. Signed-off-by: Stian Halseth --- v2: use lseek and read instead of pread with a process_vm_readv fallback, per Adhemerval's review. Drops the process_vm_readv availability concern across ABIs, and is simpler: one path, no fallback, and the helper is defined once in pldd.c for both classes. elf/pldd-xx.c | 12 ++++++------ elf/pldd.c | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/elf/pldd-xx.c b/elf/pldd-xx.c index 29bbb7307..5e75550a5 100644 --- a/elf/pldd-xx.c +++ b/elf/pldd-xx.c @@ -103,7 +103,7 @@ E(find_maps) (const char *exe, int memfd, pid_t pid, void *auxv, error (EXIT_FAILURE, 0, gettext ("cannot find program header of process")); EW(Phdr) *p = xmalloc (phnum * phent); - if (pread (memfd, p, phnum * phent, phdr) != phnum * phent) + if (read_mem (memfd, p, phnum * phent, phdr) != phnum * phent) error (EXIT_FAILURE, 0, gettext ("cannot read program header")); /* Determine the load offset. We need this for interpreting the @@ -124,7 +124,7 @@ E(find_maps) (const char *exe, int memfd, pid_t pid, void *auxv, if (p[i].p_type == PT_DYNAMIC) { EW(Dyn) *dyn = xmalloc (p[i].p_filesz); - if (pread (memfd, dyn, p[i].p_filesz, offset + p[i].p_vaddr) + if (read_mem (memfd, dyn, p[i].p_filesz, offset + p[i].p_vaddr) != p[i].p_filesz) error (EXIT_FAILURE, 0, gettext ("cannot read dynamic section")); @@ -136,7 +136,7 @@ E(find_maps) (const char *exe, int memfd, pid_t pid, void *auxv, if (off != 0) { struct E(r_debug) r; - if (pread (memfd, &r, sizeof (r), off) + if (read_mem (memfd, &r, sizeof (r), off) != sizeof (r)) error (EXIT_FAILURE, 0, gettext ("cannot read r_debug")); @@ -154,7 +154,7 @@ E(find_maps) (const char *exe, int memfd, pid_t pid, void *auxv, else if (p[i].p_type == PT_INTERP) { interp = xmalloc (p[i].p_filesz); - if (pread (memfd, interp, p[i].p_filesz, offset + p[i].p_vaddr) + if (read_mem (memfd, interp, p[i].p_filesz, offset + p[i].p_vaddr) != p[i].p_filesz) error (EXIT_FAILURE, 0, gettext ("cannot read program interpreter")); } @@ -184,13 +184,13 @@ E(find_maps) (const char *exe, int memfd, pid_t pid, void *auxv, do { struct E(link_map) m; - if (pread (memfd, &m, sizeof (m), list) != sizeof (m)) + if (read_mem (memfd, &m, sizeof (m), list) != sizeof (m)) error (EXIT_FAILURE, 0, gettext ("cannot read link map")); EW(Addr) name_offset = m.l_name; while (1) { - ssize_t n = pread (memfd, tmpbuf.data, tmpbuf.length, name_offset); + ssize_t n = read_mem (memfd, tmpbuf.data, tmpbuf.length, name_offset); if (n == -1) error (EXIT_FAILURE, 0, gettext ("cannot read object name")); diff --git a/elf/pldd.c b/elf/pldd.c index 62e660c3f..d784c24d7 100644 --- a/elf/pldd.c +++ b/elf/pldd.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -268,6 +269,15 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ } +/* Read LEN bytes at ADDR from the target's MEMFD into BUF. */ +static ssize_t +read_mem (int memfd, void *buf, size_t len, uint64_t addr) +{ + if (lseek (memfd, addr, SEEK_SET) == (off_t) -1) + return -1; + return read (memfd, buf, len); +} + #define CLASS 32 #include "pldd-xx.c" #define CLASS 64