From a1aa1658ec2c24b16cdaedec87e5f04884eee5bd Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sat, 21 Mar 2026 20:56:59 +0100 Subject: [PATCH] LinuxSyscalls: Re-open file descriptors for parsing ELF headers File descriptors returned by dup() share state with the original FD, so we need to use open() to create a fully independent object. Fixes #5379 --- .../LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp index ad99ccabb..b1c516a6a 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp @@ -219,8 +219,12 @@ static ReadELFHeadersResult ReadELFHeaders(int FD, std::span HeaderDa // Read from FD in case the caller didn't have a mapped header available } + // Re-open the file with a fresh file descriptor (and let ELFParser close it on return). + // NOTE: FDs returned by dup() share the same cursor state, so reading from them would have observable side effects. + auto NewFD = open(fextl::fmt::format("/proc/self/fd/{}", FD).c_str(), O_RDONLY); + ELFParser Parser; - Parser.ReadElf(dup(FD)); + Parser.ReadElf(NewFD); auto Relocations = Parser.PopulateRelocations(); if (!Relocations.empty()) {