History

tee: don't assign shm id for private shms

Private shared memory object must not be referenced from user space. To guarantee that, don't assign an id to shared memory objects which are driver private.

Jens Wiklander committed 7 years ago

Commit f1bbace1 parent c180f9b2 files · +20 −14Browse files

Unified · Split

2 files
  1. drivers/tee/tee_private.h +2 −1
  2. drivers/tee/tee_shm.c +18 −13
drivers/tee/tee_private.h+2−1
@@ -37,7 +37,8 @@ struct tee_shm_pool { · 36 unmodified lines
37 * @num_users: number of active users of this device37 * @num_users: number of active users of this device
38 * @c_no_user: completion used when unregistering the device38 * @c_no_user: completion used when unregistering the device
39 * @mutex: mutex protecting @num_users and @idr39 * @mutex: mutex protecting @num_users and @idr
40 * @idr: register of shared memory object allocated on this device40 * @idr: register of user space shared memory objects allocated or
41 * registered on this device
41 * @pool: shared memory pool42 * @pool: shared memory pool
42 */43 */
43struct tee_device {44struct tee_device {
drivers/tee/tee_shm.c+18−13
@@ -15,9 +15,11 @@ static void tee_shm_release(struct tee_shm *shm) · 14 unmodified lines
15{15{
16 struct tee_device *teedev = shm->teedev;16 struct tee_device *teedev = shm->teedev;
17 17
18 mutex_lock(&teedev->mutex);18 if (shm->flags & TEE_SHM_DMA_BUF) {
19 idr_remove(&teedev->idr, shm->id);19 mutex_lock(&teedev->mutex);
20 mutex_unlock(&teedev->mutex);20 idr_remove(&teedev->idr, shm->id);
21 mutex_unlock(&teedev->mutex);
22 }
21 23
22 if (shm->flags & TEE_SHM_POOL) {24 if (shm->flags & TEE_SHM_POOL) {
23 struct tee_shm_pool_mgr *poolm;25 struct tee_shm_pool_mgr *poolm;
@@ -137,17 +139,18 @@ struct tee_shm *tee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags) · 113 unmodified lines
137 goto err_kfree;139 goto err_kfree;
138 }140 }
139 141
140 mutex_lock(&teedev->mutex);
141 shm->id = idr_alloc(&teedev->idr, shm, 1, 0, GFP_KERNEL);
142 mutex_unlock(&teedev->mutex);
143 if (shm->id < 0) {
144 ret = ERR_PTR(shm->id);
145 goto err_pool_free;
146 }
147 142
148 if (flags & TEE_SHM_DMA_BUF) {143 if (flags & TEE_SHM_DMA_BUF) {
149 DEFINE_DMA_BUF_EXPORT_INFO(exp_info);144 DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
150 145
146 mutex_lock(&teedev->mutex);
147 shm->id = idr_alloc(&teedev->idr, shm, 1, 0, GFP_KERNEL);
148 mutex_unlock(&teedev->mutex);
149 if (shm->id < 0) {
150 ret = ERR_PTR(shm->id);
151 goto err_pool_free;
152 }
153
151 exp_info.ops = &tee_shm_dma_buf_ops;154 exp_info.ops = &tee_shm_dma_buf_ops;
152 exp_info.size = shm->size;155 exp_info.size = shm->size;
153 exp_info.flags = O_RDWR;156 exp_info.flags = O_RDWR;
@@ -165,9 +168,11 @@ struct tee_shm *tee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags) · 11 unmodified lines
165 168
166 return shm;169 return shm;
167err_rem:170err_rem:
168 mutex_lock(&teedev->mutex);171 if (flags & TEE_SHM_DMA_BUF) {
169 idr_remove(&teedev->idr, shm->id);172 mutex_lock(&teedev->mutex);
170 mutex_unlock(&teedev->mutex);173 idr_remove(&teedev->idr, shm->id);
174 mutex_unlock(&teedev->mutex);
175 }
171err_pool_free:176err_pool_free:
172 poolm->ops->free(poolm, shm);177 poolm->ops->free(poolm, shm);
173err_kfree:178err_kfree:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t