From: Lars Persson <larper@axis.com>
To: Greg KH <gregkh@linuxfoundation.org>,
Jens Wiklander <jens.wiklander@linaro.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"op-tee@lists.trustedfirmware.org"
<op-tee@lists.trustedfirmware.org>,
"Sumit Garg" <sumit.garg@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Rijo Thomas" <Rijo-john.Thomas@amd.com>,
"Devaraj Rangasamy" <Devaraj.Rangasamy@amd.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
"Lars Persson" <Lars.Persson@axis.com>,
"Patrik Lantz" <Patrik.Lantz@axis.com>
Subject: Re: [PATCH] tee: handle lookup of shm with reference count 0
Date: Tue, 14 Dec 2021 15:54:11 +0100 [thread overview]
Message-ID: <5beb196e-bb70-f28c-98c9-9e18df164e94@axis.com> (raw)
In-Reply-To: <YbifvnSBjW5m19hZ@kroah.com>
On 2021-12-14 14:44, Greg KH wrote:
> On Tue, Dec 14, 2021 at 01:35:40PM +0100, Jens Wiklander wrote:
>> Since the tee subsystem does not keep a strong reference to its idle
>> shared memory buffers, it races with other threads that try to destroy a
>> shared memory through a close of its dma-buf fd or by unmapping the
>> memory.
>>
>> In tee_shm_get_from_id() when a lookup in teedev->idr has been
>> successful, it is possible that the tee_shm is in the dma-buf teardown
>> path, but that path is blocked by the teedev mutex. Since we don't have
>> an API to tell if the tee_shm is in the dma-buf teardown path or not we
>> must find another way of detecting this condition.
>>
>> Fix this by doing the reference counting directly on the tee_shm using a
>> new refcount_t refcount field. dma-buf is replaced by using
>> anon_inode_getfd() instead, this separates the life-cycle of the
>> underlying file from the tee_shm. tee_shm_put() is updated to hold the
>> mutex when decreasing the refcount to 0 and then remove the tee_shm from
>> teedev->idr before releasing the mutex. This means that the tee_shm can
>> never be found unless it has a refcount larger than 0.
>
> So you are dropping dma-buf support entirely? And anon_inode_getfd()
> works instead? Why do more people not do this as well?
Indeed, thinking about it, does it really makes sense to do mmap() on an
anon_inode_getfd() fd ? It is a singleton inode used there so don't we
breach some contract with the linux mm ? The dma-buf code for creating
the file object is more complex, it creates a unique inode for each object.
I am by no means claiming to understand inodes' interaction with mmap,
just sharing a concern that popped up in my head.
- Lars
next prev parent reply other threads:[~2021-12-14 14:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-14 12:35 Jens Wiklander
2021-12-14 13:44 ` Greg KH
2021-12-14 14:51 ` Christian König
2021-12-14 14:54 ` Lars Persson [this message]
2021-12-14 14:59 ` Jens Wiklander
2021-12-14 15:25 ` Greg KH
2021-12-14 16:31 ` Jens Wiklander
2021-12-14 16:51 ` Greg KH
2021-12-14 18:50 ` Jens Wiklander
2021-12-14 20:59 ` Greg KH
2021-12-14 21:02 ` Greg KH
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=5beb196e-bb70-f28c-98c9-9e18df164e94@axis.com \
--to=larper@axis.com \
--cc=Devaraj.Rangasamy@amd.com \
--cc=Lars.Persson@axis.com \
--cc=Patrik.Lantz@axis.com \
--cc=Rijo-john.Thomas@amd.com \
--cc=christian.koenig@amd.com \
--cc=gregkh@linuxfoundation.org \
--cc=jens.wiklander@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=op-tee@lists.trustedfirmware.org \
--cc=stable@vger.kernel.org \
--cc=sumit.garg@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®