• Jaewon Kim's avatar
    mm/page_ext.c: check if page_ext is not prepared · e492080e
    Jaewon Kim authored
    online_page_ext() and page_ext_init() allocate page_ext for each
    section, but they do not allocate if the first PFN is !pfn_present(pfn)
    or !pfn_valid(pfn).  Then section->page_ext remains as NULL.
    lookup_page_ext checks NULL only if CONFIG_DEBUG_VM is enabled.  For a
    valid PFN, __set_page_owner will try to get page_ext through
    lookup_page_ext.  Without CONFIG_DEBUG_VM lookup_page_ext will misuse
    NULL pointer as value 0.  This incurrs invalid address access.
    This is the panic example when PFN 0x100000 is not valid but PFN
    0x13FC00 is being used for page_ext.  section->page_ext is NULL,
    get_entry returned invalid page_ext address as 0x1DFA000 for a PFN
    To avoid this panic, CONFIG_DEBUG_VM should be removed so that page_ext
    will be checked at all times.
      Unable to handle kernel paging request at virtual address 01dfa014
      ------------[ cut here ]------------
      Kernel BUG at ffffff80082371e0 [verbose debug info unavailable]
      Internal error: Oops: 96000045 [#1] PREEMPT SMP
      Modules linked in:
      PC is at __set_page_owner+0x48/0x78
      LR is at __set_page_owner+0x44/0x78
    Pre-4.7 kernels also need commit f86e4271 ("mm: check the return
    value of lookup_page_ext for all call sites").
    Link: http://lkml.kernel.org/r/20171107094131.14621-1-jaewon31.kim@samsung.com
    Fixes: eefa864b ("mm/page_ext: resurrect struct page extending code for debugging")
    Signed-off-by: default avatarJaewon Kim <jaewon31.kim@samsung.com>
    Acked-by: default avatarMichal Hocko <mhocko@suse.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: Minchan Kim <minchan@kernel.org>
    Cc: Joonsoo Kim <js1304@gmail.com>
    Cc: <stable@vger.kernel.org>	[depends on f86e4271, see above]
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>