• yanghui's avatar
    mm/mempolicy: fix a race between offset_il_node and mpol_rebind_task · 02cd61fa
    yanghui authored
    commit 276aeee1 upstream.
    
    Servers happened below panic:
    
      Kernel version:5.4.56
      BUG: unable to handle page fault for address: 0000000000002c48
      RIP: 0010:__next_zones_zonelist+0x1d/0x40
      Call Trace:
        __alloc_pages_nodemask+0x277/0x310
        alloc_page_interleave+0x13/0x70
        handle_mm_fault+0xf99/0x1390
        __do_page_fault+0x288/0x500
        do_page_fault+0x30/0x110
        page_fault+0x3e/0x50
    
    The reason for the panic is that MAX_NUMNODES is passed in the third
    parameter in __alloc_pages_nodemask(preferred_nid).  So access to
    zonelist->zoneref->zone_idx in __next_zones_zonelist will cause a panic.
    
    In offset_il_node(), first_node() returns nid from pol->v.nodes, after
    this other threads may chang pol->v.nodes before next_node().  This race
    condition will let next_node return MAX_NUMNODES.  So put pol->nodes in
    a local variable.
    
    The race condition is between offset_il_node and cpuset_change_task_nodemas...
    02cd61fa
mempolicy.c 75 KB