linux-stable/include
Jens Wiklander 492eb7afe8 tee: handle lookup of shm with reference count 0
commit dfd0743f1d 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:28:54 +01:00
..
acpi ACPI: tools: fix compilation error 2021-10-07 19:18:19 +02:00
asm-generic asm-generic: build fixes for v5.15 2021-10-08 11:57:54 -07:00
clocksource
crypto
drm drm/ttm: remove ttm_bo_vm_insert_huge() 2021-11-18 19:17:08 +01:00
dt-bindings
keys
kunit kunit: fix kernel-doc warnings due to mismatched arg names 2021-10-06 17:54:07 -06:00
kvm KVM: arm64: Fix PMU probe ordering 2021-09-20 12:43:34 +01:00
linux tee: handle lookup of shm with reference count 0 2021-12-29 12:28:54 +01:00
math-emu
media media: videobuf2: rework vb2_mem_ops API 2021-11-18 19:16:13 +01:00
memory memory: renesas-rpc-if: Correct QSPI data transfer in Manual mode 2021-11-18 19:16:01 +01:00
misc
net inet: fully convert sk->sk_rx_dst to RCU rules 2021-12-29 12:28:42 +01:00
pcmcia
ras
rdma RDMA/netlink: Add __maybe_unused to static inline in C file 2021-11-25 09:49:07 +01:00
scsi scsi: core: Avoid leaving shost->last_reset with stale value if EH does not run 2021-11-18 19:15:51 +01:00
soc net: dsa: tag_ocelot_8021q: break circular dependency with ocelot switch lib 2021-10-12 17:35:18 -07:00
sound ALSA: hda: hdac_ext_stream: fix potential locking issues 2021-11-25 09:49:08 +01:00
target scsi: target: Fix ordered tag handling 2021-11-25 09:48:29 +01:00
trace f2fs: fix up f2fs_lookup tracepoints 2021-11-25 09:48:31 +01:00
uapi uapi: Fix undefined __always_inline on non-glibc systems 2021-12-29 12:28:49 +01:00
vdso
video
xen xen/console: harden hvc_xen against event channel storms 2021-12-22 09:32:52 +01:00