1. 12 9月, 2022 1 次提交
  2. 17 6月, 2022 7 次提交
  3. 16 4月, 2022 1 次提交
    • P
      mm: kmemleak: take a full lowmem check in kmemleak_*_phys() · 23c2d497
      Patrick Wang 提交于
      The kmemleak_*_phys() apis do not check the address for lowmem's min
      boundary, while the caller may pass an address below lowmem, which will
      trigger an oops:
      
        # echo scan > /sys/kernel/debug/kmemleak
        Unable to handle kernel paging request at virtual address ff5fffffffe00000
        Oops [#1]
        Modules linked in:
        CPU: 2 PID: 134 Comm: bash Not tainted 5.18.0-rc1-next-20220407 #33
        Hardware name: riscv-virtio,qemu (DT)
        epc : scan_block+0x74/0x15c
         ra : scan_block+0x72/0x15c
        epc : ffffffff801e5806 ra : ffffffff801e5804 sp : ff200000104abc30
         gp : ffffffff815cd4e8 tp : ff60000004cfa340 t0 : 0000000000000200
         t1 : 00aaaaaac23954cc t2 : 00000000000003ff s0 : ff200000104abc90
         s1 : ffffffff81b0ff28 a0 : 0000000000000000 a1 : ff5fffffffe01000
         a2 : ffffffff81b0ff28 a3 : 0000000000000002 a4 : 0000000000000001
         a5 : 0000000000000000 a6 : ff200000104abd7c a7 : 0000000000000005
         s2 : ff5fffffffe00ff9 s3 : ffffffff815cd998 s4 : ffffffff815d0e90
         s5 : ffffffff81b0ff28 s6 : 0000000000000020 s7 : ffffffff815d0eb0
         s8 : ffffffffffffffff s9 : ff5fffffffe00000 s10: ff5fffffffe01000
         s11: 0000000000000022 t3 : 00ffffffaa17db4c t4 : 000000000000000f
         t5 : 0000000000000001 t6 : 0000000000000000
        status: 0000000000000100 badaddr: ff5fffffffe00000 cause: 000000000000000d
          scan_gray_list+0x12e/0x1a6
          kmemleak_scan+0x2aa/0x57e
          kmemleak_write+0x32a/0x40c
          full_proxy_write+0x56/0x82
          vfs_write+0xa6/0x2a6
          ksys_write+0x6c/0xe2
          sys_write+0x22/0x2a
          ret_from_syscall+0x0/0x2
      
      The callers may not quite know the actual address they pass(e.g. from
      devicetree).  So the kmemleak_*_phys() apis should guarantee the address
      they finally use is in lowmem range, so check the address for lowmem's
      min boundary.
      
      Link: https://lkml.kernel.org/r/20220413122925.33856-1-patrick.wang.shcn@gmail.comSigned-off-by: NPatrick Wang <patrick.wang.shcn@gmail.com>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      23c2d497
  4. 02 4月, 2022 1 次提交
    • K
      mm/kmemleak: reset tag when compare object pointer · bfc8089f
      Kuan-Ying Lee 提交于
      When we use HW-tag based kasan and enable vmalloc support, we hit the
      following bug.  It is due to comparison between tagged object and
      non-tagged pointer.
      
      We need to reset the kasan tag when we need to compare tagged object and
      non-tagged pointer.
      
        kmemleak: [name:kmemleak&]Scan area larger than object 0xffffffe77076f440
        CPU: 4 PID: 1 Comm: init Tainted: G S      W         5.15.25-android13-0-g5cacf919c2bc #1
        Hardware name: MT6983(ENG) (DT)
        Call trace:
         add_scan_area+0xc4/0x244
         kmemleak_scan_area+0x40/0x9c
         layout_and_allocate+0x1e8/0x288
         load_module+0x2c8/0xf00
         __se_sys_finit_module+0x190/0x1d0
         __arm64_sys_finit_module+0x20/0x30
         invoke_syscall+0x60/0x170
         el0_svc_common+0xc8/0x114
         do_el0_svc+0x28/0xa0
         el0_svc+0x60/0xf8
         el0t_64_sync_handler+0x88/0xec
         el0t_64_sync+0x1b4/0x1b8
        kmemleak: [name:kmemleak&]Object 0xf5ffffe77076b000 (size 32768):
        kmemleak: [name:kmemleak&]  comm "init", pid 1, jiffies 4294894197
        kmemleak: [name:kmemleak&]  min_count = 0
        kmemleak: [name:kmemleak&]  count = 0
        kmemleak: [name:kmemleak&]  flags = 0x1
        kmemleak: [name:kmemleak&]  checksum = 0
        kmemleak: [name:kmemleak&]  backtrace:
             module_alloc+0x9c/0x120
             move_module+0x34/0x19c
             layout_and_allocate+0x1c4/0x288
             load_module+0x2c8/0xf00
             __se_sys_finit_module+0x190/0x1d0
             __arm64_sys_finit_module+0x20/0x30
             invoke_syscall+0x60/0x170
             el0_svc_common+0xc8/0x114
             do_el0_svc+0x28/0xa0
             el0_svc+0x60/0xf8
             el0t_64_sync_handler+0x88/0xec
             el0t_64_sync+0x1b4/0x1b8
      
      Link: https://lkml.kernel.org/r/20220318034051.30687-1-Kuan-Ying.Lee@mediatek.comSigned-off-by: NKuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
      Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: Matthias Brugger <matthias.bgg@gmail.com>
      Cc: Chinwen Chang <chinwen.chang@mediatek.com>
      Cc: Nicholas Tang <nicholas.tang@mediatek.com>
      Cc: Yee Lee <yee.lee@mediatek.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      bfc8089f
  5. 05 2月, 2022 1 次提交
    • L
      mm/kmemleak: avoid scanning potential huge holes · c10a0f87
      Lang Yu 提交于
      When using devm_request_free_mem_region() and devm_memremap_pages() to
      add ZONE_DEVICE memory, if requested free mem region's end pfn were
      huge(e.g., 0x400000000), the node_end_pfn() will be also huge (see
      move_pfn_range_to_zone()).  Thus it creates a huge hole between
      node_start_pfn() and node_end_pfn().
      
      We found on some AMD APUs, amdkfd requested such a free mem region and
      created a huge hole.  In such a case, following code snippet was just
      doing busy test_bit() looping on the huge hole.
      
        for (pfn = start_pfn; pfn < end_pfn; pfn++) {
      	struct page *page = pfn_to_online_page(pfn);
      		if (!page)
      			continue;
      	...
        }
      
      So we got a soft lockup:
      
        watchdog: BUG: soft lockup - CPU#6 stuck for 26s! [bash:1221]
        CPU: 6 PID: 1221 Comm: bash Not tainted 5.15.0-custom #1
        RIP: 0010:pfn_to_online_page+0x5/0xd0
        Call Trace:
          ? kmemleak_scan+0x16a/0x440
          kmemleak_write+0x306/0x3a0
          ? common_file_perm+0x72/0x170
          full_proxy_write+0x5c/0x90
          vfs_write+0xb9/0x260
          ksys_write+0x67/0xe0
          __x64_sys_write+0x1a/0x20
          do_syscall_64+0x3b/0xc0
          entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      I did some tests with the patch.
      
      (1) amdgpu module unloaded
      
      before the patch:
      
        real    0m0.976s
        user    0m0.000s
        sys     0m0.968s
      
      after the patch:
      
        real    0m0.981s
        user    0m0.000s
        sys     0m0.973s
      
      (2) amdgpu module loaded
      
      before the patch:
      
        real    0m35.365s
        user    0m0.000s
        sys     0m35.354s
      
      after the patch:
      
        real    0m1.049s
        user    0m0.000s
        sys     0m1.042s
      
      Link: https://lkml.kernel.org/r/20211108140029.721144-1-lang.yu@amd.comSigned-off-by: NLang Yu <lang.yu@amd.com>
      Acked-by: NDavid Hildenbrand <david@redhat.com>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c10a0f87
  6. 15 1月, 2022 1 次提交
    • K
      kmemleak: fix kmemleak false positive report with HW tag-based kasan enable · ad1a3e15
      Kuan-Ying Lee 提交于
      With HW tag-based kasan enable, We will get the warning when we free
      object whose address starts with 0xFF.
      
      It is because kmemleak rbtree stores tagged object and this freeing
      object's tag does not match with rbtree object.
      
      In the example below, kmemleak rbtree stores the tagged object in the
      kmalloc(), and kfree() gets the pointer with 0xFF tag.
      
      Call sequence:
          ptr = kmalloc(size, GFP_KERNEL);
          page = virt_to_page(ptr);
          offset = offset_in_page(ptr);
          kfree(page_address(page) + offset);
          ptr = kmalloc(size, GFP_KERNEL);
      
      A sequence like that may cause the warning as following:
      
       1) Freeing unknown object:
      
          In kfree(), we will get free unknown object warning in
          kmemleak_free(). Because object(0xFx) in kmemleak rbtree and
          pointer(0xFF) in kfree() have different tag.
      
       2) Overlap existing:
      
          When we allocate that object with the same hw-tag again, we will
          find the overlap in the kmemleak rbtree and kmemleak thread will be
          killed.
      
      	kmemleak: Freeing unknown object at 0xffff000003f88000
      	CPU: 5 PID: 177 Comm: cat Not tainted 5.16.0-rc1-dirty #21
      	Hardware name: linux,dummy-virt (DT)
      	Call trace:
      	 dump_backtrace+0x0/0x1ac
      	 show_stack+0x1c/0x30
      	 dump_stack_lvl+0x68/0x84
      	 dump_stack+0x1c/0x38
      	 kmemleak_free+0x6c/0x70
      	 slab_free_freelist_hook+0x104/0x200
      	 kmem_cache_free+0xa8/0x3d4
      	 test_version_show+0x270/0x3a0
      	 module_attr_show+0x28/0x40
      	 sysfs_kf_seq_show+0xb0/0x130
      	 kernfs_seq_show+0x30/0x40
      	 seq_read_iter+0x1bc/0x4b0
      	 seq_read_iter+0x1bc/0x4b0
      	 kernfs_fop_read_iter+0x144/0x1c0
      	 generic_file_splice_read+0xd0/0x184
      	 do_splice_to+0x90/0xe0
      	 splice_direct_to_actor+0xb8/0x250
      	 do_splice_direct+0x88/0xd4
      	 do_sendfile+0x2b0/0x344
      	 __arm64_sys_sendfile64+0x164/0x16c
      	 invoke_syscall+0x48/0x114
      	 el0_svc_common.constprop.0+0x44/0xec
      	 do_el0_svc+0x74/0x90
      	 el0_svc+0x20/0x80
      	 el0t_64_sync_handler+0x1a8/0x1b0
      	 el0t_64_sync+0x1ac/0x1b0
      	...
      	kmemleak: Cannot insert 0xf2ff000003f88000 into the object search tree (overlaps existing)
      	CPU: 5 PID: 178 Comm: cat Not tainted 5.16.0-rc1-dirty #21
      	Hardware name: linux,dummy-virt (DT)
      	Call trace:
      	 dump_backtrace+0x0/0x1ac
      	 show_stack+0x1c/0x30
      	 dump_stack_lvl+0x68/0x84
      	 dump_stack+0x1c/0x38
      	 create_object.isra.0+0x2d8/0x2fc
      	 kmemleak_alloc+0x34/0x40
      	 kmem_cache_alloc+0x23c/0x2f0
      	 test_version_show+0x1fc/0x3a0
      	 module_attr_show+0x28/0x40
      	 sysfs_kf_seq_show+0xb0/0x130
      	 kernfs_seq_show+0x30/0x40
      	 seq_read_iter+0x1bc/0x4b0
      	 kernfs_fop_read_iter+0x144/0x1c0
      	 generic_file_splice_read+0xd0/0x184
      	 do_splice_to+0x90/0xe0
      	 splice_direct_to_actor+0xb8/0x250
      	 do_splice_direct+0x88/0xd4
      	 do_sendfile+0x2b0/0x344
      	 __arm64_sys_sendfile64+0x164/0x16c
      	 invoke_syscall+0x48/0x114
      	 el0_svc_common.constprop.0+0x44/0xec
      	 do_el0_svc+0x74/0x90
      	 el0_svc+0x20/0x80
      	 el0t_64_sync_handler+0x1a8/0x1b0
      	 el0t_64_sync+0x1ac/0x1b0
      	kmemleak: Kernel memory leak detector disabled
      	kmemleak: Object 0xf2ff000003f88000 (size 128):
      	kmemleak:   comm "cat", pid 177, jiffies 4294921177
      	kmemleak:   min_count = 1
      	kmemleak:   count = 0
      	kmemleak:   flags = 0x1
      	kmemleak:   checksum = 0
      	kmemleak:   backtrace:
      	     kmem_cache_alloc+0x23c/0x2f0
      	     test_version_show+0x1fc/0x3a0
      	     module_attr_show+0x28/0x40
      	     sysfs_kf_seq_show+0xb0/0x130
      	     kernfs_seq_show+0x30/0x40
      	     seq_read_iter+0x1bc/0x4b0
      	     kernfs_fop_read_iter+0x144/0x1c0
      	     generic_file_splice_read+0xd0/0x184
      	     do_splice_to+0x90/0xe0
      	     splice_direct_to_actor+0xb8/0x250
      	     do_splice_direct+0x88/0xd4
      	     do_sendfile+0x2b0/0x344
      	     __arm64_sys_sendfile64+0x164/0x16c
      	     invoke_syscall+0x48/0x114
      	     el0_svc_common.constprop.0+0x44/0xec
      	     do_el0_svc+0x74/0x90
      	kmemleak: Automatic memory scanning thread ended
      
      [akpm@linux-foundation.org: whitespace tweak]
      
      Link: https://lkml.kernel.org/r/20211118054426.4123-1-Kuan-Ying.Lee@mediatek.comSigned-off-by: NKuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
      Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: Doug Berger <opendmb@gmail.com>
      Cc: Mel Gorman <mgorman@techsingularity.net>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      ad1a3e15
  7. 09 9月, 2021 2 次提交
    • N
      mm/kmemleak: allow __GFP_NOLOCKDEP passed to kmemleak's gfp · 79d37050
      Naohiro Aota 提交于
      In a memory pressure situation, I'm seeing the lockdep WARNING below.
      Actually, this is similar to a known false positive which is already
      addressed by commit 6dcde60e ("xfs: more lockdep whackamole with
      kmem_alloc*").
      
      This warning still persists because it's not from kmalloc() itself but
      from an allocation for kmemleak object.  While kmalloc() itself suppress
      the warning with __GFP_NOLOCKDEP, gfp_kmemleak_mask() is dropping the
      flag for the kmemleak's allocation.
      
      Allow __GFP_NOLOCKDEP to be passed to kmemleak's allocation, so that the
      warning for it is also suppressed.
      
        ======================================================
        WARNING: possible circular locking dependency detected
        5.14.0-rc7-BTRFS-ZNS+ #37 Not tainted
        ------------------------------------------------------
        kswapd0/288 is trying to acquire lock:
        ffff88825ab45df0 (&xfs_nondir_ilock_class){++++}-{3:3}, at: xfs_ilock+0x8a/0x250
      
        but task is already holding lock:
        ffffffff848cc1e0 (fs_reclaim){+.+.}-{0:0}, at: __fs_reclaim_acquire+0x5/0x30
      
        which lock already depends on the new lock.
      
        the existing dependency chain (in reverse order) is:
      
        -> #1 (fs_reclaim){+.+.}-{0:0}:
               fs_reclaim_acquire+0x112/0x160
               kmem_cache_alloc+0x48/0x400
               create_object.isra.0+0x42/0xb10
               kmemleak_alloc+0x48/0x80
               __kmalloc+0x228/0x440
               kmem_alloc+0xd3/0x2b0
               kmem_alloc_large+0x5a/0x1c0
               xfs_attr_copy_value+0x112/0x190
               xfs_attr_shortform_getvalue+0x1fc/0x300
               xfs_attr_get_ilocked+0x125/0x170
               xfs_attr_get+0x329/0x450
               xfs_get_acl+0x18d/0x430
               get_acl.part.0+0xb6/0x1e0
               posix_acl_xattr_get+0x13a/0x230
               vfs_getxattr+0x21d/0x270
               getxattr+0x126/0x310
               __x64_sys_fgetxattr+0x1a6/0x2a0
               do_syscall_64+0x3b/0x90
               entry_SYSCALL_64_after_hwframe+0x44/0xae
      
        -> #0 (&xfs_nondir_ilock_class){++++}-{3:3}:
               __lock_acquire+0x2c0f/0x5a00
               lock_acquire+0x1a1/0x4b0
               down_read_nested+0x50/0x90
               xfs_ilock+0x8a/0x250
               xfs_can_free_eofblocks+0x34f/0x570
               xfs_inactive+0x411/0x520
               xfs_fs_destroy_inode+0x2c8/0x710
               destroy_inode+0xc5/0x1a0
               evict+0x444/0x620
               dispose_list+0xfe/0x1c0
               prune_icache_sb+0xdc/0x160
               super_cache_scan+0x31e/0x510
               do_shrink_slab+0x337/0x8e0
               shrink_slab+0x362/0x5c0
               shrink_node+0x7a7/0x1a40
               balance_pgdat+0x64e/0xfe0
               kswapd+0x590/0xa80
               kthread+0x38c/0x460
               ret_from_fork+0x22/0x30
      
        other info that might help us debug this:
         Possible unsafe locking scenario:
               CPU0                    CPU1
               ----                    ----
          lock(fs_reclaim);
                                       lock(&xfs_nondir_ilock_class);
                                       lock(fs_reclaim);
          lock(&xfs_nondir_ilock_class);
      
         *** DEADLOCK ***
        3 locks held by kswapd0/288:
         #0: ffffffff848cc1e0 (fs_reclaim){+.+.}-{0:0}, at: __fs_reclaim_acquire+0x5/0x30
         #1: ffffffff848a08d8 (shrinker_rwsem){++++}-{3:3}, at: shrink_slab+0x269/0x5c0
         #2: ffff8881a7a820e8 (&type->s_umount_key#60){++++}-{3:3}, at: super_cache_scan+0x5a/0x510
      
      Link: https://lkml.kernel.org/r/20210907055659.3182992-1-naohiro.aota@wdc.comSigned-off-by: NNaohiro Aota <naohiro.aota@wdc.com>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: "Darrick J . Wong" <djwong@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      79d37050
    • C
      mm: in_irq() cleanup · ea0eafea
      Changbin Du 提交于
      Replace the obsolete and ambiguos macro in_irq() with new macro
      in_hardirq().
      
      Link: https://lkml.kernel.org/r/20210813145245.86070-1-changbin.du@gmail.comSigned-off-by: NChangbin Du <changbin.du@gmail.com>
      Acked-by: Catalin Marinas <catalin.marinas@arm.com>	[kmemleak]
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      ea0eafea
  8. 14 8月, 2021 1 次提交
    • K
      kasan, kmemleak: reset tags when scanning block · 6c7a00b8
      Kuan-Ying Lee 提交于
      Patch series "kasan, slub: reset tag when printing address", v3.
      
      With hardware tag-based kasan enabled, we reset the tag when we access
      metadata to avoid from false alarm.
      
      This patch (of 2):
      
      Kmemleak needs to scan kernel memory to check memory leak.  With hardware
      tag-based kasan enabled, when it scans on the invalid slab and
      dereference, the issue will occur as below.
      
      Hardware tag-based KASAN doesn't use compiler instrumentation, we can not
      use kasan_disable_current() to ignore tag check.
      
      Based on the below report, there are 11 0xf7 granules, which amounts to
      176 bytes, and the object is allocated from the kmalloc-256 cache.  So
      when kmemleak accesses the last 256-176 bytes, it causes faults, as those
      are marked with KASAN_KMALLOC_REDZONE == KASAN_TAG_INVALID == 0xfe.
      
      Thus, we reset tags before accessing metadata to avoid from false positives.
      
        BUG: KASAN: out-of-bounds in scan_block+0x58/0x170
        Read at addr f7ff0000c0074eb0 by task kmemleak/138
        Pointer tag: [f7], memory tag: [fe]
      
        CPU: 7 PID: 138 Comm: kmemleak Not tainted 5.14.0-rc2-00001-g8cae8cd8-dirty #134
        Hardware name: linux,dummy-virt (DT)
        Call trace:
         dump_backtrace+0x0/0x1b0
         show_stack+0x1c/0x30
         dump_stack_lvl+0x68/0x84
         print_address_description+0x7c/0x2b4
         kasan_report+0x138/0x38c
         __do_kernel_fault+0x190/0x1c4
         do_tag_check_fault+0x78/0x90
         do_mem_abort+0x44/0xb4
         el1_abort+0x40/0x60
         el1h_64_sync_handler+0xb4/0xd0
         el1h_64_sync+0x78/0x7c
         scan_block+0x58/0x170
         scan_gray_list+0xdc/0x1a0
         kmemleak_scan+0x2ac/0x560
         kmemleak_scan_thread+0xb0/0xe0
         kthread+0x154/0x160
         ret_from_fork+0x10/0x18
      
        Allocated by task 0:
         kasan_save_stack+0x2c/0x60
         __kasan_kmalloc+0xec/0x104
         __kmalloc+0x224/0x3c4
         __register_sysctl_paths+0x200/0x290
         register_sysctl_table+0x2c/0x40
         sysctl_init+0x20/0x34
         proc_sys_init+0x3c/0x48
         proc_root_init+0x80/0x9c
         start_kernel+0x648/0x6a4
         __primary_switched+0xc0/0xc8
      
        Freed by task 0:
         kasan_save_stack+0x2c/0x60
         kasan_set_track+0x2c/0x40
         kasan_set_free_info+0x44/0x54
         ____kasan_slab_free.constprop.0+0x150/0x1b0
         __kasan_slab_free+0x14/0x20
         slab_free_freelist_hook+0xa4/0x1fc
         kfree+0x1e8/0x30c
         put_fs_context+0x124/0x220
         vfs_kern_mount.part.0+0x60/0xd4
         kern_mount+0x24/0x4c
         bdev_cache_init+0x70/0x9c
         vfs_caches_init+0xdc/0xf4
         start_kernel+0x638/0x6a4
         __primary_switched+0xc0/0xc8
      
        The buggy address belongs to the object at ffff0000c0074e00
         which belongs to the cache kmalloc-256 of size 256
        The buggy address is located 176 bytes inside of
         256-byte region [ffff0000c0074e00, ffff0000c0074f00)
        The buggy address belongs to the page:
        page:(____ptrval____) refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x100074
        head:(____ptrval____) order:2 compound_mapcount:0 compound_pincount:0
        flags: 0xbfffc0000010200(slab|head|node=0|zone=2|lastcpupid=0xffff|kasantag=0x0)
        raw: 0bfffc0000010200 0000000000000000 dead000000000122 f5ff0000c0002300
        raw: 0000000000000000 0000000000200020 00000001ffffffff 0000000000000000
        page dumped because: kasan: bad access detected
      
        Memory state around the buggy address:
         ffff0000c0074c00: f0 f0 f0 f0 f0 f0 f0 f0 f0 fe fe fe fe fe fe fe
         ffff0000c0074d00: fe fe fe fe fe fe fe fe fe fe fe fe fe fe fe fe
        >ffff0000c0074e00: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 fe fe fe fe fe
                                                            ^
         ffff0000c0074f00: fe fe fe fe fe fe fe fe fe fe fe fe fe fe fe fe
         ffff0000c0075000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
        ==================================================================
        Disabling lock debugging due to kernel taint
        kmemleak: 181 new suspected memory leaks (see /sys/kernel/debug/kmemleak)
      
      Link: https://lkml.kernel.org/r/20210804090957.12393-1-Kuan-Ying.Lee@mediatek.com
      Link: https://lkml.kernel.org/r/20210804090957.12393-2-Kuan-Ying.Lee@mediatek.comSigned-off-by: NKuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Reviewed-by: NAndrey Konovalov <andreyknvl@gmail.com>
      Cc: Marco Elver <elver@google.com>
      Cc: Nicholas Tang <nicholas.tang@mediatek.com>
      Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Chinwen Chang <chinwen.chang@mediatek.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      6c7a00b8
  9. 30 6月, 2021 1 次提交
  10. 01 5月, 2021 1 次提交
  11. 26 3月, 2021 1 次提交
  12. 14 10月, 2020 1 次提交
  13. 15 8月, 2020 1 次提交
    • Q
      mm/kmemleak: silence KCSAN splats in checksum · 69d0b54d
      Qian Cai 提交于
      Even if KCSAN is disabled for kmemleak, update_checksum() could still call
      crc32() (which is outside of kmemleak.c) to dereference object->pointer.
      Thus, the value of object->pointer could be accessed concurrently as
      noticed by KCSAN,
      
       BUG: KCSAN: data-race in crc32_le_base / do_raw_spin_lock
      
       write to 0xffffb0ea683a7d50 of 4 bytes by task 23575 on cpu 12:
        do_raw_spin_lock+0x114/0x200
        debug_spin_lock_after at kernel/locking/spinlock_debug.c:91
        (inlined by) do_raw_spin_lock at kernel/locking/spinlock_debug.c:115
        _raw_spin_lock+0x40/0x50
        __handle_mm_fault+0xa9e/0xd00
        handle_mm_fault+0xfc/0x2f0
        do_page_fault+0x263/0x6f9
        page_fault+0x34/0x40
      
       read to 0xffffb0ea683a7d50 of 4 bytes by task 839 on cpu 60:
        crc32_le_base+0x67/0x350
        crc32_le_base+0x67/0x350:
        crc32_body at lib/crc32.c:106
        (inlined by) crc32_le_generic at lib/crc32.c:179
        (inlined by) crc32_le at lib/crc32.c:197
        kmemleak_scan+0x528/0xd90
        update_checksum at mm/kmemleak.c:1172
        (inlined by) kmemleak_scan at mm/kmemleak.c:1497
        kmemleak_scan_thread+0xcc/0xfa
        kthread+0x1e0/0x200
        ret_from_fork+0x27/0x50
      
      If a shattered value was returned due to a data race, it will be corrected
      in the next scan.  Thus, let KCSAN ignore all reads in the region to
      silence KCSAN in case the write side is non-atomic.
      Suggested-by: NMarco Elver <elver@google.com>
      Signed-off-by: NQian Cai <cai@lca.pw>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Acked-by: NMarco Elver <elver@google.com>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Link: http://lkml.kernel.org/r/20200317182754.2180-1-cai@lca.pwSigned-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      69d0b54d
  14. 03 4月, 2020 1 次提交
  15. 01 2月, 2020 1 次提交
  16. 14 10月, 2019 1 次提交
  17. 25 9月, 2019 4 次提交
  18. 14 8月, 2019 1 次提交
  19. 03 8月, 2019 1 次提交
    • Y
      Revert "kmemleak: allow to coexist with fault injection" · df9576de
      Yang Shi 提交于
      When running ltp's oom test with kmemleak enabled, the below warning was
      triggerred since kernel detects __GFP_NOFAIL & ~__GFP_DIRECT_RECLAIM is
      passed in:
      
        WARNING: CPU: 105 PID: 2138 at mm/page_alloc.c:4608 __alloc_pages_nodemask+0x1c31/0x1d50
        Modules linked in: loop dax_pmem dax_pmem_core ip_tables x_tables xfs virtio_net net_failover virtio_blk failover ata_generic virtio_pci virtio_ring virtio libata
        CPU: 105 PID: 2138 Comm: oom01 Not tainted 5.2.0-next-20190710+ #7
        Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.2-0-g5f4c7b1-prebuilt.qemu-project.org 04/01/2014
        RIP: 0010:__alloc_pages_nodemask+0x1c31/0x1d50
        ...
         kmemleak_alloc+0x4e/0xb0
         kmem_cache_alloc+0x2a7/0x3e0
         mempool_alloc_slab+0x2d/0x40
         mempool_alloc+0x118/0x2b0
         bio_alloc_bioset+0x19d/0x350
         get_swap_bio+0x80/0x230
         __swap_writepage+0x5ff/0xb20
      
      The mempool_alloc_slab() clears __GFP_DIRECT_RECLAIM, however kmemleak
      has __GFP_NOFAIL set all the time due to d9570ee3 ("kmemleak:
      allow to coexist with fault injection").  But, it doesn't make any sense
      to have __GFP_NOFAIL and ~__GFP_DIRECT_RECLAIM specified at the same
      time.
      
      According to the discussion on the mailing list, the commit should be
      reverted for short term solution.  Catalin Marinas would follow up with
      a better solution for longer term.
      
      The failure rate of kmemleak metadata allocation may increase in some
      circumstances, but this should be expected side effect.
      
      Link: http://lkml.kernel.org/r/1563299431-111710-1-git-send-email-yang.shi@linux.alibaba.com
      Fixes: d9570ee3 ("kmemleak: allow to coexist with fault injection")
      Signed-off-by: NYang Shi <yang.shi@linux.alibaba.com>
      Suggested-by: NCatalin Marinas <catalin.marinas@arm.com>
      Acked-by: NMichal Hocko <mhocko@suse.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Qian Cai <cai@lca.pw>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      df9576de
  20. 13 7月, 2019 2 次提交
    • A
      mm/kmemleak.c: change error at _write when kmemleak is disabled · 4e4dfce2
      André Almeida 提交于
      According to POSIX, EBUSY means that the "device or resource is busy", and
      this can lead to people thinking that the file
      `/sys/kernel/debug/kmemleak/` is somehow locked or being used by other
      process.  Change this error code to a more appropriate one.
      
      Link: http://lkml.kernel.org/r/20190612155231.19448-1-andrealmeid@collabora.comSigned-off-by: NAndré Almeida <andrealmeid@collabora.com>
      Reviewed-by: NAndrew Morton <akpm@linux-foundation.org>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      4e4dfce2
    • D
      mm/kmemleak.c: fix check for softirq context · 6ef90569
      Dmitry Vyukov 提交于
      in_softirq() is a wrong predicate to check if we are in a softirq
      context.  It also returns true if we have BH disabled, so objects are
      falsely stamped with "softirq" comm.  The correct predicate is
      in_serving_softirq().
      
      If user does cat from /sys/kernel/debug/kmemleak previously they would
      see this, which is clearly wrong, this is system call context (see the
      comm):
      
      unreferenced object 0xffff88805bd661c0 (size 64):
        comm "softirq", pid 0, jiffies 4294942959 (age 12.400s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00  ................
          00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
        backtrace:
          [<0000000007dcb30c>] kmemleak_alloc_recursive include/linux/kmemleak.h:55 [inline]
          [<0000000007dcb30c>] slab_post_alloc_hook mm/slab.h:439 [inline]
          [<0000000007dcb30c>] slab_alloc mm/slab.c:3326 [inline]
          [<0000000007dcb30c>] kmem_cache_alloc_trace+0x13d/0x280 mm/slab.c:3553
          [<00000000969722b7>] kmalloc include/linux/slab.h:547 [inline]
          [<00000000969722b7>] kzalloc include/linux/slab.h:742 [inline]
          [<00000000969722b7>] ip_mc_add1_src net/ipv4/igmp.c:1961 [inline]
          [<00000000969722b7>] ip_mc_add_src+0x36b/0x400 net/ipv4/igmp.c:2085
          [<00000000a4134b5f>] ip_mc_msfilter+0x22d/0x310 net/ipv4/igmp.c:2475
          [<00000000d20248ad>] do_ip_setsockopt.isra.0+0x19fe/0x1c00 net/ipv4/ip_sockglue.c:957
          [<000000003d367be7>] ip_setsockopt+0x3b/0xb0 net/ipv4/ip_sockglue.c:1246
          [<000000003c7c76af>] udp_setsockopt+0x4e/0x90 net/ipv4/udp.c:2616
          [<000000000c1aeb23>] sock_common_setsockopt+0x3e/0x50 net/core/sock.c:3130
          [<000000000157b92b>] __sys_setsockopt+0x9e/0x120 net/socket.c:2078
          [<00000000a9f3d058>] __do_sys_setsockopt net/socket.c:2089 [inline]
          [<00000000a9f3d058>] __se_sys_setsockopt net/socket.c:2086 [inline]
          [<00000000a9f3d058>] __x64_sys_setsockopt+0x26/0x30 net/socket.c:2086
          [<000000001b8da885>] do_syscall_64+0x7c/0x1a0 arch/x86/entry/common.c:301
          [<00000000ba770c62>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      now they will see this:
      
      unreferenced object 0xffff88805413c800 (size 64):
        comm "syz-executor.4", pid 8960, jiffies 4294994003 (age 14.350s)
        hex dump (first 32 bytes):
          00 7a 8a 57 80 88 ff ff e0 00 00 01 00 00 00 00  .z.W............
          00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000c5d3be64>] kmemleak_alloc_recursive include/linux/kmemleak.h:55 [inline]
          [<00000000c5d3be64>] slab_post_alloc_hook mm/slab.h:439 [inline]
          [<00000000c5d3be64>] slab_alloc mm/slab.c:3326 [inline]
          [<00000000c5d3be64>] kmem_cache_alloc_trace+0x13d/0x280 mm/slab.c:3553
          [<0000000023865be2>] kmalloc include/linux/slab.h:547 [inline]
          [<0000000023865be2>] kzalloc include/linux/slab.h:742 [inline]
          [<0000000023865be2>] ip_mc_add1_src net/ipv4/igmp.c:1961 [inline]
          [<0000000023865be2>] ip_mc_add_src+0x36b/0x400 net/ipv4/igmp.c:2085
          [<000000003029a9d4>] ip_mc_msfilter+0x22d/0x310 net/ipv4/igmp.c:2475
          [<00000000ccd0a87c>] do_ip_setsockopt.isra.0+0x19fe/0x1c00 net/ipv4/ip_sockglue.c:957
          [<00000000a85a3785>] ip_setsockopt+0x3b/0xb0 net/ipv4/ip_sockglue.c:1246
          [<00000000ec13c18d>] udp_setsockopt+0x4e/0x90 net/ipv4/udp.c:2616
          [<0000000052d748e3>] sock_common_setsockopt+0x3e/0x50 net/core/sock.c:3130
          [<00000000512f1014>] __sys_setsockopt+0x9e/0x120 net/socket.c:2078
          [<00000000181758bc>] __do_sys_setsockopt net/socket.c:2089 [inline]
          [<00000000181758bc>] __se_sys_setsockopt net/socket.c:2086 [inline]
          [<00000000181758bc>] __x64_sys_setsockopt+0x26/0x30 net/socket.c:2086
          [<00000000d4b73623>] do_syscall_64+0x7c/0x1a0 arch/x86/entry/common.c:301
          [<00000000c1098bec>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Link: http://lkml.kernel.org/r/20190517171507.96046-1-dvyukov@gmail.comSigned-off-by: NDmitry Vyukov <dvyukov@google.com>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      6ef90569
  21. 05 6月, 2019 1 次提交
  22. 03 6月, 2019 1 次提交
  23. 29 4月, 2019 1 次提交
    • T
      mm/kmemleak: Simplify stacktrace handling · 07984aad
      Thomas Gleixner 提交于
      Replace the indirection through struct stack_trace by using the storage
      array based interfaces.
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: linux-mm@kvack.org
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: kasan-dev@googlegroups.com
      Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
      Cc: Akinobu Mita <akinobu.mita@gmail.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: iommu@lists.linux-foundation.org
      Cc: Robin Murphy <robin.murphy@arm.com>
      Cc: Marek Szyprowski <m.szyprowski@samsung.com>
      Cc: Johannes Thumshirn <jthumshirn@suse.de>
      Cc: David Sterba <dsterba@suse.com>
      Cc: Chris Mason <clm@fb.com>
      Cc: Josef Bacik <josef@toxicpanda.com>
      Cc: linux-btrfs@vger.kernel.org
      Cc: dm-devel@redhat.com
      Cc: Mike Snitzer <snitzer@redhat.com>
      Cc: Alasdair Kergon <agk@redhat.com>
      Cc: Daniel Vetter <daniel@ffwll.ch>
      Cc: intel-gfx@lists.freedesktop.org
      Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
      Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
      Cc: dri-devel@lists.freedesktop.org
      Cc: David Airlie <airlied@linux.ie>
      Cc: Jani Nikula <jani.nikula@linux.intel.com>
      Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
      Cc: Tom Zanussi <tom.zanussi@linux.intel.com>
      Cc: Miroslav Benes <mbenes@suse.cz>
      Cc: linux-arch@vger.kernel.org
      Link: https://lkml.kernel.org/r/20190425094801.863716911@linutronix.de
      07984aad
  24. 20 4月, 2019 1 次提交
  25. 06 4月, 2019 1 次提交
  26. 22 2月, 2019 1 次提交
  27. 29 12月, 2018 2 次提交
  28. 31 10月, 2018 1 次提交