Skip to contentSkip to conversation

cgroup: fix unbalanced locking

PATCH Applied Zefan Li 3 participants 3 messages Sep 18, 2014 cgroup

lore
Share & tools
lore

Zefan Li

author
#0 lore raw

PATCH 1/1 cgroup: fix unbalanced locking

cgroup_pidlist_start() holds cgrp->pidlist_mutex and then calls pidlist_array_load(), and cgroup_pidlist_stop() releases the mutex.

It is wrong that we release the mutex in the failure path in pidlist_array_load(), because cgroup_pidlist_stop() will be called no matter if cgroup_pidlist_start() returns errno or not.

Fixes 4bac00d16a8760eae7205e41d2c246477d42a210
Cc <[email protected]> # 3.14+
---
 kernel/cgroup.c | 1 -
 1 file changed, 1 deletion(-)
kernel/cgroup.c +0 -1
index 2332efd..de70b63 100644
@@ -3970,7 +3970,6 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
 
 	l = cgroup_pidlist_find_create(cgrp, type);
 	if (!l) {
-		mutex_unlock(&cgrp->pidlist_mutex);
 		pidlist_free(array);
 		return -ENOMEM;
 	}
Signature · 1 line
1.8.0.2
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Zefan Li

cgroup_pidlist_start() holds cgrp->pidlist_mutex and then calls pidlist_array_load(), and cgroup_pidlist_stop() releases the mutex.

It is wrong that we release the mutex in the failure path in pidlist_array_load(), because cgroup_pidlist_stop() will be called no matter if cgroup_pidlist_start() returns errno or not.

I found same thing yesterday and tried to analysis if this could be the cause of the the NULL ptr def bug I saw, it seems not.

Anyway, this fix is definitely correct,

maintainer Applied
#2 lore raw
In reply to Zefan Li
Quoted 10 lines · Zefan Li

cgroup_pidlist_start() holds cgrp->pidlist_mutex and then calls pidlist_array_load(), and cgroup_pidlist_stop() releases the mutex.

It is wrong that we release the mutex in the failure path in pidlist_array_load(), because cgroup_pidlist_stop() will be called no matter if cgroup_pidlist_start() returns errno or not.

Fixes 4bac00d16a8760eae7205e41d2c246477d42a210
Cc <[email protected]> # 3.14+

Applied to cgroup/for-3.17-fixes.

Thanks.

Signature · 1 line
tejun