Skip to content

Commit

Permalink
cygwin: pread/pwrite: prevent EBADF error after fork()
Browse files Browse the repository at this point in the history
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: c36cd56 ("* fhandler.cc (fhandler_base::open): Drop local create_options variable.")
Signed-off-by: Christian Franke <[email protected]>
  • Loading branch information
chrfranke authored and github-cygwin committed Oct 23, 2024
1 parent 1b7c72f commit bdd06f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions winsup/cygwin/fhandler/disk_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions winsup/cygwin/release/3.5.5
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bdd06f8

Please sign in to comment.