x86/MCE/AMD: Fix memory leak when threshold_create_bank() fails
stable inclusion from stable-v5.10.121 commit b4acb8e7f1594607bc9017ef0aacb40b24a003d6 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I5L6CQ Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=b4acb8e7f1594607bc9017ef0aacb40b24a003d6 -------------------------------- commit e5f28623 upstream. In mce_threshold_create_device(), if threshold_create_bank() fails, the previously allocated threshold banks array @bp will be leaked because the call to mce_threshold_remove_device() will not free it. This happens because mce_threshold_remove_device() fetches the pointer through the threshold_banks per-CPU variable but bp is written there only after the bank creation is successful, and not before, when threshold_create_bank() fails. Add a helper which unwinds all the bank creation work previously done and pass into it the previously allocated threshold banks array for freeing. [ bp: Massage. ] Fixes: 6458de97 ("x86/mce/amd: Straighten CPU hotplug path") Co-developed-by: NAlviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org> Signed-off-by: NAlviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org> Co-developed-by: NYazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: NYazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: NAmmar Faizi <ammarfaizi2@gnuweeb.org> Signed-off-by: NBorislav Petkov <bp@suse.de> Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/r/20220329104705.65256-3-ammarfaizi2@gnuweeb.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com> Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
Showing
想要评论请 注册 或 登录