Skip to content

Commit 2c2b67a

Browse files
Hongbo Librauner
authored andcommitted
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: cd140ce ("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>
1 parent 0778ac7 commit 2c2b67a

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

fs/hostfs/hostfs_kern.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ static int hostfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
979979
{
980980
struct hostfs_fs_info *fsi = fc->s_fs_info;
981981
struct fs_parse_result result;
982-
char *host_root;
982+
char *host_root, *tmp_root;
983983
int opt;
984984

985985
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)
990990
case Opt_hostfs:
991991
host_root = param->string;
992992
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)
997997
return -ENOMEM;
998+
kfree(fsi->host_root_path);
999+
fsi->host_root_path = tmp_root;
9981000
break;
9991001
}
10001002

@@ -1004,17 +1006,17 @@ static int hostfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
10041006
static int hostfs_parse_monolithic(struct fs_context *fc, void *data)
10051007
{
10061008
struct hostfs_fs_info *fsi = fc->s_fs_info;
1007-
char *host_root = (char *)data;
1009+
char *tmp_root, *host_root = (char *)data;
10081010

10091011
/* NULL is printed as '(null)' by printf(): avoid that. */
10101012
if (host_root == NULL)
1011-
host_root = "";
1013+
return 0;
10121014

1013-
fsi->host_root_path =
1014-
kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root);
1015-
if (fsi->host_root_path == NULL)
1015+
tmp_root = kasprintf(GFP_KERNEL, "%s%s", fsi->host_root_path, host_root);
1016+
if (!tmp_root)
10161017
return -ENOMEM;
1017-
1018+
kfree(fsi->host_root_path);
1019+
fsi->host_root_path = tmp_root;
10181020
return 0;
10191021
}
10201022

@@ -1049,6 +1051,11 @@ static int hostfs_init_fs_context(struct fs_context *fc)
10491051
if (!fsi)
10501052
return -ENOMEM;
10511053

1054+
fsi->host_root_path = kasprintf(GFP_KERNEL, "%s/", root_ino);
1055+
if (!fsi->host_root_path) {
1056+
kfree(fsi);
1057+
return -ENOMEM;
1058+
}
10521059
fc->s_fs_info = fsi;
10531060
fc->ops = &hostfs_context_ops;
10541061
return 0;

0 commit comments

Comments
 (0)