[GIT PULL 08/16 for v7.2] vfs openat2

From: Christian Brauner

Date: Fri Jun 12 2026 - 11:13:57 EST


Hey Linus,

/* Summary */

This contains the openat2 changes for this cycle:

Features

- Add O_EMPTYPATH to openat(2)/openat2(2). To get an operable file
descriptor from an O_PATH file descriptor it is possible to use
openat(fd, ".", O_DIRECTORY) for directories, but other file types
require going through open("/proc/<pid>/fd/<nr>") and thus depend on
a functioning procfs. With O_EMPTYPATH an empty path string is
accepted and LOOKUP_EMPTY is set at path resolution time, allowing
to reopen the file behind the file descriptor directly. Selftests
are included.

- Add an OPENAT2_REGULAR flag for openat2(2) which refuses to open
anything but regular files with the new EFTYPE error code. This
implements the "ability to only open regular files" feature
requested by userspace via uapi-group.org and protects services
from being redirected to fifos, device nodes, and friends.

All atomic_open implementations were audited for OPENAT2_REGULAR
handling. Explicit checks were added to ceph, gfs2, nfs (v4), and
cifs/smb - these are the filesystems whose atomic_open can encounter
an existing non-regular file and would otherwise call finish_open()
on it or return a misleading error code. The remaining
implementations (9p, fuse, vboxsf, nfs v2/v3) only call
finish_open() on freshly created files and use finish_no_open() for
lookup hits, letting the VFS catch non-regular files via the
do_open() safety net.

Cleanups

- Migrate the openat2 selftests to the kselftest harness and move
them under selftests/filesystems/. The tests were written in the
early days of selftests' TAP support and the modern kselftest
harness is much easier to follow and maintain. The contents of the
tests are unchanged and the new emptypath tests are ported on top.

- Make the LAST_XXX last-type constants private to fs/namei.c. The
only user outside of fs/namei.c was ksmbd which only needs to know
whether the last component is a regular one, so
vfs_path_parent_lookup() now performs the LAST_NORM check
internally. The ints are replaced with a dedicated enum last_type.

/* Testing */

gcc (Debian 14.2.0-19) 14.2.0
Debian clang version 19.1.7 (3+b1)

No build failures or warnings were observed.

/* Conflicts */

Merge conflicts with mainline
=============================

No known conflicts.

Merge conflicts with other trees
================================

The following changes since commit 254f49634ee16a731174d2ae34bc50bd5f45e731:

Linux 7.1-rc1 (2026-04-26 14:19:00 -0700)

are available in the Git repository at:

git@xxxxxxxxxxxxxxxxxxx:pub/scm/linux/kernel/git/vfs/vfs tags/vfs-7.2-rc1.openat2

for you to fetch changes up to 318643721de396012da102723f337f35ba7ec1e9:

vfs: replace ints with enum last_type for LAST_XXX (2026-05-29 09:47:02 +0200)

----------------------------------------------------------------
vfs-7.2-rc1.openat2

Please consider pulling these changes from the signed vfs-7.2-rc1.openat2 tag.

Thanks!
Christian

----------------------------------------------------------------
Aleksa Sarai (4):
selftests: move openat2 tests to selftests/filesystems/
selftests: openat2: move helpers to header
selftests: openat2: switch from custom ARRAY_LEN to ARRAY_SIZE
selftests: openat2: migrate to kselftest harness

Christian Brauner (4):
Merge patch series "selftests: openat2: migrate to kselftest harness"
Merge patch series "vfs: add O_EMPTYPATH to openat(2)/openat2(2)"
Merge patch series "OPENAT2_REGULAR flag support for openat2"
selftests: openat2: port emptypath_test to kselftest harness

Dorjoy Chowdhury (3):
openat2: introduce EFTYPE error code
openat2: new OPENAT2_REGULAR flag support
kselftest/openat2: test for OPENAT2_REGULAR flag

Jori Koolstra (4):
vfs: add O_EMPTYPATH to openat(2)/openat2(2)
selftest: add tests for O_EMPTYPATH
vfs: make LAST_XXX private to fs/namei.c
vfs: replace ints with enum last_type for LAST_XXX

arch/alpha/include/uapi/asm/errno.h | 2 +
arch/mips/include/uapi/asm/errno.h | 2 +
arch/parisc/include/uapi/asm/errno.h | 2 +
arch/sparc/include/uapi/asm/errno.h | 2 +
fs/ceph/file.c | 4 +
fs/fcntl.c | 4 +-
fs/gfs2/inode.c | 7 +
fs/namei.c | 48 ++-
fs/nfs/dir.c | 4 +
fs/open.c | 41 ++-
fs/smb/client/dir.c | 18 +-
fs/smb/server/vfs.c | 15 +-
include/linux/fcntl.h | 20 +-
include/linux/namei.h | 7 +-
include/uapi/asm-generic/errno.h | 2 +
include/uapi/asm-generic/fcntl.h | 4 +
include/uapi/linux/openat2.h | 7 +
tools/arch/alpha/include/uapi/asm/errno.h | 2 +
tools/arch/mips/include/uapi/asm/errno.h | 2 +
tools/arch/parisc/include/uapi/asm/errno.h | 2 +
tools/arch/sparc/include/uapi/asm/errno.h | 2 +
tools/include/uapi/asm-generic/errno.h | 2 +
tools/include/uapi/linux/openat2.h | 43 +++
.../selftests/{ => filesystems}/openat2/.gitignore | 0
.../selftests/{ => filesystems}/openat2/Makefile | 9 +-
.../selftests/filesystems/openat2/emptypath_test.c | 77 +++++
.../selftests/filesystems/openat2/helpers.h | 135 ++++++++
.../{ => filesystems}/openat2/openat2_test.c | 262 ++++++++-------
.../filesystems/openat2/rename_attack_test.c | 159 +++++++++
.../{ => filesystems}/openat2/resolve_test.c | 368 ++++++++++++---------
tools/testing/selftests/openat2/helpers.c | 109 ------
tools/testing/selftests/openat2/helpers.h | 108 ------
.../testing/selftests/openat2/rename_attack_test.c | 160 ---------
33 files changed, 920 insertions(+), 709 deletions(-)
create mode 100644 tools/include/uapi/linux/openat2.h
rename tools/testing/selftests/{ => filesystems}/openat2/.gitignore (100%)
rename tools/testing/selftests/{ => filesystems}/openat2/Makefile (65%)
create mode 100644 tools/testing/selftests/filesystems/openat2/emptypath_test.c
create mode 100644 tools/testing/selftests/filesystems/openat2/helpers.h
rename tools/testing/selftests/{ => filesystems}/openat2/openat2_test.c (63%)
create mode 100644 tools/testing/selftests/filesystems/openat2/rename_attack_test.c
rename tools/testing/selftests/{ => filesystems}/openat2/resolve_test.c (74%)
delete mode 100644 tools/testing/selftests/openat2/helpers.c
delete mode 100644 tools/testing/selftests/openat2/helpers.h
delete mode 100644 tools/testing/selftests/openat2/rename_attack_test.c