[PATCH 0/3] fs: return ERR_PTR() from iget_locked() and friends

From: Konstantin Adzer

Date: Tue Dec 01 2026 - 08:36:16 EST


iget_locked(), iget5_locked(), iget5_locked_rcu() and inode_insert5()
return NULL for a failed allocation and also for an inode under
creation, which find_inode() and find_inode_fast() report as -ESTALE.
Callers read NULL as -ENOMEM. As reported in [1], open_by_handle_at() on
ext4 then fails with ENOMEM, and nfsd returns a jukebox/DELAY error, for
the handle of a deleted inode whose number is being reused. Following
the discussion in [2], this series makes the helpers return ERR_PTR().

Patches 1 and 2 make fuse_iget() and hfs_iget() return ERR_PTR(), so
that patch 3 can convert the four helpers and all their callers at once.

Testing:
- The reproducer below, in virtme-ng (x86_64 defconfig, 4 CPUs, ext4 on
a loop device, 10 seconds): one process creates and unlinks a file in
a loop, the other calls open_by_handle_at() with the handle of an
earlier, deleted file of that name.
vfs.all at 84fb6f8a1ba9: ESTALE 2312698 ENOMEM 637252
with this series: ESTALE 3394396 ENOMEM 0
dmesg has no messages from the test in either run.
- allmodconfig x86_64 builds of every directory the series touches, with
all three patches and with patches 1-2 only; ARCH=um for hostfs;
sparc64 for openpromfs. No new warnings. checkpatch --strict reports
no errors.
- Not done: run-time tests of filesystems other than ext4 and of the
changed error paths in the callers.

The series was written with Claude Code (claude-opus-5-5). I asked it to
find out why open_by_handle_at() returns ENOMEM to our file scanner and
to fix the cause in the kernel. It traced the error to iget_locked(),
wrote the reproducer, the patches, their changelogs and this letter, and
ran the builds and the tests above.

[1] https://lore.kernel.org/179612584364.3457081.15142720814992093613@xxxxxxxxxxxxxx
[2] https://lore.kernel.org/all/20261201-advent-fahrkarte-zierlich-b5b73df9e312@brauner/

Reproducer, run as root: ./iget-repro <empty directory on ext4> <seconds>

#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

int main(int argc, char **argv)
{
long estale = 0, enomem = 0, other = 0, opened = 0;
struct file_handle *fh;
int mount_id, mfd, fd;
time_t end;
pid_t pid;

if (argc != 3) {
fprintf(stderr, "usage: %s DIR SECONDS\n", argv[0]);
return 2;
}
if (chdir(argv[1]))
return perror("chdir"), 1;

fh = malloc(sizeof(*fh) + MAX_HANDLE_SZ);
fh->handle_bytes = MAX_HANDLE_SZ;
fd = open("f", O_CREAT | O_EXCL | O_WRONLY, 0600);
if (fd < 0 || name_to_handle_at(AT_FDCWD, "f", fh, &mount_id, 0))
return perror("name_to_handle_at"), 1;
close(fd);
unlink("f");

mfd = open(".", O_RDONLY | O_DIRECTORY);
pid = fork();
if (!pid) {
for (;;) {
fd = open("f", O_CREAT | O_EXCL | O_WRONLY, 0600);
if (fd >= 0)
close(fd);
unlink("f");
}
}

end = time(NULL) + atoi(argv[2]);
while (time(NULL) < end) {
fd = open_by_handle_at(mfd, fh, O_RDONLY);
if (fd >= 0) {
opened++;
close(fd);
} else if (errno == ESTALE) {
estale++;
} else if (errno == ENOMEM) {
enomem++;
} else {
other++;
}
}
kill(pid, SIGKILL);
waitpid(pid, NULL, 0);
printf("ESTALE %ld ENOMEM %ld other %ld opened %ld\n",
estale, enomem, other, opened);
return enomem != 0;
}

Konstantin Adzer (3):
fuse: return ERR_PTR() from fuse_iget()
hfs: return ERR_PTR() from hfs_iget()
fs: return ERR_PTR() from iget_locked() and friends

Documentation/filesystems/porting.rst | 9 ++
drivers/dax/super.c | 8 +-
fs/9p/vfs_inode.c | 4 +-
fs/9p/vfs_inode_dotl.c | 4 +-
fs/affs/inode.c | 4 +-
fs/afs/dynroot.c | 14 +--
fs/afs/inode.c | 12 +--
fs/befs/linuxvfs.c | 4 +-
fs/btrfs/inode.c | 12 +--
fs/ceph/inode.c | 4 +-
fs/coda/cnode.c | 4 +-
fs/cramfs/inode.c | 4 +-
fs/ecryptfs/inode.c | 4 +-
fs/erofs/inode.c | 4 +-
fs/erofs/ishare.c | 6 +-
fs/ext2/inode.c | 4 +-
fs/ext4/inode.c | 4 +-
fs/f2fs/inode.c | 4 +-
fs/fuse/dir.c | 13 +--
fs/fuse/inode.c | 16 ++--
fs/fuse/readdir.c | 4 +-
fs/gfs2/inode.c | 4 +-
fs/hfs/btree.c | 2 +-
fs/hfs/dir.c | 2 -
fs/hfs/inode.c | 8 +-
fs/hfs/super.c | 4 +-
fs/hfsplus/super.c | 4 +-
fs/hostfs/hostfs_kern.c | 4 +-
fs/hpfs/dir.c | 3 +-
fs/hpfs/inode.c | 2 +-
fs/hpfs/super.c | 2 +-
fs/inode.c | 126 +++++++++++++++-----------
fs/isofs/inode.c | 4 +-
fs/jffs2/fs.c | 4 +-
fs/jfs/inode.c | 4 +-
fs/kernfs/inode.c | 8 +-
fs/kernfs/mount.c | 4 +-
fs/minix/inode.c | 4 +-
fs/nfs/inode.c | 4 +-
fs/nilfs2/cpfile.c | 4 +-
fs/nilfs2/dat.c | 4 +-
fs/nilfs2/ifile.c | 4 +-
fs/nilfs2/inode.c | 16 ++--
fs/nilfs2/sufile.c | 4 +-
fs/ntfs/inode.c | 12 +--
fs/ntfs3/inode.c | 4 +-
fs/ocfs2/inode.c | 3 +-
fs/openpromfs/inode.c | 5 +-
fs/orangefs/inode.c | 4 +-
fs/overlayfs/inode.c | 10 +-
fs/qnx4/inode.c | 4 +-
fs/qnx6/inode.c | 4 +-
fs/romfs/super.c | 4 +-
fs/smb/client/file.c | 5 +-
fs/smb/client/inode.c | 12 ++-
fs/smb/client/readdir.c | 2 -
fs/squashfs/inode.c | 4 +-
fs/ubifs/super.c | 4 +-
fs/udf/inode.c | 4 +-
fs/ufs/inode.c | 4 +-
fs/vboxsf/super.c | 4 +-
fs/zonefs/super.c | 8 +-
include/linux/kernfs.h | 2 +-
kernel/cgroup/cgroup.c | 4 +-
64 files changed, 251 insertions(+), 219 deletions(-)


base-commit: 84fb6f8a1ba91eee3ffe6aa519686fce851a0e42
--
2.56.1