]> git.karo-electronics.de Git - karo-tx-linux.git/commit
mempolicy: fix a race in shared_policy_replace()
authorMel Gorman <mgorman@suse.de>
Fri, 7 Sep 2012 00:23:12 +0000 (10:23 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 7 Sep 2012 05:36:12 +0000 (15:36 +1000)
commit9b3d72ef4c77b8ce45c829b9ad16f5ea1d572d34
tree535890f87ee48511da7caa3aff512d9286c66a27
parentf1e9a06b92a3246970300d9f3c52f54467a1865c
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>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mempolicy.h
mm/mempolicy.c