linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrea Arcangeli <aarcange@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>,
	linux-mm <linux-mm@kvack.org>, Peter Xu <peterx@redhat.com>,
	Mike Rapoport <rppt@linux.ibm.com>, Jann Horn <jannh@google.com>,
	Jason Gunthorpe <jgg@mellanox.com>,
	Michal Hocko <mhocko@suse.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [BUG] kernel BUG at fs/userfaultfd.c:385 after 04f5866e41fb
Date: Thu, 29 Aug 2019 08:05:09 -0400	[thread overview]
Message-ID: <20190829120509.GA14112@redhat.com> (raw)
In-Reply-To: <20190828142544.GB3721@redhat.com>

On Wed, Aug 28, 2019 at 04:25:45PM +0200, Oleg Nesterov wrote:
> I seem to understand... Somehow I thought that __mcopy_atomic() should
> verify that dst_vma->vm_userfaultfd_ctx.ctx is the same ctx which was
> used in userfaultfd_ioctl() but it doesn't, it only checks
> dst_vma->vm_userfaultfd_ctx.ctx != NULL.
> 
> But why?
> 
> (I am just curious, let me repeat I know nothing about userfaultfd).

The ioctl fd only needs to hold an indirect reference to any ctx of
that mm. In other words the only thing the uffd ctx represents in the
UFFDIO_COPY is the destination mm, not the vma.

All the rest is done from the userland parameters of the ioctl
syscall. It's true you could have two uffd registered in the same mm
and you could call the UFFDIO_COPY ioctl on anyone of the two and it
wouldn't make any difference as long as they both are registered in
the same mm.

The uffd ctx in __mcopy_atomic is checked to be not null to be sure
the VM_MAYWRITE check run during uffd registration of the vma, before
we allow to fill any hole into the vma but it's otherwise a refcounting
neutral check.

The uffd ctx refcount in handle_userfault, that may also trigger in
copy-user invoked by the uffd ioctl -> __mcopy_atomic, works like for
any other page fault: by checking vm_userfaultfd_ctx.ctx is not null
while holding the mmap_sem with no association to the uffd ctx
refcount hold by the ioctl (again only needed to obtain the uffd
ctx->mm which is the dst_mm of the UFFDIO_COPY).

There would be nothing wrong to make it more strict, but it's not
strictly needed.

Thanks,
Andrea


  reply	other threads:[~2019-08-29 12:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-13  9:08 [BUG] kernel BUG at fs/userfaultfd.c:385 after 04f5866e41fb 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
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
2019-08-27 16:33 ` [BUG] kernel BUG at fs/userfaultfd.c:385 after 04f5866e41fb Oleg Nesterov
2019-08-27 17:14   ` Andrea Arcangeli
2019-08-28 14:25     ` Oleg Nesterov
2019-08-29 12:05       ` Andrea Arcangeli [this message]
2019-08-30 16:49         ` Oleg Nesterov

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=20190829120509.GA14112@redhat.com \
    --to=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 \
    --cc=wangkefeng.wang@huawei.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
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;
as well as URLs for NNTP newsgroup(s).