cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cgroup: add a validation check to cgroup_add_cftyps()
@ 2014-02-17  2:41 Li Zefan
  2014-02-18 23:20 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Li Zefan @ 2014-02-17  2:41 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Fengguang Wu, LKML, Cgroups

Fengguang reported this bug:

BUG: unable to handle kernel NULL pointer dereference at 0000003c
IP: [<cc90b4ad>] cgroup_cfts_commit+0x27/0x1c1
...
Call Trace:
  [<cc9d1129>] ? kmem_cache_alloc_trace+0x33f/0x3b7
  [<cc90c6fc>] cgroup_add_cftypes+0x8f/0xca
  [<cd78b646>] cgroup_init+0x6a/0x26a
  [<cd764d7d>] start_kernel+0x4d7/0x57a
  [<cd7642ef>] i386_start_kernel+0x92/0x96

This happens in a corner case. If CGROUP_SCHED=y but CFS_BANDWIDTH=n &&
FAIR_GROUP_SCHED=n && RT_GROUP_SCHED=n, we have:

cpu_files[] = {
	{ }	/* terminate */
}

When we pass cpu_files to cgroup_apply_cftypes(), as cpu_files[0].ss
is NULL, we'll access NULL pointer.

The bug was introduced by commit de00ffa56ea3132c6013fc8f07133b8a1014cf53
("cgroup: make cgroup_subsys->base_cftypes use cgroup_add_cftypes()").

Reported-by: Fengguang Wu <fengguang.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
 kernel/cgroup.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index eaffc08..465c1d8 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2356,6 +2356,9 @@ int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
 {
 	int ret;
 
+	if (!cfts || cfts[0].name[0] == '\0')
+		return 0;
+
 	ret = cgroup_init_cftypes(ss, cfts);
 	if (ret)
 		return ret;
-- 
1.8.0.2

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

* Re: [PATCH] cgroup: add a validation check to cgroup_add_cftyps()
  2014-02-17  2:41 [PATCH] cgroup: add a validation check to cgroup_add_cftyps() Li Zefan
@ 2014-02-18 23:20 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2014-02-18 23:20 UTC (permalink / raw)
  To: Li Zefan; +Cc: Fengguang Wu, LKML, Cgroups

On Mon, Feb 17, 2014 at 10:41:50AM +0800, Li Zefan wrote:
> Fengguang reported this bug:
> 
> BUG: unable to handle kernel NULL pointer dereference at 0000003c
> IP: [<cc90b4ad>] cgroup_cfts_commit+0x27/0x1c1
> ...
> Call Trace:
>   [<cc9d1129>] ? kmem_cache_alloc_trace+0x33f/0x3b7
>   [<cc90c6fc>] cgroup_add_cftypes+0x8f/0xca
>   [<cd78b646>] cgroup_init+0x6a/0x26a
>   [<cd764d7d>] start_kernel+0x4d7/0x57a
>   [<cd7642ef>] i386_start_kernel+0x92/0x96
> 
> This happens in a corner case. If CGROUP_SCHED=y but CFS_BANDWIDTH=n &&
> FAIR_GROUP_SCHED=n && RT_GROUP_SCHED=n, we have:
> 
> cpu_files[] = {
> 	{ }	/* terminate */
> }
> 
> When we pass cpu_files to cgroup_apply_cftypes(), as cpu_files[0].ss
> is NULL, we'll access NULL pointer.
> 
> The bug was introduced by commit de00ffa56ea3132c6013fc8f07133b8a1014cf53
> ("cgroup: make cgroup_subsys->base_cftypes use cgroup_add_cftypes()").
> 
> Reported-by: Fengguang Wu <fengguang.wu@intel.com>
> Signed-off-by: Li Zefan <lizefan@huawei.com>

Applied to cgroup/for-3.15.  Thanks.

-- 
tejun

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

end of thread, other threads:[~2014-02-18 23:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-17  2:41 [PATCH] cgroup: add a validation check to cgroup_add_cftyps() Li Zefan
2014-02-18 23:20 ` Tejun Heo

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).