CVE-2023-53020: l2tp: close all race conditions in l2tp_tunnel_register()
Description
===========
In the Linux kernel, the following vulnerability has been resolved:
l2tp: close all race conditions in l2tp_tunnel_register()
The code in l2tp_tunnel_register() is racy in several ways:
1. It modifies the tunnel socket _after_ publishing it.
2. It calls setup_udp_tunnel_sock() on an existing socket without locking.
3. It changes sock lock class on fly, which triggers many syzbot reports.
This patch amends all of them by moving socket initialization code before publishing and under sock lock. As suggested by Jakub, the l2tp lockdep class is not necessary as we can just switch to bh_lock_sock_nested().
The Linux kernel CVE team has assigned CVE-2023-53020 to this issue.
Affected and fixed versions
===========================
Issue introduced in 3.6 with commit 37159ef2c1ae1e696b24b260b241209a19f92c60 and fixed in 5.10.166 with commit 2d77e5c0ad79004b5ef901895437e9cce6dfcc7e Issue introduced in 3.6 with commit 37159ef2c1ae1e696b24b260b241209a19f92c60 and fixed in 5.15.91 with commit 77e8ed776cdb1a24b2aab8fe7c6f1f154235e1ce Issue introduced in 3.6 with commit 37159ef2c1ae1e696b24b260b241209a19f92c60 and fixed in 6.1.9 with commit cef0845b6dcfa2f6c2c832e7f9622551456c741d Issue introduced in 3.6 with commit 37159ef2c1ae1e696b24b260b241209a19f92c60 and fixed in 6.2 with commit 0b2c59720e65885a394a017d0cf9cab118914682
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-53020
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/l2tp/l2tp_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/2d77e5c0ad79004b5ef901895437e9cce6dfcc7e https://git.kernel.org/stable/c/77e8ed776cdb1a24b2aab8fe7c6f1f154235e1ce https://git.kernel.org/stable/c/cef0845b6dcfa2f6c2c832e7f9622551456c741d https://git.kernel.org/stable/c/0b2c59720e65885a394a017d0cf9cab118914682