Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

hostfs: Fix only passing host root in boot stage with new mount

In the old mount proceedure, hostfs could only pass root directory during
boot. This is because it constructed the root directory using the @root_ino
event without any mount options. However, when using it with the new mount
API, this step is no longer triggered. As a result, if users mounts without
specifying any mount options, the @host_root_path remains uninitialized. To
prevent this issue, the @host_root_path should be initialized at the time
of allocation.

Reported-by: Geoffrey Thorpe <geoff@geoffthorpe.net>
Closes: https://lore.kernel.org/all/643333a0-f434-42fb-82ac-d25a0b56f3b7@geoffthorpe.net/
Fixes: cd140ce9f611 ("hostfs: convert hostfs to use the new mount API")
Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Link: https://patch.msgid.link/20251011092235.29880-1-lihongbo22@huawei.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Hongbo Li and committed by
Christian Brauner
2c2b67af 0778ac7d

+18 -11
+18 -11
fs/hostfs/hostfs_kern.c
··· 979 979 { 980 980 struct hostfs_fs_info *fsi = fc->s_fs_info; 981 981 struct fs_parse_result result; 982 - char *host_root; 982 + char *host_root, *tmp_root; 983 983 int opt; 984 984 985 985 opt = fs_parse(fc, hostfs_param_specs, param, &result); ··· 990 990 case Opt_hostfs: 991 991 host_root = param->string; 992 992 if (!*host_root) 993 - host_root = ""; 994 - fsi->host_root_path = 995 - kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); 996 - if (fsi->host_root_path == NULL) 993 + break; 994 + tmp_root = kasprintf(GFP_KERNEL, "%s%s", 995 + fsi->host_root_path, host_root); 996 + if (!tmp_root) 997 997 return -ENOMEM; 998 + kfree(fsi->host_root_path); 999 + fsi->host_root_path = tmp_root; 998 1000 break; 999 1001 } 1000 1002 ··· 1006 1004 static int hostfs_parse_monolithic(struct fs_context *fc, void *data) 1007 1005 { 1008 1006 struct hostfs_fs_info *fsi = fc->s_fs_info; 1009 - char *host_root = (char *)data; 1007 + char *tmp_root, *host_root = (char *)data; 1010 1008 1011 1009 /* NULL is printed as '(null)' by printf(): avoid that. */ 1012 1010 if (host_root == NULL) 1013 - host_root = ""; 1011 + return 0; 1014 1012 1015 - fsi->host_root_path = 1016 - kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); 1017 - if (fsi->host_root_path == NULL) 1013 + tmp_root = kasprintf(GFP_KERNEL, "%s%s", fsi->host_root_path, host_root); 1014 + if (!tmp_root) 1018 1015 return -ENOMEM; 1019 - 1016 + kfree(fsi->host_root_path); 1017 + fsi->host_root_path = tmp_root; 1020 1018 return 0; 1021 1019 } 1022 1020 ··· 1051 1049 if (!fsi) 1052 1050 return -ENOMEM; 1053 1051 1052 + fsi->host_root_path = kasprintf(GFP_KERNEL, "%s/", root_ino); 1053 + if (!fsi->host_root_path) { 1054 + kfree(fsi); 1055 + return -ENOMEM; 1056 + } 1054 1057 fc->s_fs_info = fsi; 1055 1058 fc->ops = &hostfs_context_ops; 1056 1059 return 0;