Commit 555406d3 authored by Chengguang Xu's avatar Chengguang Xu Committed by Kleber Sacilotto de Souza

fs/exofs: fix potential memory leak in mount option parsing

BugLink: https://bugs.launchpad.net/bugs/1810958

[ Upstream commit 515f1867 ]

There are some cases can cause memory leak when parsing
option 'osdname'.
Signed-off-by: default avatarChengguang Xu <cgxu519@gmx.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 6dfc1c1f
...@@ -100,6 +100,7 @@ static int parse_options(char *options, struct exofs_mountopt *opts) ...@@ -100,6 +100,7 @@ static int parse_options(char *options, struct exofs_mountopt *opts)
token = match_token(p, tokens, args); token = match_token(p, tokens, args);
switch (token) { switch (token) {
case Opt_name: case Opt_name:
kfree(opts->dev_name);
opts->dev_name = match_strdup(&args[0]); opts->dev_name = match_strdup(&args[0]);
if (unlikely(!opts->dev_name)) { if (unlikely(!opts->dev_name)) {
EXOFS_ERR("Error allocating dev_name"); EXOFS_ERR("Error allocating dev_name");
...@@ -868,8 +869,10 @@ static struct dentry *exofs_mount(struct file_system_type *type, ...@@ -868,8 +869,10 @@ static struct dentry *exofs_mount(struct file_system_type *type,
int ret; int ret;
ret = parse_options(data, &opts); ret = parse_options(data, &opts);
if (ret) if (ret) {
kfree(opts.dev_name);
return ERR_PTR(ret); return ERR_PTR(ret);
}
if (!opts.dev_name) if (!opts.dev_name)
opts.dev_name = dev_name; opts.dev_name = dev_name;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment