Bug 295826 - kern_renameat() infinite loop
Summary: kern_renameat() infinite loop
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: Konstantin Belousov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-06-03 18:51 UTC by Ivan Rozhuk
Modified: 2026-07-18 19:03 UTC (History)
3 users (show)

See Also:
linimon: mfc-stable14?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Rozhuk 2026-06-03 18:51:17 UTC
Target /usr/local/www dir was subject of multiple nullfs mount points.

Looks like namei() got ERELOOKUP every time and can not exit loop.
Probably some simple loop counter with some limit should fix this problem.

# procstat kstack 80837
  PID    TID COMM                TDNAME              KSTACK                       
80837 487501 pkg-static          -                   kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   ufs_delete_denied ufs_lookup_ino vfs_cache_lookup cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   namei_setup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   __lockmgr_args getblkx breadn_flags ffs_blkatoff ufs_lookup_ino vfs_cache_lookup vfs_lookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vput cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   ufs_need_inactive vput_final kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vgonel vrecycle null_inactive vinactivef vput_final kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   breadn_flags ffs_blkatoff ufs_lookup_ino vfs_cache_lookup vfs_lookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   ufs_need_inactive vput_final vfs_lookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vget_finish cache_lookup vfs_cache_lookup vfs_lookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vget_finish cache_lookup vfs_cache_lookup vfs_lookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   fgetvp_lookup namei_setup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vget nullfs_root vfs_lookup_cross_mount vfs_lookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   ufs_lookup_ino vfs_cache_lookup cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   ufs_accessx vop_stdaccess vn_dir_check_exec vfs_cache_lookup cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vfs_lookup_cross_mount vfs_lookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   fgetvp_lookup namei_setup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vop_stdaccess ufs_delete_denied ufs_lookup_ino vfs_cache_lookup cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   getblkx breadn_flags ffs_blkatoff ufs_lookup_ino vfs_cache_lookup cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vfs_cache_lookup cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   cache_fplookup_dirfd cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vfs_lookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vput_final kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vfs_cache_lookup cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   ffs_lock _vn_lock vget_finish cache_lookup vfs_cache_lookup vfs_lookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
80837 487501 pkg-static          -                   vn_dir_check_exec vfs_cache_lookup cache_fplookup_final_modifying cache_fplookup namei kern_renameat sys_renameat amd64_syscall fast_syscall_common 
...
Comment 1 Ivan Rozhuk 2026-06-03 18:55:53 UTC
# mount | grep www
/mnt/10T20240705/Data/usr/local/www/rtorrent/share on /usr/local/www/rutorrent/share (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/dokuwiki/conf on /usr/local/www/dokuwiki/conf (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/dokuwiki/data on /usr/local/www/dokuwiki/data (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/nextcloud/apps on /usr/local/www/nextcloud/apps (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/nextcloud/config on /usr/local/www/nextcloud/config (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/nextcloud/.user.ini on /usr/local/www/nextcloud/.user.ini (nullfs, local, noatime, noexec, nosuid)
/mnt/backup/nextcloud/data on /usr/local/www/nextcloud/data (nullfs, local, noatime, noexec, nosuid)
/usr/local/www/dokuwiki on /var/run/chroot-php-dokuwiki/usr/local/www/wiki (nullfs, local, noatime, noexec, nosuid, read-only)
/var/db/chroots/dokuwiki/conf on /var/run/chroot-php-dokuwiki/usr/local/www/wiki/conf (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/dokuwiki/data on /var/run/chroot-php-dokuwiki/usr/local/www/wiki/data (nullfs, local, noatime, noexec, nosuid)
/usr/local/www/nextcloud on /var/run/chroot-php-nextcloud/usr/local/www/nextcloud (nullfs, local, noatime, noexec, nosuid, read-only)
/var/db/chroots/nextcloud/apps on /var/run/chroot-php-nextcloud/usr/local/www/nextcloud/apps (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/nextcloud/config on /var/run/chroot-php-nextcloud/usr/local/www/nextcloud/config (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/nextcloud/.user.ini on /var/run/chroot-php-nextcloud/usr/local/www/nextcloud/.user.ini (nullfs, local, noatime, noexec, nosuid)
/mnt/backup/nextcloud/data on /var/run/chroot-php-nextcloud/usr/local/www/nextcloud/data (nullfs, local, noatime, noexec, nosuid)
Comment 2 Konstantin Belousov freebsd_committer freebsd_triage 2026-06-04 17:42:44 UTC
What is the filesystem type below nullfs mounts?
Comment 3 Konstantin Belousov freebsd_committer freebsd_triage 2026-06-04 17:54:39 UTC
Another question, how did you know that it is ERELOOKUP loop?
BTW, is the renaming process killable?

The simplest experiment is to apply the following patch and see if the process
doing rename becomes killable by a signal:

commit 86239c7761813ee7d70972292cb69cfff35fa9e4
Author: Konstantin Belousov <kib@FreeBSD.org>
Date:   Thu Jun 4 20:53:26 2026 +0300

    renameat(2): when retrying with ERELOOKUP, check for pending signals
    
    PR:     295826

diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 0c4eeb584d41..0407e8831cff 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -3937,8 +3937,11 @@ kern_renameat(struct thread *td, int oldfd, const char *old, int newfd,
 out1:
 	if (error == ERESTART)
 		return (0);
-	if (error == ERELOOKUP)
-		goto again;
+	if (error == ERELOOKUP) {
+		error = sig_intr();
+		if (error == 0)
+			goto again;
+	}
 	return (error);
 }
Comment 4 Ivan Rozhuk 2026-06-04 18:50:18 UTC
> What is the filesystem type below nullfs mounts?

UFS2.

> Another question, how did you know that it is ERELOOKUP loop?

It is my guess.

> BTW, is the renaming process killable?

No, that was main problem.


As far I understand it hang on .user.ini file, after I unmount them it exit loop.
Comment 5 Ivan Rozhuk 2026-06-04 18:53:11 UTC
/var/db/chroots/nextcloud/apps on /usr/local/www/nextcloud/apps (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/nextcloud/config on /usr/local/www/nextcloud/config (nullfs, local, noatime, noexec, nosuid)
/var/db/chroots/nextcloud/.user.ini on /usr/local/www/nextcloud/.user.ini (nullfs, local, noatime, noexec, nosuid)
/mnt/backup/nextcloud/data on /usr/local/www/nextcloud/data (nullfs, local, noatime, noexec, nosuid)

is UFS2, same FS.

and pkg work with files on tmpfs.
Comment 6 Konstantin Belousov freebsd_committer freebsd_triage 2026-06-04 18:59:42 UTC
(In reply to Ivan Rozhuk from comment #5)
You are trying to rename the file with a nullfs mounted on?

I am even more curious if the patch above makes your case interruptible.
Comment 7 Ivan Rozhuk 2026-06-04 19:09:02 UTC
Here is sample reproducible test:

cd /root
mkdir -p /root/test_loop/a
mkdir -p /root/test_loop/b
echo '123' > /root/test_loop/b/file
touch /root/test_loop/a/file
mount_nullfs -o rw -o nocache -o noatime -o noexec -o nosuid /root/test_loop/b/file /root/test_loop/a/file
echo '123' > /tmp/file
mv /tmp/file /root/test_loop/a/file


/root - is UFS2
/tmp - is tmpfs
Comment 8 Konstantin Belousov freebsd_committer freebsd_triage 2026-06-04 19:21:21 UTC
peter, could you please try to reproduce this?
Comment 9 Konstantin Belousov freebsd_committer freebsd_triage 2026-06-04 20:03:52 UTC
(In reply to Konstantin Belousov from comment #8)
https://reviews.freebsd.org/D57453 should be the fix
Comment 10 Ivan Rozhuk 2026-06-04 20:23:04 UTC
After patch apply:
# mv /tmp/file /root/test_loop/a/file
mv: rename /tmp/file to /root/test_loop/a/file: Device busy
Comment 11 commit-hook freebsd_committer freebsd_triage 2026-06-06 03:29:41 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d53633bfcf24a3eb3711e24b597aa8301f92b958

commit d53633bfcf24a3eb3711e24b597aa8301f92b958
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-06-04 19:56:36 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-06-06 03:28:28 +0000

    rename(2): do not allow to rename root vnode of the mounted filesystem

    Check for tdvp being vp_crossmp.  This cannot happen for the normal
    rename cases, but could if the target path specified by the syscall
    points to the nullfs mount over the regular file.  In this case namei()
    cannot step over crossmp, and keep it in ni_dvp.

    Since crossmp VOP_GETWRITEMOUNT() returns NULL mp, we retry the locking
    dance since the belief is that NULL return is transient.

    PR:     295826
    Reviewed by:    markj
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D57453

 sys/kern/vfs_lookup.c   | 2 +-
 sys/kern/vfs_syscalls.c | 9 +++++++++
 sys/sys/vnode.h         | 1 +
 3 files changed, 11 insertions(+), 1 deletion(-)
Comment 12 commit-hook freebsd_committer freebsd_triage 2026-06-06 03:29:42 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5d0ebfe1d97801518755c7025f57ba7d5bf1c8db

commit 5d0ebfe1d97801518755c7025f57ba7d5bf1c8db
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-06-04 17:53:26 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-06-06 03:28:28 +0000

    renameat(2): when retrying, check for pending signals

    The vn_start_write() call there is already interruptible.  Check for
    user signals before restarting due to ERELOOKUP, or after failed
    vn_start_write().  Note that vn_start_write(V_XSLEEP | V_PCATCH)
    does not check for signals if not sleeping.

    PR:     295826
    Reviewed by:    markj
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D57453

 sys/kern/vfs_syscalls.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Comment 13 commit-hook freebsd_committer freebsd_triage 2026-06-13 01:04:41 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f9a216c4fcc1766798e93e376bc4e23ea99e9ddf

commit f9a216c4fcc1766798e93e376bc4e23ea99e9ddf
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-06-04 17:53:26 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-06-13 00:58:34 +0000

    renameat(2): when retrying, check for pending signals

    PR:     295826

    (cherry picked from commit 5d0ebfe1d97801518755c7025f57ba7d5bf1c8db)

 sys/kern/vfs_syscalls.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Comment 14 commit-hook freebsd_committer freebsd_triage 2026-06-13 01:04:45 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f8fc6a086e559855243ef3d2ffda35e1ae0e7d71

commit f8fc6a086e559855243ef3d2ffda35e1ae0e7d71
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-06-04 19:56:36 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-06-13 00:58:34 +0000

    rename(2): do not allow to rename root vnode of the mounted filesystem

    PR:     295826

    (cherry picked from commit d53633bfcf24a3eb3711e24b597aa8301f92b958)

 sys/kern/vfs_lookup.c   | 2 +-
 sys/kern/vfs_syscalls.c | 9 +++++++++
 sys/sys/vnode.h         | 1 +
 3 files changed, 11 insertions(+), 1 deletion(-)