Skip to content
  • Hugh Dickins's avatar
    ksm: prevent mremap move poisoning · 1ff82995
    Hugh Dickins authored
    
    
    KSM's scan allows for user pages to be COWed or unmapped at any time,
    without requiring any notification.  But its stable tree does assume that
    when it finds a KSM page where it placed a KSM page, then it is the same
    KSM page that it placed there.
    
    mremap move could break that assumption: if an area containing a KSM page
    was unmapped, then an area containing a different KSM page was moved with
    mremap into the place of the original, before KSM's scan came around to
    notice.  That could then poison a node of the stable tree, so that memcmps
    would "lie" and upset the ordering of the tree.
    
    Probably noone will ever need mremap move on a VM_MERGEABLE area; except
    that prohibiting it would make trouble for schemes in which we try making
    everything VM_MERGEABLE e.g.  for testing: an mremap which normally works
    would then fail mysteriously.
    
    There's no need to go to any trouble, such as re-sorting KSM's list of
    rmap_items to match the new layout: simply unmerge the area to COW all its
    KSM pages before moving, but leave VM_MERGEABLE on so that they're
    remerged later.
    
    Signed-off-by: default avatarHugh Dickins <hugh.dickins@tiscali.co.uk>
    Signed-off-by: default avatarChris Wright <chrisw@redhat.com>
    Signed-off-by: default avatarIzik Eidus <ieidus@redhat.com>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Cc: Rik van Riel <riel@redhat.com>
    Cc: Wu Fengguang <fengguang.wu@intel.com>
    Cc: Balbir Singh <balbir@in.ibm.com>
    Cc: Hugh Dickins <hugh.dickins@tiscali.co.uk>
    Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
    Cc: Avi Kivity <avi@redhat.com>
    Cc: Nick Piggin <nickpiggin@yahoo.com.au>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    1ff82995