Skip to content
  1. Dec 13, 2023
    • SeongJae Park's avatar
      mm/damon/core: make damon_start() waits until kdamond_fn() starts · 6376a824
      SeongJae Park authored
      The cleanup tasks of kdamond threads including reset of corresponding
      DAMON context's ->kdamond field and decrease of global nr_running_ctxs
      counter is supposed to be executed by kdamond_fn().  However, commit
      0f91d133 ("mm/damon: simplify stop mechanism") made neither
      damon_start() nor damon_stop() ensure the corresponding kdamond has
      started the execution of kdamond_fn().
      
      As a result, the cleanup can be skipped if damon_stop() is called fast
      enough after the previous damon_start().  Especially the skipped reset
      of ->kdamond could cause a use-after-free.
      
      Fix it by waiting for start of kdamond_fn() execution from
      damon_start().
      
      Link: https://lkml.kernel.org/r/20231208175018.63880-1-sj@kernel.org
      
      
      Fixes: 0f91d133 ("mm/damon: simplify stop mechanism")
      Signed-off-by: default avatarSeongJae Park <sj@kernel.org>
      Reported-by: default avatarJakub Acs <acsjakub@amazon.de>
      Cc: Changbin Du <changbin.du@intel.com>
      Cc: Jakub Acs <acsjakub@amazon.de>
      Cc: <stable@vger.kernel.org> # 5.15.x
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      6376a824
    • David Hildenbrand's avatar
      selftests/mm: cow: print ksft header before printing anything else · a6fcd57c
      David Hildenbrand authored
      Doing a ksft_print_msg() before the ksft_print_header() seems to confuse
      the ksft framework in a strange way: running the test on the cmdline
      results in the expected output.
      
      But piping the output somewhere else, results in some odd output,
      whereby we repeatedly get the same info printed:
      	# [INFO] detected THP size: 2048 KiB
      	# [INFO] detected hugetlb page size: 2048 KiB
      	# [INFO] detected hugetlb page size: 1048576 KiB
      	# [INFO] huge zeropage is enabled
      	TAP version 13
      	1..190
      	# [INFO] Anonymous memory tests in private mappings
      	# [RUN] Basic COW after fork() ... with base page
      	# [INFO] detected THP size: 2048 KiB
      	# [INFO] detected hugetlb page size: 2048 KiB
      	# [INFO] detected hugetlb page size: 1048576 KiB
      	# [INFO] huge zeropage is enabled
      	TAP version 13
      	1..190
      	# [INFO] Anonymous memory tests in private mappings
      	# [RUN] Basic COW after fork() ... with base page
      	ok 1 No leak from parent into child
      	# [RUN] Basic COW after fork() ... with swapped out base page
      	# [INFO] detected THP size: 2048 KiB
      	# [INFO] detected hugetlb page size: 2048 KiB
      	# [INFO] detected hugetlb page size: 1048576 KiB
      	# [INFO] huge zeropage is enabled
      
      Doing the ksft_print_header() first seems to resolve that and gives us
      the output we expect:
      	TAP version 13
      	# [INFO] detected THP size: 2048 KiB
      	# [INFO] detected hugetlb page size: 2048 KiB
      	# [INFO] detected hugetlb page size: 1048576 KiB
      	# [INFO] huge zeropage is enabled
      	1..190
      	# [INFO] Anonymous memory tests in private mappings
      	# [RUN] Basic COW after fork() ... with base page
      	ok 1 No leak from parent into child
      	# [RUN] Basic COW after fork() ... with swapped out base page
      	ok 2 No leak from parent into child
      	# [RUN] Basic COW after fork() ... with THP
      	ok 3 No leak from parent into child
      	# [RUN] Basic COW after fork() ... with swapped-out THP
      	ok 4 No leak from parent into child
      	# [RUN] Basic COW after fork() ... with PTE-mapped THP
      	ok 5 No leak from parent into child
      
      Link: https://lkml.kernel.org/r/20231206103558.38040-1-david@redhat.com
      
      
      Fixes: f4b5fd69 ("selftests/vm: anon_cow: THP tests")
      Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Reported-by: default avatarNico Pache <npache@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      a6fcd57c
    • Kefeng Wang's avatar
      mm: fix VMA heap bounds checking · d3bb89ea
      Kefeng Wang authored
      
      
      After converting selinux to VMA heap check helper, the gcl triggers an
      execheap SELinux denial, which is caused by a changed logic check.
      
      Previously selinux only checked that the VMA range was within the VMA heap
      range, and the implementation checks the intersection between the two
      ranges, but the corner case (vm_end=start_brk, brk=vm_start) isn't handled
      correctly.
      
      Since commit 11250fd1 ("mm: factor out VMA stack and heap checks") was
      only a function extraction, it seems that the issue was introduced by
      commit 0db0c01b ("procfs: fix /proc/<pid>/maps heap check").  Let's
      fix above corner cases, meanwhile, correct the wrong indentation of the
      stack and heap check helpers.
      
      Fixes: 11250fd1 ("mm: factor out VMA stack and heap checks")
      Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
      Reported-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Closes: https://lore.kernel.org/selinux/CAFqZXNv0SVT0fkOK6neP9AXbj3nxJ61JAY4+zJzvxqJaeuhbFw@mail.gmail.com/
      
      
      Tested-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Link: https://lkml.kernel.org/r/20231207152525.2607420-1-wangkefeng.wang@huawei.com
      
      
      Cc: David Hildenbrand <david@redhat.com>
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      d3bb89ea
    • Baoquan He's avatar
      riscv: fix VMALLOC_START definition · ac88ff6b
      Baoquan He authored
      When below config items are set, compiler complained:
      
      --------------------
      CONFIG_CRASH_CORE=y
      CONFIG_KEXEC_CORE=y
      CONFIG_CRASH_DUMP=y
      ......
      -----------------------
      
      -------------------------------------------------------------------
      arch/riscv/kernel/crash_core.c: In function 'arch_crash_save_vmcoreinfo':
      arch/riscv/kernel/crash_core.c:11:58: warning: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'int' [-Wformat=]
      11 |         vmcoreinfo_append_str("NUMBER(VMALLOC_START)=0x%lx\n", VMALLOC_START);
         |                                                        ~~^
         |                                                          |
         |                                                          long unsigned int
         |                                                        %x
      ----------------------------------------------------------------------
      
      This is because on riscv macro VMALLOC_START has different type when
      CONFIG_MMU is set or unset.
      
      arch/riscv/include/asm/pgtable.h:
      --------------------------------------------------
      
      Changing it to _AC(0, UL) in case CONFIG_MMU=n can fix the warning.
      
      Link: https://lkml.kernel.org/r/ZW7OsX4zQRA3mO4+@MiWiFi-R3L-srv
      
      
      Signed-off-by: default avatarBaoquan He <bhe@redhat.com>
      Reported-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Acked-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Tested-by: Randy Dunlap <rdunlap@infradead.org>	# build-tested
      Cc: Eric DeVolder <eric_devolder@yahoo.com>
      Cc: Ignat Korchagin <ignat@cloudflare.com>
      Cc: Stephen Rothwell <sfr@canb.auug.org.au>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Cc: Palmer Dabbelt <palmer@dabbelt.com>
      Cc: Albert Ou <aou@eecs.berkeley.edu>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      ac88ff6b
    • Ignat Korchagin's avatar
      kexec: drop dependency on ARCH_SUPPORTS_KEXEC from CRASH_DUMP · c41bd251
      Ignat Korchagin authored
      In commit f8ff23429c62 ("kernel/Kconfig.kexec: drop select of KEXEC for
      CRASH_DUMP") we tried to fix a config regression, where CONFIG_CRASH_DUMP
      required CONFIG_KEXEC.
      
      However, it was not enough at least for arm64 platforms.  While further
      testing the patch with our arm64 config I noticed that CONFIG_CRASH_DUMP
      is unavailable in menuconfig.  This is because CONFIG_CRASH_DUMP still
      depends on the new CONFIG_ARCH_SUPPORTS_KEXEC introduced in commit
      91506f7e ("arm64/kexec: refactor for kernel/Kconfig.kexec") and on
      arm64 CONFIG_ARCH_SUPPORTS_KEXEC requires CONFIG_PM_SLEEP_SMP=y, which in
      turn requires either CONFIG_SUSPEND=y or CONFIG_HIBERNATION=y neither of
      which are set in our config.
      
      Given that we already established that CONFIG_KEXEC (which is a switch for
      kexec system call itself) is not required for CONFIG_CRASH_DUMP drop
      CONFIG_ARCH_SUPPORTS_KEXEC dependency as well.  The arm64 kernel builds
      just fine with CONFIG_CRASH_DUMP=y and with both CONFIG_KEXEC=n and
      CONFIG_KEXEC_FILE=n after f8ff23429c62 ("kernel/Kconfig.kexec: drop select
      of KEXEC for CRASH_DUMP") and this patch are applied given that the
      necessary shared bits are included via CONFIG_KEXEC_CORE dependency.
      
      [bhe@redhat.com: don't export some symbols when CONFIG_MMU=n]
        Link: https://lkml.kernel.org/r/ZW03ODUKGGhP1ZGU@MiWiFi-R3L-srv
      [bhe@redhat.com: riscv, kexec: fix dependency of two items]
        Link: https://lkml.kernel.org/r/ZW04G/SKnhbE5mnX@MiWiFi-R3L-srv
      Link: https://lkml.kernel.org/r/20231129220409.55006-1-ignat@cloudflare.com
      
      
      Fixes: 91506f7e ("arm64/kexec: refactor for kernel/Kconfig.kexec")
      Signed-off-by: default avatarIgnat Korchagin <ignat@cloudflare.com>
      Signed-off-by: default avatarBaoquan He <bhe@redhat.com>
      Acked-by: default avatarBaoquan He <bhe@redhat.com>
      Cc: Alexander Gordeev <agordeev@linux.ibm.com>
      Cc: <stable@vger.kernel.org> # 6.6+: f8ff234: kernel/Kconfig.kexec: drop select of KEXEC for CRASH_DUMP
      Cc: <stable@vger.kernel.org> # 6.6+
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      c41bd251
  2. Dec 07, 2023
  3. Dec 03, 2023