]> git.ipfire.org Git - thirdparty/linux.git/commit
l2tp: pppol2tp: hold reference to session in pppol2tp_ioctl()
authorLee Jones <lee@kernel.org>
Wed, 27 May 2026 13:36:29 +0000 (13:36 +0000)
committerJakub Kicinski <kuba@kernel.org>
Tue, 2 Jun 2026 02:40:46 +0000 (19:40 -0700)
commita213a8950414c684999dcf03edeea6c46ede172e
tree2affe36f7a6966d079de024823626605cbccaf55
parent2a58899d11009bffc7b4b32a571858f381121837
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: fd558d186df2 ("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>
net/l2tp/l2tp_ppp.c