kernel/module: Fix memleak in module_add_modinfo_attrs()
authorYueHaibing <yuehaibing@huawei.com>
Sat, 28 Dec 2019 11:54:55 +0000 (19:54 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Feb 2020 07:36:26 +0000 (08:36 +0100)
[ Upstream commit f6d061d617124abbd55396a3bc37b9bf7d33233c ]

In module_add_modinfo_attrs() if sysfs_create_file() fails
on the first iteration of the loop (so i = 0), we forget to
free the modinfo_attrs.

Fixes: bc6f2a757d52 ("kernel/module: Fix mem leak in module_add_modinfo_attrs")
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/module.c

index cb09a5f37a5fc83ace165dafa2e96aacb58e2ba0..9fb8fa22e16b3e841bdf5296ed2f2a7b41493c02 100644 (file)
@@ -1781,6 +1781,8 @@ static int module_add_modinfo_attrs(struct module *mod)
 error_out:
        if (i > 0)
                module_remove_modinfo_attrs(mod, --i);
+       else
+               kfree(mod->modinfo_attrs);
        return error;
 }