From 38800907ccca38ea45e6e3fdb102b3a351263dbf Mon Sep 17 00:00:00 2001 From: Albab Hasan <155961300+Albab-Hasan@users.noreply.github.com> Date: Wed, 11 Feb 2026 14:32:39 +0600 Subject: [PATCH] gpui: Fix double-close of fd in read_fd on linux (#48850) `read_fd` calls `File::from_raw_fd(fd.as_raw_fd())`, which creates a new `File` that assumes ownership of the raw fd, while the original `FileDescriptor` also retains ownership. when both drop at the end of the function, the same fd is closed twice. between the two closes another thread can receive that fd number from the kernel for an unrelated file/socket, and the second close silently kills it. this can cause hard to diagnose data corruption or i/o failures. fix: use `fd.into_raw_fd()` instead of `fd.as_raw_fd()` to transfer ownership to the `File` without running `FileDescriptor`'s drop. Release Notes: - N/A --- crates/gpui/src/platform/linux/platform.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index 5f328cd928073764a39db34400279949c608a368..4ed42608d73b7a875857d01687a4fd095eceb098 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -9,7 +9,7 @@ use std::{ ffi::OsString, fs::File, io::Read as _, - os::fd::{AsFd, AsRawFd, FromRawFd}, + os::fd::{AsFd, FromRawFd, IntoRawFd}, time::Duration, }; @@ -737,8 +737,8 @@ pub(super) fn get_xkb_compose_state(cx: &xkb::Context) -> Option Result> { - let mut file = unsafe { File::from_raw_fd(fd.as_raw_fd()) }; +pub(super) unsafe fn read_fd(fd: filedescriptor::FileDescriptor) -> Result> { + let mut file = unsafe { File::from_raw_fd(fd.into_raw_fd()) }; let mut buffer = Vec::new(); file.read_to_end(&mut buffer)?; Ok(buffer)