cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cgroup: add lock validation in check_for_release()
@ 2013-01-25  7:10 Li Zefan
  0 siblings, 0 replies; only message in thread
From: Li Zefan @ 2013-01-25  7:10 UTC (permalink / raw)
  To: Tejun Heo, LKML, Cgroups

There was a long-standing bug that this function was called without any
lock. Add a check to prevent similar issue.

Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
 kernel/cgroup.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 776ff75..3d21adf 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -5028,13 +5028,20 @@ int cgroup_is_descendant(const struct cgroup *cgrp, struct task_struct *task)
 
 static void check_for_release(struct cgroup *cgrp)
 {
-	/* All of these checks rely on RCU to keep the cgroup
-	 * structure alive */
+	/*
+	 * All of these checks rely on RCU or cgroup_mutex to keep the cgroup
+	 * structure alive
+	 */
+	rcu_lockdep_assert(rcu_read_lock_held() || cgroup_lock_is_held(),
+			   "check_for_release() called witout proper locking");
+
 	if (cgroup_is_releasable(cgrp) && !atomic_read(&cgrp->count)
 	    && list_empty(&cgrp->children) && !cgroup_has_css_refs(cgrp)) {
-		/* Control Group is currently removeable. If it's not
+		/*
+		 * Control Group is currently removable. If it's not
 		 * already queued for a userspace notification, queue
-		 * it now */
+		 * it now
+		 */
 		int need_schedule_work = 0;
 		raw_spin_lock(&release_list_lock);
 		if (!cgroup_is_removed(cgrp) &&
-- 
1.8.0.2

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-01-25  7:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-25  7:10 [PATCH] cgroup: add lock validation in check_for_release() Li Zefan

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