* [PATCH] Sched/rt:Fix memory leak in alloc_rt_sched_group
@ 2015-07-01 19:29 Anshul Garg
2015-07-06 15:35 ` [tip:sched/core] sched/rt: Fix memory leak in alloc_rt_sched_group() tip-bot for Anshul Garg
0 siblings, 1 reply; 4+ messages in thread
From: Anshul Garg @ 2015-07-01 19:29 UTC (permalink / raw)
To: linux-kernel, mingo, peterz; +Cc: aksgarg1989
From: Anshul Garg <aksgarg1989@gmail.com>
Added code to free allocated memory by function
alloc_rt_sched_group in case kzalloc api fails.
Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
---
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 f4d4b07..47213e9 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -177,7 +177,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);
@@ -186,7 +186,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));
@@ -202,6 +202,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;
}
--
1.7.9.5
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [tip:sched/core] sched/rt: Fix memory leak in alloc_rt_sched_group()
2015-07-01 19:29 [PATCH] Sched/rt:Fix memory leak in alloc_rt_sched_group Anshul Garg
@ 2015-07-06 15:35 ` tip-bot for Anshul Garg
2015-07-06 19:43 ` Anshul Garg
0 siblings, 1 reply; 4+ messages in thread
From: tip-bot for Anshul Garg @ 2015-07-06 15:35 UTC (permalink / raw)
To: linux-tip-commits
Cc: torvalds, mingo, aksgarg1989, tglx, linux-kernel, hpa, peterz
Commit-ID: ecdd6804b7c9e15fe8fc836ba0233d9912834e8b
Gitweb: http://git.kernel.org/tip/ecdd6804b7c9e15fe8fc836ba0233d9912834e8b
Author: Anshul Garg <aksgarg1989@gmail.com>
AuthorDate: Wed, 1 Jul 2015 12:29:26 -0700
Committer: Ingo Molnar <mingo@kernel.org>
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 <aksgarg1989@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1435778966-36415-1-git-send-email-aksgarg1989@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
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;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [tip:sched/core] sched/rt: Fix memory leak in alloc_rt_sched_group()
2015-07-06 15:35 ` [tip:sched/core] sched/rt: Fix memory leak in alloc_rt_sched_group() tip-bot for Anshul Garg
@ 2015-07-06 19:43 ` Anshul Garg
2015-07-07 6:45 ` Ingo Molnar
0 siblings, 1 reply; 4+ messages in thread
From: Anshul Garg @ 2015-07-06 19:43 UTC (permalink / raw)
To: peterz, hpa, Linus Torvalds, Linux Kernel Mailing List, tglx,
mingo, anshul garg
Cc: linux-tip-commits
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
<tipbot@zytor.com> wrote:
> Commit-ID: ecdd6804b7c9e15fe8fc836ba0233d9912834e8b
> Gitweb: http://git.kernel.org/tip/ecdd6804b7c9e15fe8fc836ba0233d9912834e8b
> Author: Anshul Garg <aksgarg1989@gmail.com>
> AuthorDate: Wed, 1 Jul 2015 12:29:26 -0700
> Committer: Ingo Molnar <mingo@kernel.org>
> 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 <aksgarg1989@gmail.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Link: http://lkml.kernel.org/r/1435778966-36415-1-git-send-email-aksgarg1989@gmail.com
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> ---
> 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;
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [tip:sched/core] sched/rt: Fix memory leak in alloc_rt_sched_group()
2015-07-06 19:43 ` Anshul Garg
@ 2015-07-07 6:45 ` Ingo Molnar
0 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2015-07-07 6:45 UTC (permalink / raw)
To: Anshul Garg
Cc: peterz, hpa, Linus Torvalds, Linux Kernel Mailing List, tglx,
linux-tip-commits
* Anshul Garg <aksgarg1989@gmail.com> wrote:
> 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
Ok, I've removed this patch.
Thanks!
Ingo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-07-07 6:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-01 19:29 [PATCH] Sched/rt:Fix memory leak in alloc_rt_sched_group Anshul Garg
2015-07-06 15:35 ` [tip:sched/core] sched/rt: Fix memory leak in alloc_rt_sched_group() tip-bot for Anshul Garg
2015-07-06 19:43 ` Anshul Garg
2015-07-07 6:45 ` Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).