Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1628288

[RFC PATCH 06/14] cgroup: Fix reference counting bug in cgroup_procs_write()

From Waiman Long <longman@redhat.com>
Newsgroups linux.kernel
Subject [RFC PATCH 06/14] cgroup: Fix reference counting bug in cgroup_procs_write()
Date 2017-04-21 16:10 +0200
Message-ID <tyHq2-6LU-29@gated-at.bofh.it> (permalink)
References <tyHq1-6LU-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


The cgroup_procs_write_start() took a reference to the task structure
which was not properly released within cgroup_procs_write() and so
on. So a put_task_struct() call is added to cgroup_procs_write_finish()
to match the get_task_struct() in cgroup_procs_write_start() to fix
this reference counting error.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/cgroup/cgroup-internal.h |  2 +-
 kernel/cgroup/cgroup-v1.c       |  2 +-
 kernel/cgroup/cgroup.c          | 10 ++++++----
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h
index 6ef662a..bea3928 100644
--- a/kernel/cgroup/cgroup-internal.h
+++ b/kernel/cgroup/cgroup-internal.h
@@ -181,7 +181,7 @@ int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
 		       bool threadgroup);
 struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup)
 	__acquires(&cgroup_threadgroup_rwsem);
-void cgroup_procs_write_finish(void)
+void cgroup_procs_write_finish(struct task_struct *task)
 	__releases(&cgroup_threadgroup_rwsem);
 
 void cgroup_lock_and_drain_offline(struct cgroup *cgrp);
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index b837e1a..e80bc8e 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -549,7 +549,7 @@ static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of,
 	ret = cgroup_attach_task(cgrp, task, threadgroup);
 
 out_finish:
-	cgroup_procs_write_finish();
+	cgroup_procs_write_finish(task);
 out_unlock:
 	cgroup_kn_unlock(of->kn);
 
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 6748207..d48eedd 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2487,12 +2487,15 @@ struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup)
 	return tsk;
 }
 
-void cgroup_procs_write_finish(void)
+void cgroup_procs_write_finish(struct task_struct *task)
 	__releases(&cgroup_threadgroup_rwsem)
 {
 	struct cgroup_subsys *ss;
 	int ssid;
 
+	/* release reference from cgroup_procs_write_start() */
+	put_task_struct(task);
+
 	percpu_up_write(&cgroup_threadgroup_rwsem);
 	for_each_subsys(ss, ssid)
 		if (ss->post_attach)
@@ -3295,7 +3298,6 @@ static int cgroup_addrm_files(struct cgroup_subsys_state *css,
 
 static int cgroup_apply_cftypes(struct cftype *cfts, bool is_add)
 {
-	LIST_HEAD(pending);
 	struct cgroup_subsys *ss = cfts[0].ss;
 	struct cgroup *root = &ss->root->cgrp;
 	struct cgroup_subsys_state *css;
@@ -4060,7 +4062,7 @@ static ssize_t cgroup_procs_write(struct kernfs_open_file *of,
 	ret = cgroup_attach_task(cgrp, task, true);
 
 out_finish:
-	cgroup_procs_write_finish();
+	cgroup_procs_write_finish(task);
 out_unlock:
 	cgroup_kn_unlock(of->kn);
 
@@ -4130,7 +4132,7 @@ static ssize_t cgroup_threads_write(struct kernfs_open_file *of,
 	ret = cgroup_attach_task(cgrp, task, false);
 
 out_finish:
-	cgroup_procs_write_finish();
+	cgroup_procs_write_finish(task);
 out_unlock:
 	cgroup_kn_unlock(of->kn);
 
-- 
1.8.3.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC PATCH 00/14] cgroup: Implement cgroup v2 thread mode & CPU controller Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 08/14] cgroup: Keep accurate count of tasks in each css_set Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 12/14] sched: Implement interface for cgroup unified hierarchy Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 13/14] sched: Make cpu/cpuacct threaded controllers Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 03/14] cgroup: introduce cgroup->proc_cgrp and threaded css_set handling Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 09/14] cgroup: Make debug cgroup support v2 and thread mode Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 06/14] cgroup: Fix reference counting bug in cgroup_procs_write() Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 07/14] cgroup: Move debug cgroup to its own file Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 05/14] cgroup: implement cgroup v2 thread support Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 10/14] cgroup: Implement new thread mode semantics Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 04/14] cgroup: implement CSS_TASK_ITER_THREADED Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 14/14] cgroup: Enable separate control knobs for thread root internal processes Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 02/14] cgroup: add @flags to css_task_iter_start() and implement CSS_TASK_ITER_PROCS Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 11/14] sched: Misc preps for cgroup unified hierarchy interface Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200
  [RFC PATCH 01/14] cgroup: reorganize cgroup.procs / task write path Waiman Long <longman@redhat.com> - 2017-04-21 16:10 +0200

csiph-web