Skip to content
Snippets Groups Projects
  1. May 15, 2021
    • Phillip Lougher's avatar
      squashfs: fix divide error in calculate_skip() · d6e621de
      Phillip Lougher authored
      Sysbot has reported a "divide error" which has been identified as being
      caused by a corrupted file_size value within the file inode.  This value
      has been corrupted to a much larger value than expected.
      
      Calculate_skip() is passed i_size_read(inode) >> msblk->block_log.  Due to
      the file_size value corruption this overflows the int argument/variable in
      that function, leading to the divide error.
      
      This patch changes the function to use u64.  This will accommodate any
      unexpectedly large values due to corruption.
      
      The value returned from calculate_skip() is clamped to be never more than
      SQUASHFS_CACHED_BLKS - 1, or 7.  So file_size corruption does not lead to
      an unexpectedly large return result here.
      
      Link: https://lkml.kernel.org/r/20210507152618.9447-1-phillip@squashfs.org.uk
      
      
      Signed-off-by: default avatarPhillip Lougher <phillip@squashfs.org.uk>
      Reported-by: default avatar <syzbot+e8f781243ce16ac2f962@syzkaller.appspotmail.com>
      Reported-by: default avatar <syzbot+7b98870d4fec9447b951@syzkaller.appspotmail.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      d6e621de
    • Alistair Popple's avatar
      kernel/resource: fix return code check in __request_free_mem_region · eb1f065f
      Alistair Popple authored
      Splitting an earlier version of a patch that allowed calling
      __request_region() while holding the resource lock into a series of
      patches required changing the return code for the newly introduced
      __request_region_locked().
      
      Unfortunately this change was not carried through to a subsequent commit
      56fd9491 ("kernel/resource: fix locking in request_free_mem_region")
      in the series.  This resulted in a use-after-free due to freeing the
      struct resource without properly releasing it.  Fix this by correcting the
      return code check so that the struct is not freed if the request to add it
      was successful.
      
      Link: https://lkml.kernel.org/r/20210512073528.22334-1-apopple@nvidia.com
      
      
      Fixes: 56fd9491 ("kernel/resource: fix locking in request_free_mem_region")
      Signed-off-by: default avatarAlistair Popple <apopple@nvidia.com>
      Reported-by: default avatarkernel test robot <oliver.sang@intel.com>
      Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Balbir Singh <bsingharora@gmail.com>
      Cc: Dan Williams <dan.j.williams@intel.com>
      Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jerome Glisse <jglisse@redhat.com>
      Cc: John Hubbard <jhubbard@nvidia.com>
      Cc: Muchun Song <smuchun@gmail.com>
      Cc: Oliver Sang <oliver.sang@intel.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      eb1f065f
    • Vlastimil Babka's avatar
      mm, slub: move slub_debug static key enabling outside slab_mutex · afe0c26d
      Vlastimil Babka authored
      Paul E.  McKenney reported [1] that commit 1f0723a4 ("mm, slub: enable
      slub_debug static key when creating cache with explicit debug flags")
      results in the lockdep complaint:
      
       ======================================================
       WARNING: possible circular locking dependency detected
       5.12.0+ #15 Not tainted
       ------------------------------------------------------
       rcu_torture_sta/109 is trying to acquire lock:
       ffffffff96063cd0 (cpu_hotplug_lock){++++}-{0:0}, at: static_key_enable+0x9/0x20
      
       but task is already holding lock:
       ffffffff96173c28 (slab_mutex){+.+.}-{3:3}, at: kmem_cache_create_usercopy+0x2d/0x250
      
       which lock already depends on the new lock.
      
       the existing dependency chain (in reverse order) is:
      
       -> #1 (slab_mutex){+.+.}-{3:3}:
              lock_acquire+0xb9/0x3a0
              __mutex_lock+0x8d/0x920
              slub_cpu_dead+0x15/0xf0
              cpuhp_invoke_callback+0x17a/0x7c0
              cpuhp_invoke_callback_range+0x3b/0x80
              _cpu_down+0xdf/0x2a0
              cpu_down+0x2c/0x50
              device_offline+0x82/0xb0
              remove_cpu+0x1a/0x30
              torture_offline+0x80/0x140
              torture_onoff+0x147/0x260
              kthread+0x10a/0x140
              ret_from_fork+0x22/0x30
      
       -> #0 (cpu_hotplug_lock){++++}-{0:0}:
              check_prev_add+0x8f/0xbf0
              __lock_acquire+0x13f0/0x1d80
              lock_acquire+0xb9/0x3a0
              cpus_read_lock+0x21/0xa0
              static_key_enable+0x9/0x20
              __kmem_cache_create+0x38d/0x430
              kmem_cache_create_usercopy+0x146/0x250
              kmem_cache_create+0xd/0x10
              rcu_torture_stats+0x79/0x280
              kthread+0x10a/0x140
              ret_from_fork+0x22/0x30
      
       other info that might help us debug this:
      
        Possible unsafe locking scenario:
      
              CPU0                    CPU1
              ----                    ----
         lock(slab_mutex);
                                      lock(cpu_hotplug_lock);
                                      lock(slab_mutex);
         lock(cpu_hotplug_lock);
      
        *** DEADLOCK ***
      
       1 lock held by rcu_torture_sta/109:
        #0: ffffffff96173c28 (slab_mutex){+.+.}-{3:3}, at: kmem_cache_create_usercopy+0x2d/0x250
      
       stack backtrace:
       CPU: 3 PID: 109 Comm: rcu_torture_sta Not tainted 5.12.0+ #15
       Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014
       Call Trace:
        dump_stack+0x6d/0x89
        check_noncircular+0xfe/0x110
        ? lock_is_held_type+0x98/0x110
        check_prev_add+0x8f/0xbf0
        __lock_acquire+0x13f0/0x1d80
        lock_acquire+0xb9/0x3a0
        ? static_key_enable+0x9/0x20
        ? mark_held_locks+0x49/0x70
        cpus_read_lock+0x21/0xa0
        ? static_key_enable+0x9/0x20
        static_key_enable+0x9/0x20
        __kmem_cache_create+0x38d/0x430
        kmem_cache_create_usercopy+0x146/0x250
        ? rcu_torture_stats_print+0xd0/0xd0
        kmem_cache_create+0xd/0x10
        rcu_torture_stats+0x79/0x280
        ? rcu_torture_stats_print+0xd0/0xd0
        kthread+0x10a/0x140
        ? kthread_park+0x80/0x80
        ret_from_fork+0x22/0x30
      
      This is because there's one order of locking from the hotplug callbacks:
      
      lock(cpu_hotplug_lock); // from hotplug machinery itself
      lock(slab_mutex); // in e.g. slab_mem_going_offline_callback()
      
      And commit 1f0723a4 made the reverse sequence possible:
      lock(slab_mutex); // in kmem_cache_create_usercopy()
      lock(cpu_hotplug_lock); // kmem_cache_open() -> static_key_enable()
      
      The simplest fix is to move static_key_enable() to a place before slab_mutex is
      taken. That means kmem_cache_create_usercopy() in mm/slab_common.c which is not
      ideal for SLUB-specific code, but the #ifdef CONFIG_SLUB_DEBUG makes it
      at least self-contained and obvious.
      
      [1] https://lore.kernel.org/lkml/20210502171827.GA3670492@paulmck-ThinkPad-P17-Gen-1/
      
      Link: https://lkml.kernel.org/r/20210504120019.26791-1-vbabka@suse.cz
      
      
      Fixes: 1f0723a4 ("mm, slub: enable slub_debug static key when creating cache with explicit debug flags")
      Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Reported-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      Tested-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      Acked-by: default avatarDavid Rientjes <rientjes@google.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      afe0c26d
    • Peter Xu's avatar
      mm/hugetlb: fix cow where page writtable in child · 84894e1c
      Peter Xu authored
      When rework early cow of pinned hugetlb pages, we moved huge_ptep_get()
      upper but overlooked a side effect that the huge_ptep_get() will fetch the
      pte after wr-protection.  After moving it upwards, we need explicit
      wr-protect of child pte or we will keep the write bit set in the child
      process, which could cause data corrution where the child can write to the
      original page directly.
      
      This issue can also be exposed by "memfd_test hugetlbfs" kselftest.
      
      Link: https://lkml.kernel.org/r/20210503234356.9097-3-peterx@redhat.com
      
      
      Fixes: 4eae4efa ("hugetlb: do early cow when page pinned on src mm")
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: Joel Fernandes (Google) <joel@joelfernandes.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      84894e1c
    • Peter Xu's avatar
      mm/hugetlb: fix F_SEAL_FUTURE_WRITE · 22247efd
      Peter Xu authored
      Patch series "mm/hugetlb: Fix issues on file sealing and fork", v2.
      
      Hugh reported issue with F_SEAL_FUTURE_WRITE not applied correctly to
      hugetlbfs, which I can easily verify using the memfd_test program, which
      seems that the program is hardly run with hugetlbfs pages (as by default
      shmem).
      
      Meanwhile I found another probably even more severe issue on that hugetlb
      fork won't wr-protect child cow pages, so child can potentially write to
      parent private pages.  Patch 2 addresses that.
      
      After this series applied, "memfd_test hugetlbfs" should start to pass.
      
      This patch (of 2):
      
      F_SEAL_FUTURE_WRITE is missing for hugetlb starting from the first day.
      There is a test program for that and it fails constantly.
      
      $ ./memfd_test hugetlbfs
      memfd-hugetlb: CREATE
      memfd-hugetlb: BASIC
      memfd-hugetlb: SEAL-WRITE
      memfd-hugetlb: SEAL-FUTURE-WRITE
      mmap() didn't fail as expected
      Aborted (core dumped)
      
      I think it's probably because no one is really running the hugetlbfs test.
      
      Fix it by checking FUTURE_WRITE also in hugetlbfs_file_mmap() as what we
      do in shmem_mmap().  Generalize a helper for that.
      
      Link: https://lkml.kernel.org/r/20210503234356.9097-1-peterx@redhat.com
      Link: https://lkml.kernel.org/r/20210503234356.9097-2-peterx@redhat.com
      
      
      Fixes: ab3948f5 ("mm/memfd: add an F_SEAL_FUTURE_WRITE seal to memfd")
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Reported-by: default avatarHugh Dickins <hughd@google.com>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Cc: Joel Fernandes (Google) <joel@joelfernandes.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      22247efd
  2. May 14, 2021
    • Linus Torvalds's avatar
      Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux · bd3c9cdb
      Linus Torvalds authored
      Pull arm64 fixes from Catalin Marinas:
       "Fixes and cpucaps.h automatic generation:
      
         - Generate cpucaps.h at build time rather than carrying lots of
           #defines. Merged at -rc1 to avoid some conflicts during the merge
           window.
      
         - Initialise RGSR_EL1.SEED in __cpu_setup() as it may be left as 0
           out of reset and the IRG instruction would not function as expected
           if only the architected pseudorandom number generator is
           implemented.
      
         - Fix potential race condition in __sync_icache_dcache() where the
           PG_dcache_clean page flag is set before the actual cache
           maintenance.
      
         - Fix header include in BTI kselftests"
      
      * tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux:
        arm64: Fix race condition on PG_dcache_clean in __sync_icache_dcache()
        arm64: tools: Add __ASM_CPUCAPS_H to the endif in cpucaps.h
        arm64: mte: initialize RGSR_EL1.SEED in __cpu_setup
        kselftest/arm64: Add missing stddef.h include to BTI tests
        arm64: Generate cpucaps.h
      bd3c9cdb
    • Linus Torvalds's avatar
      Merge tag 'f2fs-5.13-rc1-fix' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs · ac524ece
      Linus Torvalds authored
      Pull f2fs fixes from Jaegeuk Kim:
       "This fixes some critical bugs such as memory leak in compression
        flows, kernel panic when handling errors, and swapon failure due to
        newly added condition check"
      
      * tag 'f2fs-5.13-rc1-fix' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs:
        f2fs: return EINVAL for hole cases in swap file
        f2fs: avoid swapon failure by giving a warning first
        f2fs: compress: fix to assign cc.cluster_idx correctly
        f2fs: compress: fix race condition of overwrite vs truncate
        f2fs: compress: fix to free compress page correctly
        f2fs: support iflag change given the mask
        f2fs: avoid null pointer access when handling IPU error
      ac524ece
    • Linus Torvalds's avatar
      Merge tag 'drm-fixes-2021-05-14' of git://anongit.freedesktop.org/drm/drm · b5304a4f
      Linus Torvalds authored
      Pull drm fixes from Dave Airlie:
       "Not much here, mostly amdgpu fixes, with a couple of radeon, and a
        cosmetic vc4.
      
        Two MAINTAINERS file updates also.
      
        amdgpu:
         - Fixes for flexible array conversions
         - Fix sysfs attribute init
         - Harvesting fixes
         - VCN CG/PG fixes for Picasso
      
        radeon:
         - Fixes for flexible array conversions
         - Fix for flickering on Oland with multiple 4K displays
      
        vc4:
         - drop unused function"
      
      * tag 'drm-fixes-2021-05-14' of git://anongit.freedesktop.org/drm/drm:
        drm/amdgpu: update vcn1.0 Non-DPG suspend sequence
        drm/amdgpu: set vcn mgcg flag for picasso
        drm/radeon/dpm: Disable sclk switching on Oland when two 4K 60Hz monitors are connected
        drm/amdgpu: update the method for harvest IP for specific SKU
        drm/amdgpu: add judgement when add ip blocks (v2)
        drm/amd/display: Initialize attribute for hdcp_srm sysfs file
        drm/amd/pm: Fix out-of-bounds bug
        drm/radeon/si_dpm: Fix SMU power state load
        drm/radeon/ni_dpm: Fix booting bug
        MAINTAINERS: Update address for Emma Anholt
        MAINTAINERS: Update my e-mail
        drm/vc4: remove unused function
        drm/ttm: Do not add non-system domain BO into swap list
      b5304a4f
    • Catalin Marinas's avatar
      arm64: Fix race condition on PG_dcache_clean in __sync_icache_dcache() · 588a513d
      Catalin Marinas authored
      
      To ensure that instructions are observable in a new mapping, the arm64
      set_pte_at() implementation cleans the D-cache and invalidates the
      I-cache to the PoU. As an optimisation, this is only done on executable
      mappings and the PG_dcache_clean page flag is set to avoid future cache
      maintenance on the same page.
      
      When two different processes map the same page (e.g. private executable
      file or shared mapping) there's a potential race on checking and setting
      PG_dcache_clean via set_pte_at() -> __sync_icache_dcache(). While on the
      fault paths the page is locked (PG_locked), mprotect() does not take the
      page lock. The result is that one process may see the PG_dcache_clean
      flag set but the I/D cache maintenance not yet performed.
      
      Avoid test_and_set_bit(PG_dcache_clean) in favour of separate test_bit()
      and set_bit(). In the rare event of a race, the cache maintenance is
      done twice.
      
      Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Cc: <stable@vger.kernel.org>
      Cc: Will Deacon <will@kernel.org>
      Cc: Steven Price <steven.price@arm.com>
      Reviewed-by: default avatarSteven Price <steven.price@arm.com>
      Acked-by: default avatarWill Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20210514095001.13236-1-catalin.marinas@arm.com
      
      
      Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      588a513d
  3. May 13, 2021
  4. May 12, 2021
Loading