All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: "Christian König" <christian.koenig@amd.com>
Cc: Maling list - DRI developers <dri-devel@lists.freedesktop.org>,
	Jason Ekstrand <jason@jlekstrand.net>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Sumit Semwal <sumit.semwal@linaro.org>
Subject: Re: [PATCH 1/2] dma-buf: Add an API for exporting sync files (v13)
Date: Thu, 5 May 2022 10:35:48 +0200	[thread overview]
Message-ID: <YnOMZGgqUFM0veSf@phenom.ffwll.local> (raw)
In-Reply-To: <03423100-0266-1396-49ad-2b61d7331f6e@amd.com>

On Thu, May 05, 2022 at 10:27:39AM +0200, Christian König wrote:
> Am 05.05.22 um 10:10 schrieb Jason Ekstrand:
> > On Thu, May 5, 2022 at 1:25 AM Christian König
> > <christian.koenig@amd.com> wrote:
> > 
> >     [SNIP]
> >     > +     fd_install(fd, sync_file->file);
> >     > +
> >     > +     arg.fd = fd;
> >     > +     if (copy_to_user(user_data, &arg, sizeof(arg)))
> >     > +             return -EFAULT;
> > 
> >     I know we had that discussion before, but I'm not 100% any more
> >     what the
> >     outcome was.
> > 
> >     The problem here is that when the copy_to_user fails we have a file
> >     descriptor which is valid, but userspace doesn't know anything
> >     about it.
> > 
> >     I only see a few possibilities here:
> >     1. Keep it like this and just assume that a process which you
> >     can't copy
> >     the fd to is also dying (a bit to much assumption for my taste).
> > 
> >     2. Close the file descriptor when this happens (not ideal either).
> > 
> >     3. Instead of returning the fd in the parameter structure return
> >     it as
> >     IOCTL result.
> > 
> >     Number 3 is what drm_prime_handle_to_fd_ioctl() is doing as well and
> >     IIRC we said that this is probably the best option.
> > 
> > 
> > I don't have a strong preference here, so I'll go with whatever in the
> > end but let me at least explain my reasoning.  First, this was based on
> > the FD import/export in syncobj which stuffs the FD in the args struct. 
> > If `copy_to_user` is a problem here, it's a problem there as well. 
> > Second, the only way `copy_to_user` can fail is if the client gives us a
> > read-only page or somehow manages to race removing the page from their
> > address space (via unmap(), for instance) with this ioctl.  Both of
> > those seem like pretty serious client errors to me.  That, or the client
> > is in the process of dying, in which case we really don't care.
> 
> Yeah, I know about that copy_to_user() issue in the syncobj and also some
> driver specific handling.
> 
> That's why we discussed this before and IIRC somebody indeed ran into an
> issue with -EFAULT and that was the reason all this bubbled up.
> 
> I don't have a strong preference either, but I think we should try to learn
> from previous mistakes and design new interfaces based on such experience.

We have this in a bunch of places (like execbuf tail handling after
drm_sched_job_push()) and I think what we commonly do is just try to clean
up the mess a bit and fail.

I think what you could do here is do the copy_to_user before you do the
fd_install, and if the copy_to_user fails you just clean up everything and
fail. That just means there's a small window where userspace has an fd
reserve that didn't end up being used, but also in real apps this just
never matters.

Leaking the fd is maybe not the best option, but meh.
-Daniel

> 
> Christian.
> 
> > 
> > --Jason
> > 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

  reply	other threads:[~2022-05-05  8:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04 20:34 [PATCH 0/2] *dma-buf: Add an API for exporting sync files (v13) Jason Ekstrand
2022-05-04 20:34 ` [PATCH 1/2] dma-buf: " Jason Ekstrand
2022-05-04 22:49   ` Daniel Vetter
2022-05-05  8:05     ` Jason Ekstrand
2022-05-05  8:23       ` Daniel Vetter
2022-05-06  0:11         ` Jason Ekstrand
2022-05-05  6:25   ` Christian König
2022-05-05  8:10     ` Jason Ekstrand
2022-05-05  8:27       ` Christian König
2022-05-05  8:35         ` Daniel Vetter [this message]
2022-05-04 20:34 ` [PATCH 2/2] dma-buf: Add an API for importing sync files (v8) Jason Ekstrand
2022-05-04 22:53   ` Daniel Vetter
2022-05-05  8:13     ` Jason Ekstrand
2022-05-05  8:39       ` Daniel Vetter
2022-05-04 22:43 [PATCH 0/2] dma-buf: Add an API for exporting sync files (v13) Jason Ekstrand
2022-05-04 22:43 ` [PATCH 1/2] " Jason Ekstrand

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=YnOMZGgqUFM0veSf@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=christian.koenig@amd.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jason@jlekstrand.net \
    --cc=sumit.semwal@linaro.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.