Subject: CVE-2019-25162: i2c: Fix a potential use after free

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

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

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

i2c: Fix a potential use after free

Free the adap structure only after we are done using it.
This patch just moves the put_device() down a bit to avoid the
use after free.

[wsa: added comment to the code, added Fixes tag]

The Linux kernel CVE team has assigned CVE-2019-25162 to this issue.

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

	Issue introduced in 4.3 with commit 611e12ea0f12 and fixed in 4.14.291 with commit e6412ba3b650
	Issue introduced in 4.3 with commit 611e12ea0f12 and fixed in 4.19.256 with commit 23a191b132cd
	Issue introduced in 4.3 with commit 611e12ea0f12 and fixed in 5.4.211 with commit 871a1e94929a
	Issue introduced in 4.3 with commit 611e12ea0f12 and fixed in 5.10.137 with commit 81cb31756888
	Issue introduced in 4.3 with commit 611e12ea0f12 and fixed in 5.15.61 with commit 35927d7509ab
	Issue introduced in 4.3 with commit 611e12ea0f12 and fixed in 5.18.18 with commit e8e1a046cf87
	Issue introduced in 4.3 with commit 611e12ea0f12 and fixed in 5.19.2 with commit 12b0606000d0
	Issue introduced in 4.3 with commit 611e12ea0f12 and fixed in 6.0 with commit e4c72c06c367

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-2019-25162
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/i2c/i2c-core-base.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/e6412ba3b6508bdf9c074d310bf4144afa6aec1a
	https://git.kernel.org/stable/c/23a191b132cd87f746c62f3dc27da33683d85829
	https://git.kernel.org/stable/c/871a1e94929a27bf6e2cd99523865c840bbc2d87
	https://git.kernel.org/stable/c/81cb31756888bb062e92d2dca21cd629d77a46a9
	https://git.kernel.org/stable/c/35927d7509ab9bf41896b7e44f639504eae08af7
	https://git.kernel.org/stable/c/e8e1a046cf87c8b1363e5de835114f2779e2aaf4
	https://git.kernel.org/stable/c/12b0606000d0828630c033bf0c74c748464fe87d
	https://git.kernel.org/stable/c/e4c72c06c367758a14f227c847f9d623f1994ecf