Subject: CVE-2023-52502: net: nfc: fix races in nfc_llcp_sock_get() and nfc_llcp_sock_get_sn()

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

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

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

net: nfc: fix races in nfc_llcp_sock_get() and nfc_llcp_sock_get_sn()

Sili Luo reported a race in nfc_llcp_sock_get(), leading to UAF.

Getting a reference on the socket found in a lookup while
holding a lock should happen before releasing the lock.

nfc_llcp_sock_get_sn() has a similar problem.

Finally nfc_llcp_recv_snl() needs to make sure the socket
found by nfc_llcp_sock_from_sn() does not disappear.

The Linux kernel CVE team has assigned CVE-2023-52502 to this issue.

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

	Issue introduced in 3.6 with commit 8f50020ed9b8 and fixed in 4.19.297 with commit e863f5720a56
	Issue introduced in 3.6 with commit 8f50020ed9b8 and fixed in 5.4.259 with commit 7adcf014bda1
	Issue introduced in 3.6 with commit 8f50020ed9b8 and fixed in 5.10.199 with commit 6ac22ecdaad2
	Issue introduced in 3.6 with commit 8f50020ed9b8 and fixed in 5.15.136 with commit d888d3f70b0d
	Issue introduced in 3.6 with commit 8f50020ed9b8 and fixed in 6.1.59 with commit e4f2611f07c8
	Issue introduced in 3.6 with commit 8f50020ed9b8 and fixed in 6.5.8 with commit d1af8a39cf83
	Issue introduced in 3.6 with commit 8f50020ed9b8 and fixed in 6.6 with commit 31c07dffafce

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-2023-52502
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/nfc/llcp_core.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/e863f5720a5680e50c4cecf12424d7cc31b3eb0a
	https://git.kernel.org/stable/c/7adcf014bda16cdbf804af5c164d94d5d025db2d
	https://git.kernel.org/stable/c/6ac22ecdaad2ecc662048f8c6b0ceb1ca0699ef9
	https://git.kernel.org/stable/c/d888d3f70b0de32b4f51534175f039ddab15eef8
	https://git.kernel.org/stable/c/e4f2611f07c87b3ddb57c4b9e8efcd1e330fc3dc
	https://git.kernel.org/stable/c/d1af8a39cf839d93c8967fdd858f6bbdc3e4a15c
	https://git.kernel.org/stable/c/31c07dffafce914c1d1543c135382a11ff058d93