Subject: CVE-2024-35785: tee: optee: Fix kernel panic caused by incorrect error handling

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

tee: optee: Fix kernel panic caused by incorrect error handling

The error path while failing to register devices on the TEE bus has a
bug leading to kernel panic as follows:

[   15.398930] Unable to handle kernel paging request at virtual address ffff07ed00626d7c
[   15.406913] Mem abort info:
[   15.409722]   ESR = 0x0000000096000005
[   15.413490]   EC = 0x25: DABT (current EL), IL = 32 bits
[   15.418814]   SET = 0, FnV = 0
[   15.421878]   EA = 0, S1PTW = 0
[   15.425031]   FSC = 0x05: level 1 translation fault
[   15.429922] Data abort info:
[   15.432813]   ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
[   15.438310]   CM = 0, WnR = 0, TnD = 0, TagAccess = 0
[   15.443372]   GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
[   15.448697] swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000000d9e3e000
[   15.455413] [ffff07ed00626d7c] pgd=1800000bffdf9003, p4d=1800000bffdf9003, pud=0000000000000000
[   15.464146] Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP

Commit 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
lead to the introduction of this bug. So fix it appropriately.

The Linux kernel CVE team has assigned CVE-2024-35785 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 5.10.204 with commit a953e45ebeae and fixed in 5.10.215 with commit bc40ded92af5
	Issue introduced in 5.15.143 with commit 01c13d8a95e0 and fixed in 5.15.154 with commit 4b12ff5edd14
	Issue introduced in 6.1.68 with commit 1c9561b438cb and fixed in 6.1.84 with commit e5b5948c769a
	Issue introduced in 6.6.7 with commit d3c4786b01aa and fixed in 6.6.24 with commit 520f79c110ff
	Issue introduced in 6.7 with commit 7269cba53d90 and fixed in 6.7.12 with commit bfa344afbe47
	Issue introduced in 6.7 with commit 7269cba53d90 and fixed in 6.8 with commit 95915ba4b987

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2024-35785
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	drivers/tee/optee/device.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/bc40ded92af55760d12bec8222d4108de725dbe4
	https://git.kernel.org/stable/c/4b12ff5edd141926d49c9ace4791adf3a4902fe7
	https://git.kernel.org/stable/c/e5b5948c769aa1ebf962dddfb972f87d8f166f95
	https://git.kernel.org/stable/c/520f79c110ff712b391b3d87fcacf03c74bc56ee
	https://git.kernel.org/stable/c/bfa344afbe472a9be08f78551fa2190c1a07d7d3
	https://git.kernel.org/stable/c/95915ba4b987cf2b222b0f251280228a1ff977ac