[PATCH 6/9] fs: symlink: drop references taken by filename_create()

Sascha Hauer s.hauer at pengutronix.de
Tue Oct 20 00:09:31 PDT 2026


symlink() never releases the dentry and the parent path returned by
filename_create(). The leaked vfsmount reference keeps the filesystem
busy, so it can't be unmounted once a symlink has been created on it:

  mount -t ramfs none /m
  ln -s x /m/l
  umount /m         -> Device or resource busy

Release both references like mkdirat() and mknodat() do. Also pin the
new dentry in ramfs_symlink() like ramfs_mknod() does, so that symlink
dentries end up with the same reference count as all other ramfs
dentries.

Fixes: b3fbfad7ae ("fs: dentry cache implementation")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 fs/fs.c    | 3 +++
 fs/ramfs.c | 1 +
 2 files changed, 4 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 40dc32b3c4..dd064c8527 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2973,6 +2973,9 @@ int symlink(const char *pathname, const char *newpath)
 	}
 
 	error = vfs_symlink(path.dentry->d_inode, dentry, pathname);
+
+	dput(dentry);
+	path_put(&path);
 out:
 	return errno_set(error);
 }
diff --git a/fs/ramfs.c b/fs/ramfs.c
index 4c64310e22..22fe620b55 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -178,6 +178,7 @@ static int ramfs_symlink(struct inode *dir, struct dentry *dentry,
 	inode->i_link = xstrdup(symname);
 	inode->i_size = strlen(symname);
 	d_instantiate(dentry, inode);
+	dget(dentry);   /* Extra count - pin the dentry in core */
 
 	return 0;
 }

-- 
2.47.3




More information about the barebox mailing list