aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mempolicy.h
diff options
context:
space:
mode:
authorMel Gorman <mgorman@suse.de>2012-10-08 19:29:17 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-09 03:22:22 -0400
commitb22d127a39ddd10d93deee3d96e643657ad53a49 (patch)
tree9a16e3d3a53a230dba611c85e9f892dda2b6c202 /include/linux/mempolicy.h
parent869833f2c5c6e4dd09a5378cfc665ffb4615e5d2 (diff)
mempolicy: fix a race in shared_policy_replace()
shared_policy_replace() use of sp_alloc() is unsafe. 1) sp_node cannot be dereferenced if sp->lock is not held and 2) another thread can modify sp_node between spin_unlock for allocating a new sp node and next spin_lock. The bug was introduced before 2.6.12-rc2. Kosaki's original patch for this problem was to allocate an sp node and policy within shared_policy_replace and initialise it when the lock is reacquired. I was not keen on this approach because it partially duplicates sp_alloc(). As the paths were sp->lock is taken are not that performance critical this patch converts sp->lock to sp->mutex so it can sleep when calling sp_alloc(). [kosaki.motohiro@jp.fujitsu.com: Original patch] Signed-off-by: Mel Gorman <mgorman@suse.de> Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Reviewed-by: Christoph Lameter <cl@linux.com> Cc: Josh Boyer <jwboyer@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/mempolicy.h')
-rw-r--r--include/linux/mempolicy.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
index ba7a0ff19d39..cec569325608 100644
--- a/include/linux/mempolicy.h
+++ b/include/linux/mempolicy.h
@@ -188,7 +188,7 @@ struct sp_node {
188 188
189struct shared_policy { 189struct shared_policy {
190 struct rb_root root; 190 struct rb_root root;
191 spinlock_t lock; 191 struct mutex mutex;
192}; 192};
193 193
194void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol); 194void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol);