• Mike Kravetz's avatar
    ipc/shm: call underlying open/close vm_ops · b6305049
    Mike Kravetz authored
    Shared memory segments can be created that are backed by hugetlb pages. 
    When this happens, the vmas associated with any mappings (shmat) are
    marked VM_HUGETLB, yet the vm_ops for such mappings are provided by
    ipc/shm (shm_vm_ops).  There is a mechanism to call the underlying hugetlb
    vm_ops, and this is done for most operations.  However, it is not done for
    open and close.
    
    This was not an issue until the introduction of the hugetlb vma_lock. 
    This lock structure is pointed to by vm_private_data and the open/close
    vm_ops help maintain this structure.  The special hugetlb routine called
    at fork took care of structure updates at fork time.  However,
    vma_splitting is not properly handled for ipc shared memory mappings
    backed by hugetlb pages.  This can result in a "kernel NULL pointer
    dereference" BUG or use after free as two vmas point to the same lock
    structure.
    
    Update the shm open and close routines to always call the underlying open
    and close routines.
    
    Link: https://lkml.kernel.org/r/20221114210018.49346-1-mike.kravetz@oracle.com
    Fixes: 8d9bfb26 ("hugetlb: add vma based lock for pmd sharing")
    Signed-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
    Reported-by: default avatarDoug Nelson <doug.nelson@intel.com>
    Reported-by: <syzbot+83b4134621b7c326d950@syzkaller.appspotmail.com>
    Cc: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
    Cc: "Eric W . Biederman" <ebiederm@xmission.com>
    Cc: Manfred Spraul <manfred@colorfullife.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Miaohe Lin <linmiaohe@huawei.com>
    Cc: Michal Hocko <mhocko@suse.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    b6305049
shm.c 45.1 KB