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
3737 * @num_users: number of active users of this device
3838 * @c_no_user: completion used when unregistering the device
3939 * @mutex: mutex protecting @num_users and @idr
40− * @idr: register of shared memory object allocated on this device
40+ * @idr: register of user space shared memory objects allocated or
41+ * registered on this device
4142 * @pool: shared memory pool
4243 */
4344 struct 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
1515 {
1616 struct tee_device *teedev = shm->teedev;
1717
18− mutex_lock(&teedev->mutex);
19− idr_remove(&teedev->idr, shm->id);
20− mutex_unlock(&teedev->mutex);
18+ if (shm->flags & TEE_SHM_DMA_BUF) {
19+ mutex_lock(&teedev->mutex);
20+ idr_remove(&teedev->idr, shm->id);
21+ mutex_unlock(&teedev->mutex);
22+ }
2123
2224 if (shm->flags & TEE_SHM_POOL) {
2325 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
137139 goto err_kfree;
138140 }
139141
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− }
147142
148143 if (flags & TEE_SHM_DMA_BUF) {
149144 DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
150145
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+
151154 exp_info.ops = &tee_shm_dma_buf_ops;
152155 exp_info.size = shm->size;
153156 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
165168
166169 return shm;
167170 err_rem:
168− mutex_lock(&teedev->mutex);
169− idr_remove(&teedev->idr, shm->id);
170− mutex_unlock(&teedev->mutex);
171+ if (flags & TEE_SHM_DMA_BUF) {
172+ mutex_lock(&teedev->mutex);
173+ idr_remove(&teedev->idr, shm->id);
174+ mutex_unlock(&teedev->mutex);
175+ }
171176 err_pool_free:
172177 poolm->ops->free(poolm, shm);
173178 err_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