Linux 7.2 will introduce the OPENAT2_REGULAR flag for the openat2 system call, preventing secure programs from being tricked into opening device files with special semantics when expecting regular files.
Among the Virtual File System (VFS) patches queued for the upcoming Linux 7.2 merge window is the implementation of the OPENAT2_REGULAR flag for the openat2 system call. This seemingly minor addition represents a significant security enhancement that addresses a long-standing vulnerability in how applications handle file operations.
Understanding OPENAT2_REGULAR
The OPENAT2_REGULAR flag ensures that when a program attempts to open a file, the operation will only succeed if the target is a regular file. If the path points to a device file, FIFO, socket, or other non-regular file type, the system call returns an EFTYPE error instead of proceeding with the potentially dangerous operation.
The patch description explains the functionality clearly:
"This flag indicates the path should be opened if it's a regular file. This is useful to write secure programs that want to avoid being tricked into opening device nodes with special semantics while thinking they operate on regular files. This is a requested feature from the uapi-group. The previously introduced EFTYPE error code is returned when the path doesn't refer to a regular file. For example, if openat2 is called on path /dev/null with OPENAT2_REGULAR in the flag param, it will return -EFTYPE."
Security Implications
This flag addresses a critical security concern where applications can be tricked into accessing unintended files through symlink attacks or malicious file paths. Device files often have special semantics that can lead to unexpected behavior or security vulnerabilities.
Consider a naive web browser implementation that's pointed to file://dev/zero. Without proper safeguards, the browser would attempt to read from /dev/zero, which provides an endless stream of null bytes. This could lead to:
- Resource exhaustion as the application tries to read infinite data
- Buffer overflows if not properly handled
- Denial of service conditions
The UAPI Group specifically highlighted this use case in their request for the kernel feature:
"Use-Case: this would be very useful to write secure programs that want to avoid being tricked into opening device nodes with special semantics while thinking they operate on regular files. This is particularly relevant as many device nodes (or even FIFOs) come with blocking I/O (or even blocking open()!) by default, which is not expected from regular files backed by 'fast' disk I/O."
Technical Implementation Details
The implementation includes several important behaviors:
When OPENAT2_REGULAR is used with O_CREAT, a regular file is created if it doesn't exist. If the path already exists, it's only opened if it's a regular file; otherwise, EFTYPE is returned.
When OPENAT2_REGULAR is combined with O_DIRECTORY, the system returns -EINVAL since a path cannot be both a directory and a regular file.
The flag works specifically with the openat2 system call, which was introduced in Linux 5.6 as an improved version of openat with additional features and security enhancements.
Why Now?
While the concept seems straightforward, it's somewhat surprising that such a fundamental security feature wasn't implemented earlier. The delay likely reflects the careful consideration needed for backward compatibility and the thorough review process for new kernel APIs.
The timing coincides with increasing focus on security in Linux system calls and the growing sophistication of attack vectors targeting file operations. As applications become more complex and the attack surface expands, having explicit mechanisms to enforce expected file types becomes increasingly valuable.
Integration with Linux 7.2
The patch has been queued into the "vfs-7.2.openat.regular" Git branch and is expected to be submitted for the Linux 7.2 merge window in mid-June. This places it alongside other VFS improvements targeting security and performance.
Developers looking to implement this feature in their applications should prepare for the following:
- Updating to Linux 7.2 or later kernels
- Modifying file opening code to include OPENAT2_REGULAR when only regular files are acceptable
- Handling the EFTYPE error code appropriately in application logic
Broader Impact
The introduction of OPENAT2_REGULAR represents a shift toward more explicit security controls in Linux system calls. Rather than relying on application developers to carefully validate file paths and types, the kernel now provides a direct mechanism to enforce these constraints.
This approach aligns with the principle of secure by design, where security considerations are built into fundamental system operations rather than bolted on as afterthoughts. As Linux continues to evolve, we can expect more such enhancements that make secure programming easier and more accessible.
For developers working on security-sensitive applications, particularly those handling untrusted file paths, this feature will simplify secure coding practices and reduce the likelihood of file descriptor-related vulnerabilities.

The Linux community has long recognized the importance of secure file operations, and OPENAT2_REGULAR is a significant step forward in this area. As we approach the Linux 7.2 release cycle, this enhancement promises to make Linux applications more resistant to file descriptor tricks and path manipulation attacks.
For those interested in following the development, the patch is available in the Linux kernel's VFS development tree, and the implementation details can be examined in the "vfs-7.2.openat.regular" branch. The feature is expected to be finalized and merged during the upcoming merge window, making it available in the Linux 7.2 release later this year.

Comments
Please log in or register to join the discussion