From: Greg KH <gregkh@linuxfoundation.org>
To: op-tee@lists.trustedfirmware.org
Subject: Re: [PATCH v2] tee: handle lookup of shm with reference count 0
Date: Wed, 15 Dec 2021 13:52:37 +0100 [thread overview]
Message-ID: <YbnlFf8930RuLkU8@kroah.com> (raw)
In-Reply-To: <20211215092501.1861229-1-jens.wiklander@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 1614 bytes --]
On Wed, Dec 15, 2021 at 10:25:01AM +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.
>
> Fixes: 967c9cca2cc5 ("tee: generic TEE subsystem")
> Cc: stable(a)vger.kernel.org
> Reviewed-by: Lars Persson <larper@axis.com>
> Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
> Reported-by: Patrik Lantz <patrik.lantz@axis.com>
> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
> ---
> v1->v2
> * fix copyright years in drivers/tee/tee_shm.c
> * update kerneldoc comment for struct tee_shm with the reference counter
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
WARNING: multiple messages have this Message-ID (diff)
From: Greg KH <gregkh@linuxfoundation.org>
To: Jens Wiklander <jens.wiklander@linaro.org>
Cc: linux-kernel@vger.kernel.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, "Lars Persson" <larper@axis.com>,
"Patrik Lantz" <patrik.lantz@axis.com>
Subject: Re: [PATCH v2] tee: handle lookup of shm with reference count 0
Date: Wed, 15 Dec 2021 13:52:37 +0100 [thread overview]
Message-ID: <YbnlFf8930RuLkU8@kroah.com> (raw)
In-Reply-To: <20211215092501.1861229-1-jens.wiklander@linaro.org>
On Wed, Dec 15, 2021 at 10:25:01AM +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.
>
> Fixes: 967c9cca2cc5 ("tee: generic TEE subsystem")
> Cc: stable@vger.kernel.org
> Reviewed-by: Lars Persson <larper@axis.com>
> Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
> Reported-by: Patrik Lantz <patrik.lantz@axis.com>
> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
> ---
> v1->v2
> * fix copyright years in drivers/tee/tee_shm.c
> * update kerneldoc comment for struct tee_shm with the reference counter
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
next prev parent reply other threads:[~2021-12-15 12:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-15 9:25 [PATCH v2] tee: handle lookup of shm with reference count 0 Jens Wiklander
2021-12-15 9:25 ` Jens Wiklander
2021-12-15 12:52 ` Greg KH [this message]
2021-12-15 12:52 ` Greg KH
2021-12-16 14:56 ` Jens Wiklander
2021-12-16 14:56 ` Jens Wiklander
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=YbnlFf8930RuLkU8@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=op-tee@lists.trustedfirmware.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.