| Message ID | 20251011092235.29880-1-lihongbo22@huawei.com |
|---|---|
| State | Handled Elsewhere |
| Headers | show |
| Series | hostfs: Fix only passing host root in boot stage with new mount | expand |
(This time, responding in plain text so the list-server doesn't reject. oops.) Yes, I've tested your patch and it has fixed the problem for me. Thanks On 2025-10-11 05:22, Hongbo Li wrote: > 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> > --- > fs/hostfs/hostfs_kern.c | 29 ++++++++++++++++++----------- > 1 file changed, 18 insertions(+), 11 deletions(-) > > diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c > index 1e1acf5775ab..86455eebbf6c 100644 > --- a/fs/hostfs/hostfs_kern.c > +++ b/fs/hostfs/hostfs_kern.c > @@ -979,7 +979,7 @@ static int hostfs_parse_param(struct fs_context *fc, struct fs_parameter *param) > { > struct hostfs_fs_info *fsi = fc->s_fs_info; > struct fs_parse_result result; > - char *host_root; > + char *host_root, *tmp_root; > int opt; > > opt = fs_parse(fc, hostfs_param_specs, param, &result); > @@ -990,11 +990,13 @@ static int hostfs_parse_param(struct fs_context *fc, struct fs_parameter *param) > case Opt_hostfs: > host_root = param->string; > if (!*host_root) > - host_root = ""; > - fsi->host_root_path = > - kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); > - if (fsi->host_root_path == NULL) > + break; > + tmp_root = kasprintf(GFP_KERNEL, "%s%s", > + fsi->host_root_path, host_root); > + if (!tmp_root) > return -ENOMEM; > + kfree(fsi->host_root_path); > + fsi->host_root_path = tmp_root; > break; > } > > @@ -1004,17 +1006,17 @@ static int hostfs_parse_param(struct fs_context *fc, struct fs_parameter *param) > static int hostfs_parse_monolithic(struct fs_context *fc, void *data) > { > struct hostfs_fs_info *fsi = fc->s_fs_info; > - char *host_root = (char *)data; > + char *tmp_root, *host_root = (char *)data; > > /* NULL is printed as '(null)' by printf(): avoid that. */ > if (host_root == NULL) > - host_root = ""; > + return 0; > > - fsi->host_root_path = > - kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); > - if (fsi->host_root_path == NULL) > + tmp_root = kasprintf(GFP_KERNEL, "%s%s", fsi->host_root_path, host_root); > + if (!tmp_root) > return -ENOMEM; > - > + kfree(fsi->host_root_path); > + fsi->host_root_path = tmp_root; > return 0; > } > > @@ -1049,6 +1051,11 @@ static int hostfs_init_fs_context(struct fs_context *fc) > if (!fsi) > return -ENOMEM; > > + fsi->host_root_path = kasprintf(GFP_KERNEL, "%s/", root_ino); > + if (!fsi->host_root_path) { > + kfree(fsi); > + return -ENOMEM; > + } > fc->s_fs_info = fsi; > fc->ops = &hostfs_context_ops; > return 0;
On Sat, 11 Oct 2025 09:22:35 +0000, Hongbo Li wrote: > 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. > > [...] Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon. Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it. It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated. Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch. tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes [1/1] hostfs: Fix only passing host root in boot stage with new mount https://git.kernel.org/vfs/vfs/c/590a4c70008c
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index 1e1acf5775ab..86455eebbf6c 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c @@ -979,7 +979,7 @@ static int hostfs_parse_param(struct fs_context *fc, struct fs_parameter *param) { struct hostfs_fs_info *fsi = fc->s_fs_info; struct fs_parse_result result; - char *host_root; + char *host_root, *tmp_root; int opt; opt = fs_parse(fc, hostfs_param_specs, param, &result); @@ -990,11 +990,13 @@ static int hostfs_parse_param(struct fs_context *fc, struct fs_parameter *param) case Opt_hostfs: host_root = param->string; if (!*host_root) - host_root = ""; - fsi->host_root_path = - kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); - if (fsi->host_root_path == NULL) + break; + tmp_root = kasprintf(GFP_KERNEL, "%s%s", + fsi->host_root_path, host_root); + if (!tmp_root) return -ENOMEM; + kfree(fsi->host_root_path); + fsi->host_root_path = tmp_root; break; } @@ -1004,17 +1006,17 @@ static int hostfs_parse_param(struct fs_context *fc, struct fs_parameter *param) static int hostfs_parse_monolithic(struct fs_context *fc, void *data) { struct hostfs_fs_info *fsi = fc->s_fs_info; - char *host_root = (char *)data; + char *tmp_root, *host_root = (char *)data; /* NULL is printed as '(null)' by printf(): avoid that. */ if (host_root == NULL) - host_root = ""; + return 0; - fsi->host_root_path = - kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); - if (fsi->host_root_path == NULL) + tmp_root = kasprintf(GFP_KERNEL, "%s%s", fsi->host_root_path, host_root); + if (!tmp_root) return -ENOMEM; - + kfree(fsi->host_root_path); + fsi->host_root_path = tmp_root; return 0; } @@ -1049,6 +1051,11 @@ static int hostfs_init_fs_context(struct fs_context *fc) if (!fsi) return -ENOMEM; + fsi->host_root_path = kasprintf(GFP_KERNEL, "%s/", root_ino); + if (!fsi->host_root_path) { + kfree(fsi); + return -ENOMEM; + } fc->s_fs_info = fsi; fc->ops = &hostfs_context_ops; return 0;
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> --- fs/hostfs/hostfs_kern.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)