All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/microcode/intel: Fix memleak in save_microcode_patch
@ 2018-06-01  4:51 Zhenzhong Duan
  2018-06-01  7:12 ` Borislav Petkov
  2018-06-22 12:45 ` [tip:x86/urgent] x86/microcode/intel: Fix memleak in save_microcode_patch() tip-bot for Zhenzhong Duan
  0 siblings, 2 replies; 3+ messages in thread
From: Zhenzhong Duan @ 2018-06-01  4:51 UTC (permalink / raw)
  To: linux-kernel; +Cc: mingo, tglx, Srinivas REDDY Eeda, bp, hpa

Free useless ucode_patch entry when it's replaced.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
---
 arch/x86/kernel/cpu/microcode/intel.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
index 1c2cfa0..461e315 100644
--- a/arch/x86/kernel/cpu/microcode/intel.c
+++ b/arch/x86/kernel/cpu/microcode/intel.c
@@ -150,6 +150,12 @@ static bool microcode_matches(struct microcode_header_intel *mc_header,
 	return false;
 }
 
+static void memfree_patch(struct ucode_patch *p)
+{
+	kfree(p->data);
+	kfree(p);
+}
+
 static struct ucode_patch *memdup_patch(void *data, unsigned int size)
 {
 	struct ucode_patch *p;
@@ -190,8 +196,10 @@ static void save_microcode_patch(void *data, unsigned int size)
 			p = memdup_patch(data, size);
 			if (!p)
 				pr_err("Error allocating buffer %p\n", data);
-			else
+			else {
 				list_replace(&iter->plist, &p->plist);
+				memfree_patch(iter);
+			}
 		}
 	}
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-22 12:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-01  4:51 [PATCH] x86/microcode/intel: Fix memleak in save_microcode_patch Zhenzhong Duan
2018-06-01  7:12 ` Borislav Petkov
2018-06-22 12:45 ` [tip:x86/urgent] x86/microcode/intel: Fix memleak in save_microcode_patch() tip-bot for Zhenzhong Duan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.