• Johannes Weiner's avatar
    mm: memcontrol: fix lockless reclaim hierarchy iterator · 89dc991f
    Johannes Weiner authored
    The lockless reclaim hierarchy iterator currently has a misplaced
    barrier that can lead to use-after-free crashes.
    
    The reclaim hierarchy iterator consist of a sequence count and a
    position pointer that are read and written locklessly, with memory
    barriers enforcing ordering.
    
    The write side sets the position pointer first, then updates the
    sequence count to "publish" the new position.  Likewise, the read side
    must read the sequence count first, then the position.  If the sequence
    count is up to date, it's guaranteed that the position is up to date as
    well:
    
      writer:                         reader:
      iter->position = position       if iter->sequence == expected:
      smp_wmb()                           smp_rmb()
      iter->sequence = sequence           position = iter->position
    
    However, the read side barrier is currently misplaced, which can lead to
    dereferencing stale position pointers that no longer point to valid
    memory.  Fix this.
    Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
    Reported-by: default avatarTejun Heo <tj@kernel.org>
    Reviewed-by: default avatarTejun Heo <tj@kernel.org>
    Acked-by: default avatarMichal Hocko <mhocko@suse.cz>
    Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Cc: Glauber Costa <glommer@parallels.com>
    Cc: <stable@kernel.org>		[3.10+]
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    89dc991f
memcontrol.c 185 KB