Subject: CVE-2024-40903: usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps

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

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

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

usb: typec: tcpm: fix use-after-free case in tcpm_register_source_caps

There could be a potential use-after-free case in
tcpm_register_source_caps(). This could happen when:
 * new (say invalid) source caps are advertised
 * the existing source caps are unregistered
 * tcpm_register_source_caps() returns with an error as
   usb_power_delivery_register_capabilities() fails

This causes port->partner_source_caps to hold on to the now freed source
caps.

Reset port->partner_source_caps value to NULL after unregistering
existing source caps.

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

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

	Issue introduced in 6.1.91 with commit cfcd544a9974 and fixed in 6.1.95 with commit 4053696594d7
	Issue introduced in 6.6.31 with commit b16abab1fb64 and fixed in 6.6.35 with commit 04c05d50fa79
	Issue introduced in 6.9 with commit 230ecdf71a64 and fixed in 6.9.6 with commit 6b67b652849f
	Issue introduced in 6.9 with commit 230ecdf71a64 and fixed in 6.10 with commit e7e921918d90
	Issue introduced in 6.8.10 with commit 931b5f302d6f

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-40903
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/usb/typec/tcpm/tcpm.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/4053696594d7235f3638d49a00cf0f289e4b36a3
	https://git.kernel.org/stable/c/04c05d50fa79a41582f7bde8a1fd4377ae4a39e5
	https://git.kernel.org/stable/c/6b67b652849faf108a09647c7fde9b179ef24e2b
	https://git.kernel.org/stable/c/e7e921918d905544500ca7a95889f898121ba886