milos-linux/net/l2tp
Lee Jones a213a89504 l2tp: pppol2tp: hold reference to session in pppol2tp_ioctl()
pppol2tp_ioctl() read sock->sk->sk_user_data directly without any
locks or reference counting.  If a controllable sleep was induced during
copy_from_user() (e.g. via a userfaultfd page fault sleep), a concurrent
socket close could trigger pppol2tp_session_close() asynchronously.  This
frees the l2tp_session structure via the l2tp_session_del_work workqueue.
Upon resuming, the ioctl thread dereferences the stale session pointer,
resulting in a Use-After-Free (UAF).

Fix this by securely fetching the session reference using the RCU-safe,
refcounted helper pppol2tp_sock_to_session(sk) on entry.  This locks the
session's refcount across the sleep.  We structured the function to exit
via standard err breaks, guaranteeing that l2tp_session_put() is cleanly
called on all return paths to drop the reference.

To preserve existing behavior we validate the session and its magic
signature only for the specific L2TP commands that require it.  This
ensures that generic/unknown ioctls called on an unconnected socket
still return -ENOIOCTLCMD and correctly fall back to generic handlers
(e.g. in sock_do_ioctl()).

Signed-off-by: Lee Jones <lee@kernel.org>
Fixes: fd558d186d ("l2tp: Split pppol2tp patch into separate l2tp and ppp parts")
Link: https://patch.msgid.link/20260527133630.2120612-1-lee@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-06-01 19:40:46 -07:00
..
Kconfig ipv6: convert CONFIG_IPV6 to built-in only and clean up Kconfigs 2026-03-29 11:21:22 -07:00
l2tp_core.c l2tp: use refcount_inc_not_zero in l2tp_session_get_by_ifname 2026-05-26 17:35:12 -07:00
l2tp_core.h l2tp: improve tunnel/session refcount helpers 2024-08-11 04:38:50 +01:00
l2tp_debugfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
l2tp_eth.c net: l2tp_eth: Replace deprecated strcpy with strscpy in l2tp_eth_create 2026-02-24 13:38:33 +01:00
l2tp_ip.c net: remove addr_len argument of recvmsg() handlers 2026-03-02 18:17:17 -08:00
l2tp_ip6.c net: remove addr_len argument of recvmsg() handlers 2026-03-02 18:17:17 -08:00
l2tp_netlink.c genetlink: hold RCU in genlmsg_mcast() 2024-10-15 17:52:58 -07:00
l2tp_ppp.c l2tp: pppol2tp: hold reference to session in pppol2tp_ioctl() 2026-06-01 19:40:46 -07:00
Makefile
trace.h