[newlib-cygwin/main] cygwin: pread/pwrite: prevent EBADF error after fork()

Corinna Vinschen corinna@sourceware.org
Wed Oct 23 10:00:20 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bdd06f82a186a509256d1b3c2dd9282f4c96553f

commit bdd06f82a186a509256d1b3c2dd9282f4c96553f
Author:     Christian Franke <christian.franke@t-online.de>
AuthorDate: Wed Oct 23 11:44:34 2024 +0200
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Oct 23 11:56:59 2024 +0200

    cygwin: pread/pwrite: prevent EBADF error after fork()
    
    If the parent process has already used pread() or pwrite(), these
    functions fail with EBADF if used on the inherited fd.  Ensure that
    fix_after_fork() is called to invalidate the prw_handle.  This issue
    has been detected by 'stress-ng --pseek 1'.
    
    Fixes: c36cd56c548a ("* fhandler.cc (fhandler_base::open): Drop local create_options variable.")
    Signed-off-by: Christian Franke <christian.franke@t-online.de>

Diff:
---
 winsup/cygwin/fhandler/disk_file.cc | 3 +++
 winsup/cygwin/release/3.5.5         | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/disk_file.cc
index f4c21d3b7f82..2008fb61ba62 100644
--- a/winsup/cygwin/fhandler/disk_file.cc
+++ b/winsup/cygwin/fhandler/disk_file.cc
@@ -1803,6 +1803,9 @@ fhandler_disk_file::prw_open (bool write, void *aio)
       return -1;
     }
 
+  /* prw_handle is invalid after fork. */
+  need_fork_fixup (true);
+
   /* record prw_handle's asyncness for subsequent pread/pwrite operations */
   prw_handle_isasync = !!aio;
   return 0;
diff --git a/winsup/cygwin/release/3.5.5 b/winsup/cygwin/release/3.5.5
index 904119a3877a..d01f31c603b0 100644
--- a/winsup/cygwin/release/3.5.5
+++ b/winsup/cygwin/release/3.5.5
@@ -7,3 +7,6 @@ Fixes:
 
 - Fix a regression in 3.5.4 that writing to pipe extremely slows down.
   Addresses: https://cygwin.com/pipermail/cygwin/2024-August/256398.html
+
+- Fix pread() and pwrite() EBADF error after fork().
+  Addresses: https://sourceware.org/pipermail/cygwin/2024-September/256468.html


More information about the Cygwin-cvs mailing list