All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: "Christian König" <ckoenig.leichtzumerken@gmail.com>,
	"Christian König" <christian.koenig@amd.com>,
	"DRI Development" <dri-devel@lists.freedesktop.org>,
	"Intel Graphics Development" <intel-gfx@lists.freedesktop.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	"John Stultz" <john.stultz@linaro.org>,
	"Daniel Vetter" <daniel.vetter@intel.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org
Subject: Re: [Linaro-mm-sig] Re: [PATCH] dma-buf: Require VM_PFNMAP vma for mmap
Date: Wed, 23 Nov 2022 17:22:50 +0100	[thread overview]
Message-ID: <CAKMK7uEXybD3iV7dDjcaP=joY-kE8aZZ5odCsjUBpatJe=Sd=Q@mail.gmail.com> (raw)
In-Reply-To: <Y342emkzKHXLQvsN@ziepe.ca>

On Wed, 23 Nov 2022 at 16:04, Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Wed, Nov 23, 2022 at 03:28:27PM +0100, Daniel Vetter wrote:
>
> > > This patch is known to be broken in so many ways. It also has a major
> > > security hole that it ignores the PTE flags making the page
> > > RO. Ignoring the special bit is somehow not surprising :(
> > >
> > > This probably doesn't work, but is the general idea of what KVM needs
> > > to do:
> >
> > Oh dear, when I dug around in there I entirely missed that
> > kvm_try_get_pfn exists, and it's very broken indeed. kvm really needs
> > to grow a proper mmu notifier.
> >
> > Another thing I'm wondering right now, the follow_pte();
> > fixup_user_fault(); follow_pte(); approach does not make any
> > guarantees of actually being right. If you're sufficiently unlucky you
> > might race against an immediate pte invalidate between the fixup and
> > the 2nd follow_pte(). But you can also not loop, because that would
> > fail to catch permanent faults.
>
> Yes, it is pretty broken.
>
> kvm already has support for mmu notifiers and uses it for other
> stuff. I can't remember what exactly this code path was for, IIRC
> Paolo talked about having a big rework/fix for it when we last talked
> about the missing write protect. I also vauagely recall he had some
> explanation why this might be safe.
>
> > I think the iommu fault drivers have a similar pattern.
>
> Where? It shouldn't
>
> The common code for SVA just calls handle_mm_fault() and restarts the
> PRI. Since the page table is physically shared there is no issue with
> a stale copy.
>
> > What am I missing here? Or is that also just broken. gup works around
> > this with the slow path that takes the mmap sem and walking the vma
> > tree, follow_pte/fixup_user_fautl users dont.
>
> follow_pte() is just fundamentally broken, things must not use it.
>
> > Maybe mmu notifier based restarting would help with this too, if
> > done properly.
>
> That is called hmm_range_fault()

Ah right I mixed that up on a quick grep, thanks for pointing me in
the right direction. Worries appeased.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: "Christian König" <ckoenig.leichtzumerken@gmail.com>,
	"Intel Graphics Development" <intel-gfx@lists.freedesktop.org>,
	"DRI Development" <dri-devel@lists.freedesktop.org>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	linaro-mm-sig@lists.linaro.org,
	"John Stultz" <john.stultz@linaro.org>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Daniel Vetter" <daniel.vetter@intel.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Christian König" <christian.koenig@amd.com>,
	linux-media@vger.kernel.org
Subject: Re: [Linaro-mm-sig] Re: [PATCH] dma-buf: Require VM_PFNMAP vma for mmap
Date: Wed, 23 Nov 2022 17:22:50 +0100	[thread overview]
Message-ID: <CAKMK7uEXybD3iV7dDjcaP=joY-kE8aZZ5odCsjUBpatJe=Sd=Q@mail.gmail.com> (raw)
In-Reply-To: <Y342emkzKHXLQvsN@ziepe.ca>

On Wed, 23 Nov 2022 at 16:04, Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Wed, Nov 23, 2022 at 03:28:27PM +0100, Daniel Vetter wrote:
>
> > > This patch is known to be broken in so many ways. It also has a major
> > > security hole that it ignores the PTE flags making the page
> > > RO. Ignoring the special bit is somehow not surprising :(
> > >
> > > This probably doesn't work, but is the general idea of what KVM needs
> > > to do:
> >
> > Oh dear, when I dug around in there I entirely missed that
> > kvm_try_get_pfn exists, and it's very broken indeed. kvm really needs
> > to grow a proper mmu notifier.
> >
> > Another thing I'm wondering right now, the follow_pte();
> > fixup_user_fault(); follow_pte(); approach does not make any
> > guarantees of actually being right. If you're sufficiently unlucky you
> > might race against an immediate pte invalidate between the fixup and
> > the 2nd follow_pte(). But you can also not loop, because that would
> > fail to catch permanent faults.
>
> Yes, it is pretty broken.
>
> kvm already has support for mmu notifiers and uses it for other
> stuff. I can't remember what exactly this code path was for, IIRC
> Paolo talked about having a big rework/fix for it when we last talked
> about the missing write protect. I also vauagely recall he had some
> explanation why this might be safe.
>
> > I think the iommu fault drivers have a similar pattern.
>
> Where? It shouldn't
>
> The common code for SVA just calls handle_mm_fault() and restarts the
> PRI. Since the page table is physically shared there is no issue with
> a stale copy.
>
> > What am I missing here? Or is that also just broken. gup works around
> > this with the slow path that takes the mmap sem and walking the vma
> > tree, follow_pte/fixup_user_fautl users dont.
>
> follow_pte() is just fundamentally broken, things must not use it.
>
> > Maybe mmu notifier based restarting would help with this too, if
> > done properly.
>
> That is called hmm_range_fault()

Ah right I mixed that up on a quick grep, thanks for pointing me in
the right direction. Worries appeased.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: "Christian König" <ckoenig.leichtzumerken@gmail.com>,
	"Intel Graphics Development" <intel-gfx@lists.freedesktop.org>,
	"DRI Development" <dri-devel@lists.freedesktop.org>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	linaro-mm-sig@lists.linaro.org,
	"John Stultz" <john.stultz@linaro.org>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Daniel Vetter" <daniel.vetter@intel.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Christian König" <christian.koenig@amd.com>,
	linux-media@vger.kernel.org
Subject: Re: [Intel-gfx] [Linaro-mm-sig] Re: [PATCH] dma-buf: Require VM_PFNMAP vma for mmap
Date: Wed, 23 Nov 2022 17:22:50 +0100	[thread overview]
Message-ID: <CAKMK7uEXybD3iV7dDjcaP=joY-kE8aZZ5odCsjUBpatJe=Sd=Q@mail.gmail.com> (raw)
In-Reply-To: <Y342emkzKHXLQvsN@ziepe.ca>

On Wed, 23 Nov 2022 at 16:04, Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Wed, Nov 23, 2022 at 03:28:27PM +0100, Daniel Vetter wrote:
>
> > > This patch is known to be broken in so many ways. It also has a major
> > > security hole that it ignores the PTE flags making the page
> > > RO. Ignoring the special bit is somehow not surprising :(
> > >
> > > This probably doesn't work, but is the general idea of what KVM needs
> > > to do:
> >
> > Oh dear, when I dug around in there I entirely missed that
> > kvm_try_get_pfn exists, and it's very broken indeed. kvm really needs
> > to grow a proper mmu notifier.
> >
> > Another thing I'm wondering right now, the follow_pte();
> > fixup_user_fault(); follow_pte(); approach does not make any
> > guarantees of actually being right. If you're sufficiently unlucky you
> > might race against an immediate pte invalidate between the fixup and
> > the 2nd follow_pte(). But you can also not loop, because that would
> > fail to catch permanent faults.
>
> Yes, it is pretty broken.
>
> kvm already has support for mmu notifiers and uses it for other
> stuff. I can't remember what exactly this code path was for, IIRC
> Paolo talked about having a big rework/fix for it when we last talked
> about the missing write protect. I also vauagely recall he had some
> explanation why this might be safe.
>
> > I think the iommu fault drivers have a similar pattern.
>
> Where? It shouldn't
>
> The common code for SVA just calls handle_mm_fault() and restarts the
> PRI. Since the page table is physically shared there is no issue with
> a stale copy.
>
> > What am I missing here? Or is that also just broken. gup works around
> > this with the slow path that takes the mmap sem and walking the vma
> > tree, follow_pte/fixup_user_fautl users dont.
>
> follow_pte() is just fundamentally broken, things must not use it.
>
> > Maybe mmu notifier based restarting would help with this too, if
> > done properly.
>
> That is called hmm_range_fault()

Ah right I mixed that up on a quick grep, thanks for pointing me in
the right direction. Worries appeased.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

  reply	other threads:[~2022-11-23 16:23 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 17:08 [PATCH] dma-buf: Require VM_PFNMAP vma for mmap Daniel Vetter
2022-11-22 17:08 ` [Intel-gfx] " Daniel Vetter
2022-11-22 17:08 ` Daniel Vetter
2022-11-22 18:03 ` Jason Gunthorpe
2022-11-22 18:03   ` Jason Gunthorpe
2022-11-22 18:08   ` Daniel Vetter
2022-11-22 18:08     ` [Intel-gfx] " Daniel Vetter
2022-11-22 18:08     ` Daniel Vetter
2022-11-22 18:50     ` Jason Gunthorpe
2022-11-22 18:50       ` Jason Gunthorpe
2022-11-22 19:29       ` Daniel Vetter
2022-11-22 19:29         ` [Intel-gfx] " Daniel Vetter
2022-11-22 19:29         ` Daniel Vetter
2022-11-22 19:34         ` Jason Gunthorpe
2022-11-22 19:34           ` Jason Gunthorpe
2022-11-22 19:50           ` Daniel Vetter
2022-11-22 19:50             ` [Intel-gfx] " Daniel Vetter
2022-11-22 19:50             ` Daniel Vetter
2022-11-23  9:06             ` Christian König
2022-11-23  9:06               ` Christian König
2022-11-23  9:06               ` [Intel-gfx] " Christian König
2022-11-23  9:30               ` Daniel Vetter
2022-11-23  9:30                 ` Daniel Vetter
2022-11-23  9:30                 ` [Intel-gfx] " Daniel Vetter
2022-11-23  9:39                 ` [Linaro-mm-sig] " Christian König
2022-11-23  9:39                   ` Christian König
2022-11-23  9:39                   ` [Intel-gfx] " Christian König
2022-11-23 10:06                   ` Daniel Vetter
2022-11-23 10:06                     ` Daniel Vetter
2022-11-23 10:06                     ` [Intel-gfx] " Daniel Vetter
2022-11-23 12:46                     ` Jason Gunthorpe
2022-11-23 12:46                       ` Jason Gunthorpe
2022-11-23 12:49                       ` Christian König
2022-11-23 12:49                         ` Christian König
2022-11-23 12:49                         ` [Intel-gfx] " Christian König
2022-11-23 12:53                         ` Jason Gunthorpe
2022-11-23 12:53                           ` Jason Gunthorpe
2022-11-23 13:12                           ` Christian König
2022-11-23 13:12                             ` Christian König
2022-11-23 13:12                             ` [Intel-gfx] " Christian König
2022-11-23 13:28                             ` Jason Gunthorpe
2022-11-23 13:28                               ` Jason Gunthorpe
2022-11-23 14:28                               ` Daniel Vetter
2022-11-23 14:28                                 ` Daniel Vetter
2022-11-23 14:28                                 ` [Intel-gfx] " Daniel Vetter
2022-11-23 15:04                                 ` Jason Gunthorpe
2022-11-23 15:04                                   ` Jason Gunthorpe
2022-11-23 16:22                                   ` Daniel Vetter [this message]
2022-11-23 16:22                                     ` [Intel-gfx] " Daniel Vetter
2022-11-23 16:22                                     ` Daniel Vetter
2022-11-23 14:34                               ` Daniel Vetter
2022-11-23 14:34                                 ` [Intel-gfx] " Daniel Vetter
2022-11-23 14:34                                 ` Daniel Vetter
2022-11-23 15:08                                 ` Jason Gunthorpe
2022-11-23 15:08                                   ` Jason Gunthorpe
2022-11-23 15:15                                   ` Christian König
2022-11-23 15:15                                     ` [Intel-gfx] " Christian König
2022-11-23 15:15                                     ` Christian König
2022-11-23 16:26                                     ` Daniel Vetter
2022-11-23 16:26                                       ` [Intel-gfx] " Daniel Vetter
2022-11-23 16:26                                       ` Daniel Vetter
2022-11-23 16:26                                     ` Jason Gunthorpe
2022-11-23 16:26                                       ` Jason Gunthorpe
2022-11-22 19:43 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for " Patchwork
2022-11-22 20:08 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-11-23  8:07 ` [PATCH] " Thomas Zimmermann
2022-11-23  8:07   ` [Intel-gfx] " Thomas Zimmermann
2022-11-23  8:07   ` Thomas Zimmermann
2022-11-23  9:33   ` Daniel Vetter
2022-11-23  9:33     ` Daniel Vetter
2022-11-23  9:33     ` [Intel-gfx] " Daniel Vetter
2022-11-23  9:58 ` [Intel-gfx] ✗ Fi.CI.IGT: failure for " Patchwork

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='CAKMK7uEXybD3iV7dDjcaP=joY-kE8aZZ5odCsjUBpatJe=Sd=Q@mail.gmail.com' \
    --to=daniel.vetter@ffwll.ch \
    --cc=christian.koenig@amd.com \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jgg@ziepe.ca \
    --cc=john.stultz@linaro.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-media@vger.kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=surenb@google.com \
    --cc=tzimmermann@suse.de \
    --cc=willy@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.