Subject: CVE-2024-35994: firmware: qcom: uefisecapp: Fix memory related IO errors and crashes

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

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

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

firmware: qcom: uefisecapp: Fix memory related IO errors and crashes

It turns out that while the QSEECOM APP_SEND command has specific fields
for request and response buffers, uefisecapp expects them both to be in
a single memory region. Failure to adhere to this has (so far) resulted
in either no response being written to the response buffer (causing an
EIO to be emitted down the line), the SCM call to fail with EINVAL
(i.e., directly from TZ/firmware), or the device to be hard-reset.

While this issue can be triggered deterministically, in the current form
it seems to happen rather sporadically (which is why it has gone
unnoticed during earlier testing). This is likely due to the two
kzalloc() calls (for request and response) being directly after each
other. Which means that those likely return consecutive regions most of
the time, especially when not much else is going on in the system.

Fix this by allocating a single memory region for both request and
response buffers, properly aligning both structs inside it. This
unfortunately also means that the qcom_scm_qseecom_app_send() interface
needs to be restructured, as it should no longer map the DMA regions
separately. Therefore, move the responsibility of DMA allocation (or
mapping) to the caller.

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

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

	Issue introduced in 6.7 with commit 759e7a2b62eb and fixed in 6.8.9 with commit dd22b34fb53c
	Issue introduced in 6.7 with commit 759e7a2b62eb and fixed in 6.9 with commit ed09f81eeaa8

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-35994
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/firmware/qcom/qcom_qseecom_uefisecapp.c
	drivers/firmware/qcom/qcom_scm.c
	include/linux/firmware/qcom/qcom_qseecom.h
	include/linux/firmware/qcom/qcom_scm.h

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/dd22b34fb53cb04b13b2f5eee5c9200bb091fc88
	https://git.kernel.org/stable/c/ed09f81eeaa8f9265e1787282cb283f10285c259