lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 27 Feb 2012 11:44:52 +0100
From:	Ingo Molnar <mingo@...e.hu>
To:	Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc:	Namhyung Kim <namhyung.kim@....com>,
	Namhyung Kim <namhyung@...il.com>,
	Paul Mackerras <paulus@...ba.org>,
	Arnaldo Carvalho de Melo <acme@...stprotocols.net>,
	LKML <linux-kernel@...r.kernel.org>,
	Frederic Weisbecker <fweisbec@...il.com>
Subject: Re: [PATCH] hw breakpoint: Fix possible memory leak


* Peter Zijlstra <a.p.zijlstra@...llo.nl> wrote:

> On Mon, 2012-02-27 at 12:02 +0900, Namhyung Kim wrote:
> > If kzalloc() for TYPE_DATA failed on a given cpu, previous chunk
> > will be leaked. Fix it.
> 
> so why not fix the error loop? wouldn't putting that err_cpu == cpu
> break after the kfree sort it?

I edited that code earlier today - is the form below OK, or can 
you see a simpler method? It's not yet pushed out so can still 
edit it.

Thanks,

	Ingo

>From f019669c93da6c2094326d07735320d3bf223ffe Mon Sep 17 00:00:00 2001
From: Namhyung Kim <namhyung.kim@....com>
Date: Mon, 27 Feb 2012 12:02:19 +0900
Subject: [PATCH] hw breakpoints: Fix possible memory leak

If kzalloc() for TYPE_DATA failed on a given cpu, previous chunk
will be leaked. Fix it.

Signed-off-by: Namhyung Kim <namhyung.kim@....com>
Cc: Namhyung Kim <namhyung@...il.com>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Arnaldo Carvalho de Melo <acme@...stprotocols.net>
Link: http://lkml.kernel.org/r/1330311739-24302-1-git-send-email-namhyung.kim@lge.com
[ rearranged the code to have a clearer flow ]
Signed-off-by: Ingo Molnar <mingo@...e.hu>
---
 kernel/events/hw_breakpoint.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index b7971d6..867032d 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -636,10 +636,9 @@ int __init init_hw_breakpoint(void)
 	for_each_possible_cpu(cpu) {
 		for (i = 0; i < TYPE_MAX; i++) {
 			task_bp_pinned = &per_cpu(nr_task_bp_pinned[i], cpu);
-			*task_bp_pinned = kzalloc(sizeof(int) * nr_slots[i],
-						  GFP_KERNEL);
+			*task_bp_pinned = kzalloc(sizeof(int) * nr_slots[i], GFP_KERNEL);
 			if (!*task_bp_pinned)
-				goto err_alloc;
+				goto err_alloc_pinned;
 		}
 	}
 
@@ -649,6 +648,9 @@ int __init init_hw_breakpoint(void)
 
 	return register_die_notifier(&hw_breakpoint_exceptions_nb);
 
+ err_alloc_pinned:
+	while (--i >= 0)
+		kfree(per_cpu(nr_task_bp_pinned[i], cpu));
  err_alloc:
 	for_each_possible_cpu(err_cpu) {
 		if (err_cpu == cpu)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ