From: "Christian König" <christian.koenig@amd.com>
To: David Laight <David.Laight@ACULAB.COM>,
"T.J. Mercier" <tjmercier@google.com>,
Charan Teja Kalla <quic_charante@quicinc.com>,
zhiguojiang <justinjiang@vivo.com>,
Sumit Semwal <sumit.semwal@linaro.org>,
"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linaro-mm-sig@lists.linaro.org" <linaro-mm-sig@lists.linaro.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"opensource.kernel@vivo.com" <opensource.kernel@vivo.com>
Subject: Re: [PATCH] dmabuf: fix dmabuf file poll uaf issue
Date: Wed, 8 May 2024 14:21:58 +0200 [thread overview]
Message-ID: <facb101b-3535-421d-bffb-c4ea675c9107@amd.com> (raw)
In-Reply-To: <c0fe95949d4f41449f17add8300270b9@AcuMS.aculab.com>
[-- Attachment #1: Type: text/plain, Size: 1783 bytes --]
Am 08.05.24 um 13:51 schrieb David Laight:
> From: Christian König
>> Sent: 07 May 2024 15:05
> ...
>> I actually have been telling people to (ab)use the epoll behavior to
>> check if two file descriptors point to the same underlying file when
>> KCMP isn't available.
> In what way?
Something like this:
fd_e = epoll_create1(EPOLL_CLOEXEC);
tmp = dup(fd_A)
epoll_ctl(fd_e, EPOLL_CTL_ADD, tmp, ....);
dup2(fd_B, tmp);
/* If this return -EEXISTS then the fd_A and fd_B are pointing to the
same struct file */
epoll_ctl(fd_e, EPOLL_CTL_ADD, tmp, ....);
close (tmp);
close (fd_e
> You can add both fd to the same epoll fd.
> Relying on the implicit EPOLL_CTL_DEL not happening until both fd are
> closed is a recipe for disaster.
> (And I can't see an obvious way of testing it.)
>
> Q6/A6 on epoll(7) should always have had a caveat that it is an
> 'implementation detail' and shouldn't be relied on.
> (it is written as a 'beware of' ...)
>
> The other point is that there are two ways to get multiple fd that
> reference the same underlying file.
> dup() fork() etc share the file offset, but open("/dev/fd/n") adds
> a reference count later and has a separate file offset.
No it doesn't.
Accessing /dev/fd/n or /proc/*/fd/n ideally accesses the same inode, but
gives you a new struct file.
dup(), fork() etc.. make you actually reference the same struct file
inside the kernel.
That turned out to be a rather important distinction when working with
device drivers and DMA-buf.
Regards,
Christian.
>
> I don't know which structure epoll is using, but I suspect it is
> the former.
> So it may not tell you what you want to know.
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
[-- Attachment #2: Type: text/html, Size: 3102 bytes --]
prev parent reply other threads:[~2024-05-08 12:22 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-27 2:29 [PATCH] dmabuf: fix dmabuf file poll uaf issue Zhiguo Jiang
2024-03-29 23:36 ` T.J. Mercier
2024-04-01 6:52 ` zhiguojiang
2024-04-01 12:22 ` Christian König
2024-04-02 6:49 ` zhiguojiang
2024-04-02 8:07 ` Christian König
2024-04-02 18:22 ` T.J. Mercier
2024-04-12 6:19 ` zhiguojiang
2024-04-12 6:39 ` Christian König
2024-04-15 10:35 ` zhiguojiang
2024-04-15 11:57 ` Christian König
2024-04-18 1:33 ` zhiguojiang
2024-04-18 6:46 ` Christian König
2024-05-03 13:40 ` Charan Teja Kalla
2024-05-03 23:13 ` T.J. Mercier
2024-05-05 16:20 ` Charan Teja Kalla
2024-05-06 9:30 ` Charan Teja Kalla
2024-05-06 19:04 ` T.J. Mercier
2024-05-07 10:10 ` Christian König
2024-05-07 13:39 ` Daniel Vetter
2024-05-07 14:04 ` Christian König
2024-05-07 18:00 ` T.J. Mercier
2024-05-07 20:19 ` Rob Clark
2024-05-08 11:51 ` David Laight
2024-05-08 12:21 ` Christian König [this message]
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=facb101b-3535-421d-bffb-c4ea675c9107@amd.com \
--to=christian.koenig@amd.com \
--cc=David.Laight@ACULAB.COM \
--cc=dri-devel@lists.freedesktop.org \
--cc=justinjiang@vivo.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=opensource.kernel@vivo.com \
--cc=quic_charante@quicinc.com \
--cc=sumit.semwal@linaro.org \
--cc=tjmercier@google.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 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.