Skip to content



dup - duplicate an existing file descriptor


The dup() system call creates a duplicate of the file descriptor oldfd. It returns the new glass reference to the same open file description and shares the same file offset and file status flags as the original file descriptor. This system call allows the programmer to use the file descriptor multiple times in the same process.

The dup() system call has several advantages, compared to other system calls such as open() and dup2(). It does not require the user to specify a pathname, since it operates on existing file descriptors. Furthermore, it does not perform a separate open() operation and all of the related system call overhead. Finally, dup() properly handles the underlying open file description reference count.

There are two edge-cases to be aware of when using the dup() system call. First, the oldfd argument must refer to an open file descriptor in order for the operation to succeed. If the oldfd argument does not refer to an open file descriptor, the system call will return an error. Second, a file descriptor created with the dup() function should also be closed with close() and not with a call to free().


  • oldfd:int[K] - file descriptor of an open file description.

Available Tags

  • K - Originated from kernel-space.




kretprobe + kprobe


The syscall_entry_dup function is hooked in order to intercept the dup() system call and record its associated arguments.

Example Use Case

The dup() system call can be used to create multiple pointers to the same open file description. This is useful for applications that need to read from the same file from multiple places at the same time. For example, an antivirus program may need to read several chunks of a file in order to scan it for viruses.


The dup() system call can be vulnerable to TOCTOU (time of check, time of use) attacks, as the open file description of the oldfd argument may have been modified between the time of the check and the time of use.

  • open() - open a file descriptor
  • close() - close a file descriptor
  • dup2() - clone existing file descriptor with a given new descriptor

This document was automatically generated by OpenAI and needs review. It might not be accurate and might contain errors. The authors of Tracee recommend that the user reads the "events.go" source file to understand the events and their arguments better.