file-descriptor · shipping · also file descriptor number

File descriptor

A file descriptor is a nonnegative integer used by a process to refer to an open file description for operations such as reading, writing or closing.

Related Observatory article: Read on hesela.com

A descriptor number is a process-local reference, not a persistent identifier for a pathname or inode. Separate opens can create different open file descriptions for the same file; dup creates another reference to the existing description. [1] [2]

Duplicated descriptors share the file offset and status flags, but not descriptor flags such as close-on-exec. Closing one alias does not close the other. After release, the same number can identify a different file, so a saved integer alone does not prove ownership of the current descriptor. [2] [3]

On Linux, a successful dup2 with distinct source and target numbers replaces the target atomically; separate close then dup leaves an allocation race. Successful replacement clears the target FD_CLOEXEC flag while leaving the source descriptor flag unchanged. A valid dup2(fd, fd) instead does nothing, preserving descriptor flags. An invalid source fails without closing the target. Atomic replacement is not durable storage, and dup2 does not report implicit target-close errors. [2]

Retained access: in a separate same-owner Linux 6.8 experiment on ext4 and tmpfs, chmod 000 denied fresh opens but retained read/write descriptors and a duplicate created after the change still accessed the file. Closing one descriptor did not revoke the duplicate or a surviving mapping. This is one-host visibility evidence, not crash durability, named-user ACL selection or a universal revocation rule. [6] NFS and additional security-policy checks require separate treatment. [5]

Relations

related
pread, File offset, Open file description, close, Inode, pwrite, Close-on-exec

Limitations

  • Descriptor numbers can be reused after release.
  • Sharing a descriptor or open file description does not provide a durable-commit guarantee.

Citations

  1. Linux man-pages 6.19: open(2), descriptors and open file descriptions (accessed 2026-10-17)
  2. Linux man-pages 6.19: dup(2), shared state and atomic replacement (accessed 2026-10-17)
  3. POSIX.1-2024: close(), descriptor deallocation (accessed 2026-10-17)
  4. Linux man-pages: chmod(2), NFS qualification (accessed 2026-11-05)
  5. Hesela: retained local access after permission changes, native evidence and limits (accessed 2026-11-05)
  6. Hesela: permission-lifetime native observations, source receipts and MIT replay bundle (accessed 2026-11-05)

Further reading

  1. Hesela: Reproduce descriptor lifetime without injecting a storage fault (accessed 2026-10-17)
Sources & caveats
  • Permission-lifetime evidence: nine scenarios, 108 recorded executions and 108 matching replay records; two compiler configurations, three repetitions per mount and one host, not independent fleet samples. No changed LSM policy, concurrent writer or power-loss experiment. [7]
  • Inheritance: raw Linux dup clears close-on-exec on its new descriptor; dup3 with O_CLOEXEC sets it on a distinct target. Prefer creation-time O_CLOEXEC when another thread could fork and exec before a later fcntl sets FD_CLOEXEC. [2] [1]

JSON: /data/terms/file-descriptor.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. File descriptor. Hesela. 2026-11-05. https://hesela.dev/terms/file-descriptor/