summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2025-01-31 20:33:54 +0300
committerLinus Torvalds <torvalds@linux-foundation.org>2025-01-31 20:33:54 +0300
commitb2fde87318f3d77314334b8bfe93846f36ae1708 (patch)
tree63d72f2070a955dc238d5f3cbf1444bc9c2ceac0
parent8f08ed05b31c6cfb5acd2eb7340368560f17cdd3 (diff)
parent60a6002432448bb3f291d80768ae98d62efc9c77 (diff)
downloadlinux-b2fde87318f3d77314334b8bfe93846f36ae1708.tar.xz
Merge tag 'pull-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull hostfs fix from Al Viro: "Fix hostfs __dentry_name() string handling. The use of strcpy() with overlapping source and destination is a UB; original loop hadn't been. More to the point, the whole thing is much easier done with memcpy() + memmove()" * tag 'pull-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: hostfs: fix string handling in __dentry_name()
-rw-r--r--fs/hostfs/hostfs_kern.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 844c45253452..e0741e468956 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -95,32 +95,17 @@ __uml_setup("hostfs=", hostfs_args,
static char *__dentry_name(struct dentry *dentry, char *name)
{
char *p = dentry_path_raw(dentry, name, PATH_MAX);
- char *root;
- size_t len;
- struct hostfs_fs_info *fsi;
-
- fsi = dentry->d_sb->s_fs_info;
- root = fsi->host_root_path;
- len = strlen(root);
- if (IS_ERR(p)) {
- __putname(name);
- return NULL;
- }
-
- /*
- * This function relies on the fact that dentry_path_raw() will place
- * the path name at the end of the provided buffer.
- */
- BUG_ON(p + strlen(p) + 1 != name + PATH_MAX);
+ struct hostfs_fs_info *fsi = dentry->d_sb->s_fs_info;
+ char *root = fsi->host_root_path;
+ size_t len = strlen(root);
- strscpy(name, root, PATH_MAX);
- if (len > p - name) {
+ if (IS_ERR(p) || len > p - name) {
__putname(name);
return NULL;
}
- if (p > name + len)
- strcpy(name + len, p);
+ memcpy(name, root, len);
+ memmove(name + len, p, name + PATH_MAX - p);
return name;
}