From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Xu Subject: Re: [PATCH 3/3] userfaultfd: apply unprivileged_userfaultfd check Date: Mon, 11 Mar 2019 17:58:40 +0800 Message-ID: <20190311095840.GA14108@xz-x1> References: <20190311093701.15734-1-peterx@redhat.com> <20190311093701.15734-4-peterx@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: Paolo Bonzini , Hugh Dickins , Luis Chamberlain , Maxime Coquelin , kvm@vger.kernel.org, Jerome Glisse , Pavel Emelyanov , Johannes Weiner , Martin Cracauer , Denis Plotnikov , linux-mm@kvack.org, Marty McFadden , Maya Gokhale , Mike Kravetz , Andrea Arcangeli , Mike Rapoport , Kees Cook , Mel Gorman , "Kirill A . Shutemov" , linux-fsdevel@vger.kernel.org, "Dr . David Alan Gilbert" Content-Disposition: inline In-Reply-To: <20190311093701.15734-4-peterx@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Mon, Mar 11, 2019 at 05:37:01PM +0800, Peter Xu wrote: > Apply the unprivileged_userfaultfd check when doing userfaultfd > syscall. We didn't check it in other paths of userfaultfd (e.g., the > ioctl() path) because we don't want to drag down the fast path of > userfaultfd, as suggested by Andrea. > > Suggested-by: Andrea Arcangeli > Suggested-by: Mike Rapoport > Signed-off-by: Peter Xu > --- > fs/userfaultfd.c | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c > index c2188464555a..effdcfc88629 100644 > --- a/fs/userfaultfd.c > +++ b/fs/userfaultfd.c > @@ -951,6 +951,28 @@ void userfaultfd_unmap_complete(struct mm_struct *mm, struct list_head *uf) > } > } > > +/* Whether current process allows to use userfaultfd syscalls */ > +static bool userfaultfd_allowed(void) > +{ > + bool allowed = false; > + > + switch (unprivileged_userfaultfd) { > + case UFFD_UNPRIV_ENABLED: > + allowed = true; > + break; > + case UFFD_UNPRIV_KVM: > + allowed = !!test_bit(MMF_USERFAULTFD_ALLOW, > + ¤t->mm->flags); > + /* Fall through */ Sorry I should squash this in otherwise compilation of !CONFIG_KVM will break: diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index effdcfc88629..1b3fa5935643 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -960,10 +960,12 @@ static bool userfaultfd_allowed(void) case UFFD_UNPRIV_ENABLED: allowed = true; break; +#if IS_ENABLED(CONFIG_KVM) case UFFD_UNPRIV_KVM: allowed = !!test_bit(MMF_USERFAULTFD_ALLOW, ¤t->mm->flags); /* Fall through */ +#endif case UFFD_UNPRIV_DISABLED: allowed = allowed || ns_capable(current_user_ns(), CAP_SYS_PTRACE); Will wait for more comments before I repost. Sorry for the noise. Regards, -- Peter Xu