Subject: CVE-2021-47143: net/smc: remove device from smcd_dev_list after failed device_add()

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

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

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

net/smc: remove device from smcd_dev_list after failed device_add()

If the device_add() for a smcd_dev fails, there's no cleanup step that
rolls back the earlier list_add(). The device subsequently gets freed,
and we end up with a corrupted list.

Add some error handling that removes the device from the list.

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

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

	Issue introduced in 4.19 with commit c6ba7c9ba43d and fixed in 5.10.42 with commit 8b2cdc004d21
	Issue introduced in 4.19 with commit c6ba7c9ba43d and fixed in 5.12.9 with commit 40588782f101
	Issue introduced in 4.19 with commit c6ba7c9ba43d and fixed in 5.13 with commit 444d7be9532d

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-47143
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:
	net/smc/smc_ism.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/8b2cdc004d21a7255f219706dca64411108f7897
	https://git.kernel.org/stable/c/40588782f1016c655ae1d302892f61d35af96842
	https://git.kernel.org/stable/c/444d7be9532dcfda8e0385226c862fd7e986f607