android_kernel_sony_sdm845/include
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jens Wiklander 964f50205d
BACKPORT: 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: 967c9cca2cc5 ("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>
[JW: backport to 5.4-stable]
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
[mkbestas: backport to 4.9]
Signed-off-by: Michael Bestas <mkbestas@lineageos.org>
Change-Id: Ibd2809a225b167563c65faff4a44e56e23c2e97b
2025-02-14 15:30:53 +02:00
..
acpi ACPI: scan: Use unique number for instance_no 2021-03-30 14:41:41 +02:00
asm-generic Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-20 2023-01-19 15:42:12 +01:00
clocksource
crypto Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-07-18 14:05:31 +03:00
drm Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-07-18 14:05:31 +03:00
dt-bindings clk: msm: gcc: Add support for BB_CLK3 for SDM429 2020-05-28 10:47:09 +05:30
keys
kvm
linux BACKPORT: tee: handle lookup of shm with reference count 0 2025-02-14 15:30:53 +02:00
math-emu
media media: media/cec.h: add CEC_CAP_DEFAULTS 2020-06-22 22:31:02 -07:00
memory
microvisor
misc
net BACKPORT: net: fix __dst_negative_advice() race 2024-08-19 10:13:09 +03:00
pcmcia
ras
rdma IB/cma: Fix reference count leak when no ipv4 addresses are set 2020-06-03 08:16:33 +02:00
rxrpc
scsi Merge remote-tracking branch 'common/android-4.9-q' into android13-4.9-sdm845 2022-11-09 19:25:28 +02:00
soc Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-17.1-caf-sdm845 2021-01-17 05:04:08 +02:00
sound Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-09-06 06:20:26 +03:00
target scsi: target: Fix ordered tag handling 2021-11-26 11:48:41 +01:00
trace Merge branch 'linux-4.9.y' of https://kernel.googlesource.com/pub/scm/linux/kernel/git/jaegeuk/f2fs-stable into lineage-20 2022-11-16 15:35:23 +01:00
uapi nl80211: add WPA3 definition for SAE authentication 2024-12-13 22:46:35 +01:00
video Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-09-06 06:20:26 +03:00
vservices
xen xen/gnttab: fix gnttab_end_foreign_access() without page specified 2022-03-11 10:03:33 +01:00