1. Oct 19, 2023
    • Haibo Li's avatar
      kasan: print the original fault addr when access invalid shadow · babddbfb
      Haibo Li authored
      when the checked address is illegal,the corresponding shadow address from
      kasan_mem_to_shadow may have no mapping in mmu table.  Access such shadow
      address causes kernel oops.  Here is a sample about oops on arm64(VA
      39bit) with KASAN_SW_TAGS and KASAN_OUTLINE on:
      
      [ffffffb80aaaaaaa] pgd=000000005d3ce003, p4d=000000005d3ce003,
          pud=000000005d3ce003, pmd=0000000000000000
      Internal error: Oops: 0000000096000006 [#1] PREEMPT SMP
      Modules linked in:
      CPU: 3 PID: 100 Comm: sh Not tainted 6.6.0-rc1-dirty #43
      Hardware name: linux,dummy-virt (DT)
      pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
      pc : __hwasan_load8_noabort+0x5c/0x90
      lr : do_ib_ob+0xf4/0x110
      ffffffb80aaaaaaa is the shadow address for efffff80aaaaaaaa.
      The problem is reading invalid shadow in kasan_check_range.
      
      The generic kasan also has similar oops.
      
      It only reports the shadow address which causes oops but not
      the original address.
      
      Commit 2f004eea("x86/kasan: Print original address on #GP")
      introduce to kasan_non_canonical_hook but limit it to KASAN_INLINE.
      
      This patch extends it to KASAN_OUTLINE mode.
      
      Link: https://lkml.kernel.org/r/20231009073748.159228-1-haibo.li@mediatek.com
      Fixes: 2f004eea
      
      ("x86/kasan: Print original address on #GP")
      Signed-off-by: default avatarHaibo Li <haibo.li@mediatek.com>
      Reviewed-by: default avatarAndrey Konovalov <andreyknvl@gmail.com>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
      Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Haibo Li <haibo.li@mediatek.com>
      Cc: Matthias Brugger <matthias.bgg@gmail.com>
      Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Kees Cook <keescook@chromium.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      babddbfb
    • Rik van Riel's avatar
      hugetlbfs: close race between MADV_DONTNEED and page fault · 2820b0f0
      Rik van Riel authored
      Malloc libraries, like jemalloc and tcalloc, take decisions on when to
      call madvise independently from the code in the main application.
      
      This sometimes results in the application page faulting on an address,
      right after the malloc library has shot down the backing memory with
      MADV_DONTNEED.
      
      Usually this is harmless, because we always have some 4kB pages sitting
      around to satisfy a page fault.  However, with hugetlbfs systems often
      allocate only the exact number of huge pages that the application wants.
      
      Due to TLB batching, hugetlbfs MADV_DONTNEED will free pages outside of
      any lock taken on the page fault path, which can open up the following
      race condition:
      
             CPU 1                            CPU 2
      
             MADV_DONTNEED
             unmap page
             shoot down TLB entry
                                             page fault
                                             fail to allocate a huge page
                                             killed with SIGBUS
             free page
      
      Fix that race by pulling the locking from __unmap_hugepage_final_range
      into helper functions called from zap_page_range_single.  This ensures
      page faults stay locked out of the MADV_DONTNEED VMA until the huge pages
      have actually been freed.
      
      Link: https://lkml.kernel.org/r/20231006040020.3677377-4-riel@surriel.com
      Fixes: 04ada095
      
       ("hugetlb: don't delete vma_lock in hugetlb MADV_DONTNEED processing")
      Signed-off-by: default avatarRik van Riel <riel@surriel.com>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Muchun Song <muchun.song@linux.dev>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      2820b0f0
    • Rik van Riel's avatar
      hugetlbfs: extend hugetlb_vma_lock to private VMAs · bf491692
      Rik van Riel authored
      Extend the locking scheme used to protect shared hugetlb mappings from
      truncate vs page fault races, in order to protect private hugetlb mappings
      (with resv_map) against MADV_DONTNEED.
      
      Add a read-write semaphore to the resv_map data structure, and use that
      from the hugetlb_vma_(un)lock_* functions, in preparation for closing the
      race between MADV_DONTNEED and page faults.
      
      Link: https://lkml.kernel.org/r/20231006040020.3677377-3-riel@surriel.com
      Fixes: 04ada095
      
       ("hugetlb: don't delete vma_lock in hugetlb MADV_DONTNEED processing")
      Signed-off-by: default avatarRik van Riel <riel@surriel.com>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Muchun Song <muchun.song@linux.dev>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      bf491692
    • Rik van Riel's avatar
      hugetlbfs: clear resv_map pointer if mmap fails · 92fe9dcb
      Rik van Riel authored
      Patch series "hugetlbfs: close race between MADV_DONTNEED and page fault", v7.
      
      Malloc libraries, like jemalloc and tcalloc, take decisions on when to
      call madvise independently from the code in the main application.
      
      This sometimes results in the application page faulting on an address,
      right after the malloc library has shot down the backing memory with
      MADV_DONTNEED.
      
      Usually this is harmless, because we always have some 4kB pages sitting
      around to satisfy a page fault.  However, with hugetlbfs systems often
      allocate only the exact number of huge pages that the application wants.
      
      Due to TLB batching, hugetlbfs MADV_DONTNEED will free pages outside of
      any lock taken on the page fault path, which can open up the following
      race condition:
      
             CPU 1                            CPU 2
      
             MADV_DONTNEED
             unmap page
             shoot down TLB entry
                                             page fault
                                             fail to allocate a huge page
                                             killed with SIGBUS
             free page
      
      Fix that race by extending the hugetlb_vma_lock locking scheme to also
      cover private hugetlb mappings (with resv_map), and pulling the locking
      from __unmap_hugepage_final_range into helper functions called from
      zap_page_range_single.  This ensures page faults stay locked out of the
      MADV_DONTNEED VMA until the huge pages have actually been freed.
      
      
      This patch (of 3):
      
      Hugetlbfs leaves a dangling pointer in the VMA if mmap fails.  This has
      not been a problem so far, but other code in this patch series tries to
      follow that pointer.
      
      Link: https://lkml.kernel.org/r/20231006040020.3677377-1-riel@surriel.com
      Link: https://lkml.kernel.org/r/20231006040020.3677377-2-riel@surriel.com
      Fixes: 04ada095
      
       ("hugetlb: don't delete vma_lock in hugetlb MADV_DONTNEED processing")
      Signed-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Signed-off-by: default avatarRik van Riel <riel@surriel.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Muchun Song <muchun.song@linux.dev>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      92fe9dcb
    • Johannes Weiner's avatar
      mm: zswap: fix pool refcount bug around shrink_worker() · 969d63e1
      Johannes Weiner authored
      When a zswap store fails due to the limit, it acquires a pool reference
      and queues the shrinker.  When the shrinker runs, it drops the reference. 
      However, there can be multiple store attempts before the shrinker wakes up
      and runs once.  This results in reference leaks and eventual saturation
      warnings for the pool refcount.
      
      Fix this by dropping the reference again when the shrinker is already
      queued.  This ensures one reference per shrinker run.
      
      Link: https://lkml.kernel.org/r/20231006160024.170748-1-hannes@cmpxchg.org
      Fixes: 45190f01
      
       ("mm/zswap.c: add allocation hysteresis if pool limit is hit")
      Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Reported-by: default avatarChris Mason <clm@fb.com>
      Acked-by: default avatarNhat Pham <nphamcs@gmail.com>
      Cc: Vitaly Wool <vitaly.wool@konsulko.com>
      Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
      Cc: <stable@vger.kernel.org>	[5.6+]
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      969d63e1
  2. Oct 07, 2023
  3. Oct 02, 2023
  4. Oct 01, 2023
  5. Sep 30, 2023
    • Baoquan He's avatar
      Crash: add lock to serialize crash hotplug handling · e2a8f20d
      Baoquan He authored
      Eric reported that handling corresponding crash hotplug event can be
      failed easily when many memory hotplug event are notified in a short
      period.  They failed because failing to take __kexec_lock.
      
      =======
      [   78.714569] Fallback order for Node 0: 0
      [   78.714575] Built 1 zonelists, mobility grouping on.  Total pages: 1817886
      [   78.717133] Policy zone: Normal
      [   78.724423] crash hp: kexec_trylock() failed, elfcorehdr may be inaccurate
      [   78.727207] crash hp: kexec_trylock() failed, elfcorehdr may be inaccurate
      [   80.056643] PEFILE: Unsigned PE binary
      =======
      
      The memory hotplug events are notified very quickly and very many, while
      the handling of crash hotplug is much slower relatively.  So the atomic
      variable __kexec_lock and kexec_trylock() can't guarantee the
      serialization of crash hotplug handling.
      
      Here, add a new mutex lock __crash_hotplug_lock to serialize crash hotplug
      handling specifically.  This doesn't impact the usage of __kexec_lock.
      
      Link: https://lkml.kernel.org/r/20230926120905.392903-1-bhe@redhat.com
      Fixes: 24726275
      
       ("crash: add generic infrastructure for crash hotplug support")
      Signed-off-by: default avatarBaoquan He <bhe@redhat.com>
      Tested-by: default avatarEric DeVolder <eric.devolder@oracle.com>
      Reviewed-by: default avatarEric DeVolder <eric.devolder@oracle.com>
      Reviewed-by: default avatarValentin Schneider <vschneid@redhat.com>
      Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      e2a8f20d