public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: kernel test robot <oliver.sang@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>,
	Balbir Singh <bsingharora@gmail.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Dan Williams <dan.j.williams@intel.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	Jerome Glisse <jglisse@redhat.com>,
	John Hubbard <jhubbard@nvidia.com>,
	Muchun Song <smuchun@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>, <lkp@lists.01.org>,
	<lkp@intel.com>
Subject: Re: [kernel/resource]  56fd94919b: BUG:KASAN:use-after-free_in__region_intersects
Date: Tue, 11 May 2021 18:28:15 +1000	[thread overview]
Message-ID: <1620740641.H8NWFiPkCk@nvdebian> (raw)
In-Reply-To: <20210511072158.GF8539@xsang-OptiPlex-9020>

I think I see the issue. For some reason when I split the original patch 
series up I inverted the return code for __request_region_locked() but failed 
to do so in __request_free_mem_region(). Additionally hmm_test doesn't always 
check the return code from dmirror_allocate_chunk() which hides the more 
obvious failure resulting in this one which I didn't see on my local setup.

Will post fixes for both of these problems.

 - Alistair

On Tuesday, 11 May 2021 5:21:58 PM AEST kernel test robot wrote:
> Greeting,
> 
> FYI, we noticed the following commit (built with gcc-9):
> 
> commit: 56fd94919b8bfdbe162f78920b4ebc72b4ce2f39 ("kernel/resource: fix 
locking in request_free_mem_region")
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git master
> 
> 
> in testcase: trinity
> version: trinity-x86_64-03f10b67-1_20210507
> with following parameters:
> 
>         number: 99999
>         group: group-01
> 
> test-description: Trinity is a linux system call fuzz tester.
> test-url: http://codemonkey.org.uk/projects/trinity/
> 
> 
> on test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 
16G
> 
> caused below changes (please refer to attached dmesg/kmsg for entire log/
backtrace):
> 
> 
> 
> If you fix the issue, kindly add following tag
> Reported-by: kernel test robot <oliver.sang@intel.com>
> 
> 
> [  148.514812] BUG: KASAN: use-after-free in __region_intersects (kbuild/
src/consumer/kernel/resource.c:516)
> [  148.515030] Read of size 8 at addr ffff8881238c7258 by task swapper/0/1
> [  148.515030]
> [  148.515030] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.12.0-11529-
g56fd94919b8b #1
> [  148.515030] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
1.12.0-1 04/01/2014
> [  148.515030] Call Trace:
> [  148.515030] dump_stack (kbuild/src/consumer/lib/dump_stack.c:122)
> [  148.515030] print_address_description.cold+0x82/0x326
> [  148.515030] ? __region_intersects (kbuild/src/consumer/kernel/resource.c:
516)
> [  148.515030] kasan_report.cold (kbuild/src/consumer/mm/kasan/report.c:420 
kbuild/src/consumer/mm/kasan/report.c:436)
> [  148.515030] ? lock_contended (kbuild/src/consumer/kernel/locking/
lockdep.c:229 kbuild/src/consumer/kernel/locking/lockdep.c:5674 kbuild/src/
consumer/kernel/locking/lockdep.c:5747)
> [  148.515030] ? __region_intersects (kbuild/src/consumer/kernel/resource.c:
516)
> [  148.515030] __region_intersects (kbuild/src/consumer/kernel/resource.c:
516)
> [  148.515030] __request_free_mem_region+0x11b/0x300
> [  148.515030] ? test_stackinit_init (kbuild/src/consumer/lib/test_hmm.c:
1114)
> [  148.515030] dmirror_allocate_chunk (kbuild/src/consumer/lib/test_hmm.c:
468)
> [  148.515030] ? __sanitizer_cov_trace_pc (kbuild/src/consumer/kernel/
kcov.c:197)
> [  148.515030] ? kobject_get (kbuild/src/consumer/lib/kobject.c:662)
> [  148.515030] ? __sanitizer_cov_trace_pc (kbuild/src/consumer/kernel/
kcov.c:197)
> [  148.515030] ? test_stackinit_init (kbuild/src/consumer/lib/test_hmm.c:
1114)
> [  148.515030] hmm_dmirror_init (kbuild/src/consumer/lib/test_hmm.c:1123)
> [  148.515030] do_one_initcall (kbuild/src/consumer/init/main.c:1249)
> [  148.515030] ? perf_trace_initcall_level (kbuild/src/consumer/init/main.c:
1240)
> [  148.515030] ? rcu_read_lock_sched_held (kbuild/src/consumer/kernel/rcu/
update.c:125)
> [  148.515030] ? rcu_read_lock_bh_held (kbuild/src/consumer/kernel/rcu/
update.c:120)
> [  148.515030] ? __kasan_kmalloc (kbuild/src/consumer/mm/kasan/common.c:475 
kbuild/src/consumer/mm/kasan/common.c:516)
> [  148.515030] ? write_comp_data (kbuild/src/consumer/kernel/kcov.c:218)
> [  148.515030] ? __sanitizer_cov_trace_pc (kbuild/src/consumer/kernel/
kcov.c:197)
> [  148.515030] kernel_init_freeable (kbuild/src/consumer/init/main.c:1321 
kbuild/src/consumer/init/main.c:1338 kbuild/src/consumer/init/main.c:1358 
kbuild/src/consumer/init/main.c:1560)
> [  148.515030] ? console_on_rootfs (kbuild/src/consumer/init/main.c:1526)
> [  148.515030] ? tracer_hardirqs_on (kbuild/src/consumer/kernel/trace/
trace_irqsoff.c:57 kbuild/src/consumer/kernel/trace/trace_irqsoff.c:610)
> [  148.515030] ? mark_held_locks (kbuild/src/consumer/kernel/locking/
lockdep.c:4069)
> [  148.515030] ? rest_init (kbuild/src/consumer/init/main.c:1444)
> [  148.515030] kernel_init (kbuild/src/consumer/init/main.c:1449)
> [  148.515030] ret_from_fork (kbuild/src/consumer/arch/x86/entry/entry_64.S:
300)
> [  148.515030]
> [  148.515030] Allocated by task 1:
> [  148.515030] kasan_save_stack (kbuild/src/consumer/mm/kasan/common.c:38)
> [  148.515030] __kasan_kmalloc (kbuild/src/consumer/mm/kasan/common.c:46 
kbuild/src/consumer/mm/kasan/common.c:428 kbuild/src/consumer/mm/kasan/
common.c:507 kbuild/src/consumer/mm/kasan/common.c:516)
> [  148.515030] kmem_cache_alloc_trace (kbuild/src/consumer/mm/slub.c:2941)
> [  148.515030] alloc_resource (kbuild/src/consumer/include/linux/slab.h:556 
kbuild/src/consumer/include/linux/slab.h:686 kbuild/src/consumer/kernel/
resource.c:178)
> [  148.515030] __request_free_mem_region+0x6a/0x300
> [  148.515030] dmirror_allocate_chunk (kbuild/src/consumer/lib/test_hmm.c:
468)
> [  148.515030] hmm_dmirror_init (kbuild/src/consumer/lib/test_hmm.c:1123)
> [  148.515030] do_one_initcall (kbuild/src/consumer/init/main.c:1249)
> [  148.515030] kernel_init_freeable (kbuild/src/consumer/init/main.c:1321 
kbuild/src/consumer/init/main.c:1338 kbuild/src/consumer/init/main.c:1358 
kbuild/src/consumer/init/main.c:1560)
> [  148.515030] kernel_init (kbuild/src/consumer/init/main.c:1449)
> [  148.515030] ret_from_fork (kbuild/src/consumer/arch/x86/entry/entry_64.S:
300)
> [  148.515030]
> [  148.515030] Freed by task 1:
> [  148.515030] kasan_save_stack (kbuild/src/consumer/mm/kasan/common.c:38)
> [  148.515030] kasan_set_track (kbuild/src/consumer/mm/kasan/common.c:46)
> [  148.515030] kasan_set_free_info (kbuild/src/consumer/mm/kasan/generic.c:
359)
> [  148.515030] __kasan_slab_free (kbuild/src/consumer/mm/kasan/common.c:362 
kbuild/src/consumer/mm/kasan/common.c:368)
> [  148.515030] slab_free_freelist_hook (kbuild/src/consumer/mm/slub.c:1606)
> [  148.515030] kfree (kbuild/src/consumer/mm/slub.c:3166 kbuild/src/
consumer/mm/slub.c:4225)
> [  148.515030] free_resource (kbuild/src/consumer/kernel/resource.c:162)
> [  148.515030] __request_free_mem_region+0x161/0x300
> [  148.515030] dmirror_allocate_chunk (kbuild/src/consumer/lib/test_hmm.c:
468)
> [  148.515030] hmm_dmirror_init (kbuild/src/consumer/lib/test_hmm.c:1123)
> [  148.515030] do_one_initcall (kbuild/src/consumer/init/main.c:1249)
> [  148.515030] kernel_init_freeable (kbuild/src/consumer/init/main.c:1321 
kbuild/src/consumer/init/main.c:1338 kbuild/src/consumer/init/main.c:1358 
kbuild/src/consumer/init/main.c:1560)
> [  148.515030] kernel_init (kbuild/src/consumer/init/main.c:1449)
> [  148.515030] ret_from_fork (kbuild/src/consumer/arch/x86/entry/entry_64.S:
300)
> [  148.515030]
> [  148.515030] The buggy address belongs to the object at ffff8881238c7240
> [  148.515030]  which belongs to the cache kmalloc-64 of size 64
> [  148.515030] The buggy address is located 24 bytes inside of
> [  148.515030]  64-byte region [ffff8881238c7240, ffff8881238c7280)
> [  148.515030] The buggy address belongs to the page:
> [  148.515030] page:(____ptrval____) refcount:1 mapcount:0 mapping:
0000000000000000 index:0xffff8881238c6440 pfn:0x1238c6
> [  148.515030] head:(____ptrval____) order:1 compound_mapcount:0
> [  148.515030] flags: 0x17ffffc0010200(slab|head|node=0|zone=2|
lastcpupid=0x1fffff)
> [  148.515030] raw: 0017ffffc0010200 ffff888100040d50 ffff888100040d50 
ffff88810004ce00
> [  148.515030] raw: ffff8881238c6440 000000000010000f 00000001ffffffff 
0000000000000000
> [  148.515030] page dumped because: kasan: bad access detected
> [  148.515030]
> [  148.515030] Memory state around the buggy address:
> [  148.515030]  ffff8881238c7100: fc fc fc fc fc fc fc fc fc fc fc fc fc fc 
fc fc
> [  148.515030]  ffff8881238c7180: fc fc fc fc fc fc fc fc fc fc fc fc fc fc 
fc fc
> [  148.515030] >ffff8881238c7200: fc fc fc fc fc fc fc fc fa fb fb fb fb fb 
fb fb
> [  148.515030]                                                     ^
> [  148.515030]  ffff8881238c7280: fc fc fc fc fc fc fc fc fc fc fc fc fc fc 
fc fc
> [  148.515030]  ffff8881238c7300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc 
fc fc
> [  148.515030] 
==================================================================
> [  148.515030] Disabling lock debugging due to kernel taint
> [  148.690200] HMM test module loaded. This is only for testing HMM.
> [  148.691899] test_free_pages: Testing with GFP_KERNEL
> 
> Kboot worker: lkp-worker29
> Elapsed time: 180
> 
> kvm=(
> qemu-system-x86_64
> -enable-kvm
> -cpu SandyBridge
> -kernel $kernel
> -initrd initrd-vm-snb-123.cgz
> -m 16384
> -smp 2
> -device e1000,netdev=net0
> 
> 
> To reproduce:
> 
>         # build kernel
>         cd linux
>         cp config-5.12.0-11529-g56fd94919b8b .config
>         make HOSTCC=gcc-9 CC=gcc-9 ARCH=x86_64 olddefconfig prepare 
modules_prepare bzImage
> 
>         git clone https://github.com/intel/lkp-tests.git
>         cd lkp-tests
>         bin/lkp qemu -k <bzImage> job-script # job-script is attached in 
this email
> 
> 
> 
> ---
> 0DAY/LKP+ Test Infrastructure                   Open Source Technology 
Center
> https://lists.01.org/hyperkitty/list/lkp@lists.01.org       Intel 
Corporation
> 
> Thanks,
> Oliver Sang
> 





      reply	other threads:[~2021-05-11  8:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11  7:21 [kernel/resource] 56fd94919b: BUG:KASAN:use-after-free_in__region_intersects kernel test robot
2021-05-11  8:28 ` Alistair Popple [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1620740641.H8NWFiPkCk@nvdebian \
    --to=apopple@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=bsingharora@gmail.com \
    --cc=dan.j.williams@intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=david@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jglisse@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=lkp@lists.01.org \
    --cc=oliver.sang@intel.com \
    --cc=smuchun@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox