Commit graph

10 commits

Author SHA1 Message Date
Dan Carpenter
8c1e0d6585 BACKPORT: tee: shm: Potential NULL dereference calling tee_shm_register()
get_user_pages_fast() can return zero in certain error paths.  We should
handle that or else it means we accidentally return ERR_PTR(0) which is
NULL instead of an error pointer.  The callers are not expecting that
and will crash with a NULL dereference.

Change-Id: I8ecf03cf8ddf3b248d765dee3cf0b634e9838678
Fixes: 033ddf12bcf5 ("tee: add register user memory")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 2490cdf6435b1d3cac0dbf710cd752487c67c296)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2018-02-21 15:40:49 +00:00
Colin Ian King
ed384bc362 BACKPORT: tee: shm: don't put_page on null shm->pages
In the case that shm->pages fails to allocate, the current exit
error path will try to put_page on a null shm->pages and cause
a null pointer dereference when accessing shm->pages[n]. Fix this
by only performing the put_page and kfree on shm->pages if it
is not null.

Detected by CoverityScan, CID#1463283 ("Dereference after null check")

Change-Id: I4874df9fce449834fdf9064c718c2d2517f69bc4
Fixes: 033ddf12bcf5 ("tee: add register user memory")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit c94f31b526fe658c25dd2d07c90486a85437f01c)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2018-02-21 15:40:49 +00:00
Colin Ian King
18fee2106b BACKPORT: tee: shm: make function __tee_shm_alloc static
The function __tee_shm_alloc is local to the source and does
not need to be in global scope, so make it static.

Cleans up sparse warning:
symbol '__tee_shm_alloc' was not declared. Should it be static?

Change-Id: I39cc9afd601505dc7fdee1cfff1811c3582822f9
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 80ec6f5de60b6934f145b2f7e5369592bcab85f3)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2018-02-21 15:40:49 +00:00
Jens Wiklander
1b8bb30b07 BACKPORT: tee: add start argument to shm_register callback
Adds a start argument to the shm_register callback to allow the callback
to check memory type of the passed pages.

Change-Id: I61457d60ca192637f8d986e2d6f8aeb153d2c484
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 95ffe4ca43877eea176d7e95aa0d38bbdc3d2903)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2018-02-21 15:40:49 +00:00
Volodymyr Babchuk
78d437dbb1 BACKPORT: tee: shm: inline tee_shm_get_id()
Now, when struct tee_shm is defined in public header,
we can inline small getter functions like this one.

Change-Id: I9aba40c18ec448c043ab0b31849e4d6429908371
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit ef8e08d24ca84846ce639b835ebd2f15a943f42b)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2018-02-21 15:40:49 +00:00
Volodymyr Babchuk
17c7c494f7 BACKPORT: tee: use reference counting for tee_context
We need to ensure that tee_context is present until last
shared buffer will be freed.

Change-Id: I0346e266f17b06af82144290d230029d0193a3d8
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 217e0250cccb9e54d457991446cd3fab413085e1)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2018-02-21 15:40:49 +00:00
Jens Wiklander
9b5e064b88 BACKPORT: tee: add register user memory
Added new ioctl to allow users register own buffers as a shared memory.

Change-Id: If7f52f1d7c733d1d31de791523a07748e77fa202
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
[jw: moved tee_shm_is_registered() declaration]
[jw: added space after __tee_shm_alloc() implementation]
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 033ddf12bcf5326b93bd604f50a7474a434a35f9)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2018-02-21 15:40:47 +00:00
Jens Wiklander
15bf9b9422 BACKPORT: tee: flexible shared memory pool creation
Makes creation of shm pools more flexible by adding new more primitive
functions to allocate a shm pool. This makes it easier to add driver
specific shm pool management.

Change-Id: Ief7841b612e1f2ad67222f058bb6627ac9dcd41d
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
(cherry picked from commit e2aca5d8928acb9cc9a87802b02102d4f9b9b596)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2018-02-21 15:40:47 +00:00
Arvind Yadav
ab64937ab1 BACKPORT: tee: tee_shm: Constify dma_buf_ops structures.
dma_buf_ops are not supposed to change at runtime. All functions
working with dma_buf_ops provided by <linux/dma-buf.h> work with
const dma_buf_ops. So mark the non-const structs as const.

File size before:
   text	   data	    bss	    dec	    hex	filename
   2026	    112	      0	   2138	    85a	drivers/tee/tee_shm.o

File size After adding 'const':
   text	   data	    bss	    dec	    hex	filename
   2138	      0	      0	   2138	    85a	drivers/tee/tee_shm.o

Change-Id: I6dfa99c45bf0078d7048525fa0554bc1f607f1e9
Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 53e3ca5cee24f5fafe4e9ff5fe4b230e1a1b85ed)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2018-01-12 16:44:44 +00:00
Jens Wiklander
048370cd16 tee: generic TEE subsystem
Initial patch for generic TEE subsystem.
This subsystem provides:
* Registration/un-registration of TEE drivers.
* Shared memory between normal world and secure world.
* Ioctl interface for interaction with user space.
* Sysfs implementation_id of TEE driver

A TEE (Trusted Execution Environment) driver is a driver that interfaces
with a trusted OS running in some secure environment, for example,
TrustZone on ARM cpus, or a separate secure co-processor etc.

The TEE subsystem can serve a TEE driver for a Global Platform compliant
TEE, but it's not limited to only Global Platform TEEs.

This patch builds on other similar implementations trying to solve
the same problem:
* "optee_linuxdriver" by among others
  Jean-michel DELORME<jean-michel.delorme@st.com> and
  Emmanuel MICHEL <emmanuel.michel@st.com>
* "Generic TrustZone Driver" by Javier González <javier@javigon.com>

Change-Id: I35b763e23b706383df5013c429c510c68d7f4176
Acked-by: Andreas Dannenberg <dannenberg@ti.com>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey)
Tested-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> (RCAR H3)
Tested-by: Scott Branden <scott.branden@broadcom.com>
Reviewed-by: Javier González <javier@javigon.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 967c9cca2cc50569efc65945325c173cecba83bd)
Signed-off-by: Victor Chong <victor.chong@linaro.org>
2017-12-02 06:53:27 +00:00