Linux-mm Archive on lore.kernel.org
 help / color / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Michal Hocko <mhocko@suse.com>, linux-mm <linux-mm@kvack.org>,
	"Andrea Arcangeli" <aarcange@redhat.com>,
	Peter Xu <peterx@redhat.com>, Mike Rapoport <rppt@linux.ibm.com>,
	Jann Horn <jannh@google.com>, Jason Gunthorpe <jgg@mellanox.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [BUG] kernel BUG at fs/userfaultfd.c:385 after 04f5866e41fb
Date: Fri, 16 Aug 2019 18:37:52 +0800
Message-ID: <3b521a8c-586f-251e-f486-d71ff094b8e9@huawei.com> (raw)
In-Reply-To: <20190815095409.GC32051@redhat.com>



On 2019/8/15 17:54, Oleg Nesterov wrote:
> On 08/15, Kefeng Wang wrote:
>>
>> On 2019/8/14 23:41, Oleg Nesterov wrote:
>>>
>>> Heh, I didn't notice you too mentioned userfaultfd_release() in your email.
>>> can you try the patch below?
>>
>> Your patch below fixes the issue, could you send a formal patch ASAP and also it
>> should be queued into stable, I have test lts4.4, it works too, thanks.
> 
> Thanks.
> 
> Yes, I _think_ we need something like this patch anyway, but it needs more
> discussion. And it is not clear if it really fixes this issue or it hides
> another bug.
> 

OK, hope more specialists notice this issue and comment it.

> 
>> I built kernel with wrong gcc version, and the KASAN is not enabled, When KASAN enabled,
>> there is an UAF,
>>
>> [   67.393442] ==================================================================
>> [   67.395531] BUG: KASAN: use-after-free in handle_userfault+0x12f/0xc70
>> [   67.397001] Read of size 8 at addr ffff8883c622c160 by task syz-executor.9/5225
> 
> OK, thanks this probably confirms that .ctx points to nowhere because it
> was freed by userfaultfd_release() without clearing vm_flags/userfaultfd_ctx.

The patch do fix the UAF and avoid panic, and it doesn't seem to cause new issue,
even if there are some another issue, it can be fixed later :)

> 
> But,
> 
>> [   67.430243] RIP: 0010:copy_user_handle_tail+0x2/0x10
>> [   67.431586] Code: c3 0f 1f 80 00 00 00 00 66 66 90 83 fa 40 0f 82 70 ff ff ff 89 d1 f3 a4 31 c0 66 66 90 c3 66 2e 0f 1f 84 00 00 00 00 00 89 d1 <f3> a4 89 c8 66 66 90 c3 66 0f 1f 44 00 00 66 66 90 83 fa 08 0f 82
>> [   67.436978] RSP: 0018:ffff8883c4e8f908 EFLAGS: 00010246
>> [   67.438743] RAX: 0000000000000001 RBX: 0000000020ffd000 RCX: 0000000000001000
>> [   67.441101] RDX: 0000000000001000 RSI: 0000000020ffd000 RDI: ffff8883c0aa4000
>> [   67.442865] RBP: 0000000000001000 R08: ffffed1078154a00 R09: 0000000000000000
>> [   67.444534] R10: 0000000000000200 R11: ffffed10781549ff R12: ffff8883c0aa4000
>> [   67.446216] R13: ffff8883c6096000 R14: ffff88837721f838 R15: ffff8883c6096000
>> [   67.448388]  _copy_from_user+0xa1/0xd0
>> [   67.449655]  mcopy_atomic+0xb3d/0x1380
>> [   67.450991]  ? lock_downgrade+0x3a0/0x3a0
>> [   67.452337]  ? mm_alloc_pmd+0x130/0x130
>> [   67.453618]  ? __might_fault+0x7d/0xe0
>> [   67.454980]  userfaultfd_ioctl+0x14a2/0x1c30
> 
> This must not be called after __fput(). So I think there is something else,
> may by just an unbalanced userfaultfd_ctx_put(). I dunno, I know nothing
> about usefaultfd.

There are different processes, maybe some concurrency problems.

> 
> It would be nice to understand what this reproducer does...

I tried strace -f the reproducer, but can't find any useful info.

> 
> Oleg.
> 
> 
> .
> 



  reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-13  9:08 Kefeng Wang
2019-08-14 13:53 ` Michal Hocko
2019-08-14 14:45   ` Kefeng Wang
2019-08-14 15:10     ` Oleg Nesterov
2019-08-14 15:41       ` Oleg Nesterov
2019-08-15  2:21         ` Kefeng Wang
2019-08-15  9:54           ` Oleg Nesterov
2019-08-16 10:37             ` Kefeng Wang [this message]
2019-08-19 12:48               ` Oleg Nesterov
2019-08-19 16:05         ` Andrea Arcangeli
2019-08-20 15:59           ` Oleg Nesterov
2019-08-20 16:15             ` Andrea Arcangeli
     [not found]           ` <73d7b5b1-a88c-5fca-ba16-be214c2524a4@I-love.SAKURA.ne.jp>
2019-08-20 16:09             ` Oleg Nesterov
2019-08-20 16:02 ` [PATCH] userfaultfd_release: always remove uffd flags and clear vm_userfaultfd_ctx Oleg Nesterov
2019-08-20 16:05   ` Andrea Arcangeli
2019-08-21  0:53   ` Kefeng Wang

Reply instructions:

You may reply publically 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=3b521a8c-586f-251e-f486-d71ff094b8e9@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=jannh@google.com \
    --cc=jgg@mellanox.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=oleg@redhat.com \
    --cc=peterx@redhat.com \
    --cc=rppt@linux.ibm.com \
    /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

Linux-mm Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mm/0 linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ https://lore.kernel.org/linux-mm \
		linux-mm@kvack.org linux-mm@archiver.kernel.org
	public-inbox-index linux-mm


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kvack.linux-mm


AGPL code for this site: git clone https://public-inbox.org/ public-inbox