Subject: CVE-2024-47751: PCI: kirin: Fix buffer overflow in kirin_pcie_parse_port()

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

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

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

PCI: kirin: Fix buffer overflow in kirin_pcie_parse_port()

Within kirin_pcie_parse_port(), the pcie->num_slots is compared to
pcie->gpio_id_reset size (MAX_PCI_SLOTS) which is correct and would lead
to an overflow.

Thus, fix condition to pcie->num_slots + 1 >= MAX_PCI_SLOTS and move
pcie->num_slots increment below the if-statement to avoid out-of-bounds
array access.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

[kwilczynski: commit log]

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

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

	Issue introduced in 5.16 with commit b22dbbb24571 and fixed in 6.1.113 with commit a5f795f94128
	Issue introduced in 5.16 with commit b22dbbb24571 and fixed in 6.6.54 with commit 95248d7497bc
	Issue introduced in 5.16 with commit b22dbbb24571 and fixed in 6.10.13 with commit 6dcc5b49d660
	Issue introduced in 5.16 with commit b22dbbb24571 and fixed in 6.11.2 with commit aeb033597180
	Issue introduced in 5.16 with commit b22dbbb24571 and fixed in 6.12-rc1 with commit c500a86693a1

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-47751
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/pci/controller/dwc/pcie-kirin.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/a5f795f9412854df28e66679c5e6b68b0b79c229
	https://git.kernel.org/stable/c/95248d7497bcbfe7deed4805469c6ff6ddd7f9d1
	https://git.kernel.org/stable/c/6dcc5b49d6607a741a14122bf3105f3ac50d259e
	https://git.kernel.org/stable/c/aeb0335971806e15ac91e838ca471936c8e7efd5
	https://git.kernel.org/stable/c/c500a86693a126c9393e602741e348f80f1b0fc5