Skip to contentSkip to conversation

CVE-2021-47195: spi: fix use-after-free of the add_lock mutex

DISCUSSION Greg Kroah-Hartman 1 participant 1 message Apr 10, 2024

lore
Share & tools
lore
#0 lore raw

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

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

spi: fix use-after-free of the add_lock mutex

Commit 6098475d4cb4 ("spi: Fix deadlock when adding SPI controllers on SPI buses") introduced a per-controller mutex. But mutex_unlock() of said lock is called after the controller is already freed:

spi_unregister_controller(ctlr)
-> put_device(&ctlr->dev)

    -> spi_controller_release(dev)

-> mutex_unlock(&ctrl->add_lock)

Move the put_device() after the mutex_unlock().

The Linux kernel CVE team has assigned CVE-2021-47195 to this issue.

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

	Issue introduced in 5.15 with commit 6098475d4cb4 and fixed in 5.15.5 with commit 37330f37f666
	Issue introduced in 5.15 with commit 6098475d4cb4 and fixed in 5.16 with commit 6c53b45c71b4
	Issue introduced in 5.14.15 with commit 722ef19a161c

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-2021-47195

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/spi/spi.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/37330f37f6666c7739a44b2b6b95b047ccdbed2d
	https://git.kernel.org/stable/c/6c53b45c71b4920b5e62f0ea8079a1da382b9434