From 7c27e260f04e6083bdcfdfb3d123db844b3865c1 Mon Sep 17 00:00:00 2001 From: jhb Date: Fri, 2 Mar 2012 18:55:19 +0000 Subject: [PATCH 164/175] Similar to the fixes in 226967 and 226987, purge any name cache entries associated with the previous vnode (if any) associated with the target of a rename(). Otherwise, a lookup of the target pathname concurrent with a rename() could re-add a name cache entry after the namei(RENAME) lookup in kern_renameat() had purged the target pathname. MFC after: 2 weeks git-svn-id: http://svn.freebsd.org/base/head@232401 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f (cherry picked from commit 03a3862792b4b96ce260b7fdc36b531bffe752aa) Signed-off-by: Xin Li --- sys/fs/tmpfs/tmpfs_vnops.c | 2 ++ sys/ufs/ufs/ufs_vnops.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index 93fea8b..d5cae29 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -1135,6 +1135,8 @@ tmpfs_rename(struct vop_rename_args *v) tmpfs_free_dirent(VFS_TO_TMPFS(tvp->v_mount), de, TRUE); } cache_purge(fvp); + if (tvp != NULL) + cache_purge(tvp); error = 0; diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c index ab33ef3..02ee1e0 100644 --- a/sys/ufs/ufs/ufs_vnops.c +++ b/sys/ufs/ufs/ufs_vnops.c @@ -1534,8 +1534,15 @@ relock: * ufs_lookup_ino() and then VFS_VGET(), another thread might do a * normal lookup of the from name just before the VFS_VGET() call, * causing the cache entry to be re-instantiated. + * + * The same issue also applies to tvp if it exists as + * otherwise we may have a stale name cache entry for the new + * name that references the old i-node if it has other links + * or open file descriptors. */ cache_purge(fvp); + if (tvp) + cache_purge(tvp); unlockout: vput(fdvp); -- 1.7.9.4