From: Jakub Kicinski <kuba@kernel.org>
To: lee@kernel.org
Cc: Jakub Kicinski <kuba@kernel.org>,
jchapman@katalix.com, davem@davemloft.net, edumazet@google.com,
pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] l2tp: pppol2tp: hold reference to session in pppol2tp_ioctl()
Date: Fri, 22 May 2026 11:15:31 -0700 [thread overview]
Message-ID: <20260522181531.1491908-1-kuba@kernel.org> (raw)
In-Reply-To: <20260520134837.2780050-1-lee@kernel.org>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
l2tp: pppol2tp: hold reference to session in pppol2tp_ioctl()
This patch addresses a use-after-free in pppol2tp_ioctl() by replacing
the direct sk_user_data dereference with the refcounted helper
pppol2tp_sock_to_session(), and refactors the function to drop the
reference on a single exit path.
> diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
> index 99d6582f41de..9a2243a32ceb 100644
> --- a/net/l2tp/l2tp_ppp.c
> +++ b/net/l2tp/l2tp_ppp.c
> @@ -1045,64 +1045,57 @@ static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
> {
> struct pppol2tp_ioc_stats stats;
> struct l2tp_session *session;
> + int err = 0;
> +
> + session = pppol2tp_sock_to_session(sock->sk);
> + if (!session)
> + return -ENOTCONN;
[Medium]
Does this change the behaviour of unknown ioctl commands when the
socket is not yet connected?
Previously, the default arm of the switch returned -ENOIOCTLCMD without
ever consulting sk_user_data:
default:
return -ENOIOCTLCMD;
In sock_do_ioctl(), -ENOIOCTLCMD is the sentinel that lets the generic
dispatcher fall through to handlers like dev_ioctl() for SIOCGIF*-style
and similar generic socket ioctls:
if (err != -ENOIOCTLCMD)
return err;
After the patch, any cmd at all on a pppol2tp socket whose sk_user_data
has not been bound by pppol2tp_connect() now fails up front with
-ENOTCONN, including the generic ioctls that previously fell through
the default arm.
Would it be worth either keeping the per-case session lookup, or
mapping the no-session case onto the default arm so unknown cmds keep
returning -ENOIOCTLCMD? The commit message describes this as a UAF
fix and does not mention this user-visible change.
>
> switch (cmd) {
> case PPPIOCGMRU:
> case PPPIOCGFLAGS:
> - session = sock->sk->sk_user_data;
> - if (!session)
> - return -ENOTCONN;
> -
> - if (WARN_ON(session->magic != L2TP_SESSION_MAGIC))
> - return -EBADF;
> -
[Low]
Is the loss of the explicit -EBADF magic-check return path intended?
Each cmd arm previously had:
if (WARN_ON(session->magic != L2TP_SESSION_MAGIC))
return -EBADF;
pppol2tp_sock_to_session() does perform a magic check, but only as
WARN_ON_ONCE() and it still returns the (possibly corrupted) session
pointer:
WARN_ON_ONCE(session->magic != L2TP_SESSION_MAGIC);
...
return session;
So on a magic mismatch the function will now proceed to dereference
session->session_id, session->tunnel, etc. instead of bailing out with
-EBADF, and the warning is reduced from per-call to once per boot.
The commit message frames the change as purely a refcount/UAF fix and
does not mention the loss of this defensive path; was that
intentional?
> /* Not defined for tunnels */
> - if (!session->session_id && !session->peer_session_id)
> - return -ENOSYS;
> + if (!session->session_id && !session->peer_session_id) {
> + err = -ENOSYS;
> + break;
> + }
[ ... ]
--
pw-bot: cr
prev parent reply other threads:[~2026-05-22 18:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 13:48 [PATCH 1/1] l2tp: pppol2tp: hold reference to session in pppol2tp_ioctl() Lee Jones
2026-05-22 18:14 ` Jakub Kicinski
2026-05-22 18:15 ` Jakub Kicinski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260522181531.1491908-1-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jchapman@katalix.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox