HomeFreeBSD

filedesc: Close race between fcntl(F_SETFL) and ioctl(FIONBIO/FIOASYNC)

Description

filedesc: Close race between fcntl(F_SETFL) and ioctl(FIONBIO/FIOASYNC)

  • Use the recently-added fsetfl_lock/unlock API to synchronize direct FIONBIO and FIOASYNC ioctls with fcntl(F_SETFL).
  • While here, skip calling the underlying ioctl if the flag's current state matches the requested state.
  • Also while here, only update the flag state if the underlying ioctl succeeds. This fixes a bug where the flags represented the new state even if the underlying ioctl failed. A test is added for this last case that a failing FIOASYNC on /dev/null doesn't result in setting O_ASYNC in the file flags.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D52721

Details

Provenance
jhbAuthored on Oct 3 2025, 4:43 PM
Reviewer
kib
Differential Revision
D52721: filedesc: Close race between fcntl(F_SETFL) and ioctl(FIONIO/FIOASYNC)
Parents
rG5c331f449e9c: fcntlflags_test: Port to atf-c(3)
Branches
Unknown
Tags
Unknown