Jens Wiklander
c05d8f66ec
tee: handle lookup of shm with reference count 0
...
commit dfd0743f1d9ea76931510ed150334d571fbab49d upstream.
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: 967c9cca2c ("tee: generic TEE subsystem")
Cc: stable@vger.kernel.org
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.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 >
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2021-12-29 12:26:02 +01:00
..
2021-04-14 08:42:06 +02:00
2021-04-07 15:00:07 +02:00
2021-05-14 09:50:05 +02:00
2021-05-14 09:50:31 +02:00
2021-07-14 16:56:37 +02:00
2020-10-29 17:22:59 -05:00
2021-08-08 09:05:22 +02:00
2021-06-16 12:01:44 +02:00
2021-10-20 11:45:04 +02:00
2021-05-11 14:47:14 +02:00
2021-03-30 14:32:06 +02:00
2021-04-21 13:00:56 +02:00
2021-04-21 13:00:55 +02:00
2021-11-26 10:39:08 +01:00
2021-09-15 09:50:26 +02:00
2021-03-25 09:04:14 +01:00
2021-12-01 09:19:10 +01:00
2021-08-26 08:35:42 -04:00
2021-03-04 11:38:14 +01:00
2021-09-08 08:49:01 +02:00
2021-09-18 13:40:13 +02:00
2021-11-06 14:10:09 +01:00
2021-03-09 11:11:13 +01:00
2021-12-08 09:03:20 +01:00
2021-07-14 16:56:53 +02:00
2021-06-03 09:00:45 +02:00
2021-01-12 20:18:17 +01:00
2021-11-21 13:46:35 +01:00
2020-11-19 08:55:44 -05:00
2021-08-04 12:46:41 +02:00
2021-08-04 12:46:45 +02:00
2021-09-03 10:09:31 +02:00
2021-12-14 11:32:36 +01:00
2021-03-30 14:32:05 +02:00
2020-12-11 14:02:14 -08:00
2021-09-26 14:08:59 +02:00
2021-11-18 14:04:32 +01:00
2021-07-14 16:56:01 +02:00
2021-07-20 16:05:46 +02:00
2021-07-20 16:05:46 +02:00
2021-07-20 16:05:46 +02:00
2021-09-30 10:11:07 +02:00
2021-05-26 12:06:56 +02:00
2021-11-18 14:03:49 +01:00
2021-06-03 09:00:45 +02:00
2021-05-28 13:17:43 +02:00
2020-11-10 18:31:17 +01:00
2021-05-19 10:13:18 +02:00
2021-09-08 08:49:00 +02:00
2021-03-09 11:11:13 +01:00
2021-06-30 08:47:18 -04:00
2020-10-30 08:37:39 +01:00
2021-03-30 14:32:06 +02:00
2021-08-18 08:59:17 +02:00
2021-01-19 18:27:22 +01:00
2021-05-07 11:04:32 +02:00
2021-03-11 14:17:27 +01:00
2021-03-25 09:04:18 +01:00
2021-05-19 10:13:13 +02:00
2021-10-27 09:56:51 +02:00
2021-09-15 09:50:37 +02:00
2021-03-17 17:06:36 +01:00
2021-11-18 14:04:25 +01:00
2021-09-18 13:40:21 +02:00
2021-03-04 11:38:41 +01:00
2021-04-07 15:00:11 +02:00
2021-11-18 14:03:42 +01:00
2021-07-31 08:16:11 +02:00
2021-11-26 10:39:22 +01:00
2021-09-08 08:48:59 +02:00
2020-12-30 11:54:18 +01:00
2020-11-12 13:59:04 -07:00
2021-12-14 11:32:33 +01:00
2021-06-18 10:00:04 +02:00
2021-09-15 09:50:25 +02:00
2021-07-25 14:36:18 +02:00
2021-09-18 13:40:36 +02:00
2021-09-18 13:40:36 +02:00
2021-05-19 10:12:54 +02:00
2021-03-04 11:38:46 +01:00
2021-03-30 14:31:57 +02:00
2021-08-18 08:59:13 +02:00
2021-09-18 13:40:14 +02:00
2020-11-04 10:22:56 -07:00
2020-11-04 08:52:46 -08:00
2021-05-14 09:50:32 +02:00
2021-12-01 09:19:10 +01:00
2021-03-04 11:38:46 +01:00
2021-08-18 08:59:15 +02:00
2020-11-30 12:21:31 +01:00
2020-11-19 22:38:29 -05:00
2021-01-09 13:46:23 +01:00
2021-11-18 14:03:56 +01:00
2021-03-04 11:37:50 +01:00
2021-03-04 11:37:59 +01:00
2021-03-04 11:38:46 +01:00
2021-03-04 11:38:20 +01:00
2021-12-08 09:03:20 +01:00
2021-02-07 15:37:17 +01:00
2021-06-16 12:01:46 +02:00
2021-11-18 14:03:37 +01:00
2021-02-03 23:28:40 +01:00
2021-09-30 10:11:04 +02:00
2021-09-15 09:50:41 +02:00
2021-09-15 09:50:41 +02:00
2021-09-15 09:50:41 +02:00
2021-11-18 14:03:36 +01:00
2021-11-18 14:03:36 +01:00
2021-04-21 13:01:00 +02:00
2021-10-09 14:40:56 +02:00
2021-07-28 14:35:46 +02:00
2021-08-26 08:35:57 -04:00
2021-09-22 12:27:59 +02:00
2021-03-17 17:06:25 +01:00
2021-03-04 11:38:21 +01:00
2021-06-03 09:00:45 +02:00
2021-06-23 14:42:49 +02:00
2021-06-30 08:47:27 -04:00
2021-06-30 08:47:26 -04:00
2021-03-30 14:32:06 +02:00
2021-08-15 14:00:25 +02:00
2021-08-18 08:59:17 +02:00
2021-03-30 14:32:07 +02:00
2021-07-19 09:44:51 +02:00
2021-12-08 09:03:25 +01:00
2020-10-30 12:57:39 +01:00
2020-10-30 12:57:39 +01:00
2021-11-18 14:04:23 +01:00
2020-11-30 10:52:22 -05:00
2021-05-19 10:13:02 +02:00
2020-11-22 10:48:22 -08:00
2021-02-07 15:37:16 +01:00
2021-07-19 09:44:39 +02:00
2021-03-09 11:11:13 +01:00
2021-09-03 10:09:21 +02:00
2021-06-30 08:47:29 -04:00
2021-09-22 12:28:00 +02:00
2021-05-19 10:13:01 +02:00
2021-05-19 10:13:01 +02:00
2021-11-21 13:46:36 +01:00
2021-11-26 10:39:22 +01:00
2020-11-09 18:12:34 +01:00
2021-03-17 17:06:28 +01:00
2021-03-30 14:32:05 +02:00
2021-09-03 10:09:28 +02:00
2021-05-14 09:50:14 +02:00
2021-12-14 11:32:41 +01:00
2021-05-19 10:12:51 +02:00
2021-11-18 14:04:29 +01:00
2021-07-14 16:55:58 +02:00
2020-12-30 11:53:56 +01:00
2021-06-23 14:42:45 +02:00
2021-04-07 15:00:13 +02:00
2021-09-18 13:40:19 +02:00
2021-06-30 08:47:27 -04:00
2021-11-18 14:04:22 +01:00
2021-01-09 13:46:24 +01:00
2021-10-17 10:43:33 +02:00
2021-11-18 14:03:36 +01:00
2020-12-30 11:53:42 +01:00
2021-11-18 14:04:27 +01:00
2021-03-17 17:06:34 +01:00
2021-12-08 09:03:23 +01:00
2021-09-22 12:27:58 +02:00
2021-08-04 12:46:44 +02:00
2021-05-14 09:50:46 +02:00
2021-06-23 14:42:44 +02:00
2021-09-03 10:09:30 +02:00
2021-09-03 10:09:30 +02:00
2021-03-30 14:31:53 +02:00
2021-03-30 14:31:53 +02:00
2021-09-03 10:09:25 +02:00
2021-03-17 17:06:34 +01:00
2021-07-25 14:36:17 +02:00
2021-07-25 14:36:18 +02:00
2021-05-07 11:04:32 +02:00
2021-01-17 14:16:59 +01:00
2021-12-29 12:26:02 +01:00
2021-09-26 14:08:59 +02:00
2021-03-25 09:04:16 +01:00
2021-09-16 12:51:23 +02:00
2021-11-18 14:04:11 +01:00
2021-11-26 10:39:14 +01:00
2020-12-30 11:53:42 +01:00
2021-07-14 16:55:46 +02:00
2021-05-14 09:50:18 +02:00
2021-03-04 11:37:36 +01:00
2021-05-14 09:50:18 +02:00
2021-03-30 14:31:51 +02:00
2021-05-14 09:50:31 +02:00
2021-02-17 11:02:28 +01:00
2021-03-25 09:04:14 +01:00
2021-03-17 17:06:19 +01:00
2021-09-08 08:49:00 +02:00
2021-03-30 14:32:03 +02:00
2021-12-29 12:25:56 +01:00
2021-08-26 08:35:41 -04:00
2021-02-10 09:29:21 +01:00
2021-12-14 11:32:39 +01:00
2021-04-07 15:00:06 +02:00
2021-03-07 12:34:15 +01:00