Subject: CVE-2021-47258: scsi: core: Fix error handling of scsi_host_alloc()

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

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

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

scsi: core: Fix error handling of scsi_host_alloc()

After device is initialized via device_initialize(), or its name is set via
dev_set_name(), the device has to be freed via put_device().  Otherwise
device name will be leaked because it is allocated dynamically in
dev_set_name().

Fix the leak by replacing kfree() with put_device(). Since
scsi_host_dev_release() properly handles IDA and kthread removal, remove
special-casing these from the error handling as well.

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

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

	Fixed in 4.9.273 with commit 8958181c1663
	Fixed in 4.14.237 with commit db08ce595dd6
	Fixed in 4.19.195 with commit 2dc85045ae65
	Fixed in 5.4.126 with commit 79296e292d67
	Fixed in 5.10.44 with commit 7a696ce1d5d1
	Fixed in 5.12.11 with commit 45d83db47281
	Fixed in 5.13 with commit 66a834d09293

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-47258
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/scsi/hosts.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/8958181c1663e24a13434448e7d6b96b5d04900a
	https://git.kernel.org/stable/c/db08ce595dd64ea9859f7d088b51cbfc8e685c66
	https://git.kernel.org/stable/c/2dc85045ae65b9302a1d2e2ddd7ce4c030153a6a
	https://git.kernel.org/stable/c/79296e292d67fa7b5fb8d8c27343683e823872c8
	https://git.kernel.org/stable/c/7a696ce1d5d16a33a6cd6400bbcc0339b2460e11
	https://git.kernel.org/stable/c/45d83db4728127944b237c0c8248987df9d478e7
	https://git.kernel.org/stable/c/66a834d092930cf41d809c0e989b13cd6f9ca006