From: Wentao Liang <vulab@iscas.ac.cn>
To: James Chapman <jchapman@katalix.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] l2tp: fix tunnel refcount leak on register failure
Date: Thu, 28 May 2026 04:34:18 +0000 [thread overview]
Message-ID: <20260528043418.1153320-1-vulab@iscas.ac.cn> (raw)
pppol2tp_tunnel_get() creates a new tunnel via l2tp_tunnel_create()
which initializes tunnel->ref_count to 1, then increments it to 2 via
refcount_inc(). If l2tp_tunnel_register() subsequently fails, the
error path calls kfree(tunnel) directly, bypassing the refcount
mechanism entirely. This leaves the tunnel's ref_count at 2 with no
way to properly release it through l2tp_tunnel_put().
Replace kfree(tunnel) with l2tp_tunnel_put(tunnel) to properly release
the reference through the standard refcount cleanup path, which will
call l2tp_tunnel_free() when the counter reaches zero.
Cc: stable@vger.kernel.org
Fixes: 6b9f34239b00 ("l2tp: fix races in tunnel creation")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
net/l2tp/l2tp_ppp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index 99d6582f41de..16672e9df748 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -661,7 +661,7 @@ static struct l2tp_tunnel *pppol2tp_tunnel_get(struct net *net,
refcount_inc(&tunnel->ref_count);
error = l2tp_tunnel_register(tunnel, net, &tcfg);
if (error < 0) {
- kfree(tunnel);
+ l2tp_tunnel_put(tunnel);
return ERR_PTR(error);
}
--
2.34.1
next reply other threads:[~2026-05-28 4:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 4:34 Wentao Liang [this message]
2026-05-28 10:31 ` Guillaume Nault
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=20260528043418.1153320-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jchapman@katalix.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®