Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754931AbbGFTna (ORCPT ); Mon, 6 Jul 2015 15:43:30 -0400 Received: from mail-qk0-f173.google.com ([209.85.220.173]:34532 "EHLO mail-qk0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751318AbbGFTn2 (ORCPT ); Mon, 6 Jul 2015 15:43:28 -0400 MIME-Version: 1.0 In-Reply-To: References: <1435778966-36415-1-git-send-email-aksgarg1989@gmail.com> Date: Tue, 7 Jul 2015 01:13:27 +0530 Message-ID: Subject: Re: [tip:sched/core] sched/rt: Fix memory leak in alloc_rt_sched_group() From: Anshul Garg To: peterz@infradead.org, hpa@zytor.com, Linus Torvalds , Linux Kernel Mailing List , tglx@linutronix.de, mingo@kernel.org, anshul garg Cc: linux-tip-commits@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3218 Lines: 86 Dear linux community, I think this patch" sched/rt: Fix memory leak in alloc_rt_sched_group()" with Commit-ID: ecdd6804b7c9e15fe8fc836ba0233d9912834e8b is not correct. As it will create panic in case of kzalloc failure because of doingkfree twice. As if alloc_rt_sched_group fails it will return zero then core.c will call free_sched_group in core.c which subsequently calls free_rt_sched_group . In free_rt_sched_group memory is getting freed properly. so it seems patch sent by me is not correct. Please help to review patch once again as it might break some things. Sorry for inconvenience. Thanks Anshul Garg On Mon, Jul 6, 2015 at 9:05 PM, tip-bot for Anshul Garg wrote: > Commit-ID: ecdd6804b7c9e15fe8fc836ba0233d9912834e8b > Gitweb: http://git.kernel.org/tip/ecdd6804b7c9e15fe8fc836ba0233d9912834e8b > Author: Anshul Garg > AuthorDate: Wed, 1 Jul 2015 12:29:26 -0700 > Committer: Ingo Molnar > CommitDate: Mon, 6 Jul 2015 14:17:14 +0200 > > sched/rt: Fix memory leak in alloc_rt_sched_group() > > Added code to free allocated memory by function > alloc_rt_sched_group() in case the kzalloc() API fails. > > Signed-off-by: Anshul Garg > Signed-off-by: Peter Zijlstra (Intel) > Cc: Linus Torvalds > Cc: Peter Zijlstra > Cc: Thomas Gleixner > Link: http://lkml.kernel.org/r/1435778966-36415-1-git-send-email-aksgarg1989@gmail.com > Signed-off-by: Ingo Molnar > --- > kernel/sched/rt.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c > index 0d193a24..cfa907d 100644 > --- a/kernel/sched/rt.c > +++ b/kernel/sched/rt.c > @@ -193,7 +193,7 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) > goto err; > tg->rt_se = kzalloc(sizeof(rt_se) * nr_cpu_ids, GFP_KERNEL); > if (!tg->rt_se) > - goto err; > + goto err_free_rt_rq; > > init_rt_bandwidth(&tg->rt_bandwidth, > ktime_to_ns(def_rt_bandwidth.rt_period), 0); > @@ -202,7 +202,7 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) > rt_rq = kzalloc_node(sizeof(struct rt_rq), > GFP_KERNEL, cpu_to_node(i)); > if (!rt_rq) > - goto err; > + goto err_free_rt_se; > > rt_se = kzalloc_node(sizeof(struct sched_rt_entity), > GFP_KERNEL, cpu_to_node(i)); > @@ -218,6 +218,10 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) > > err_free_rq: > kfree(rt_rq); > +err_free_rt_se: > + kfree(tg->rt_se); > +err_free_rt_rq: > + kfree(tg->rt_rq); > err: > return 0; > } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/