From: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>
To: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Xiyu Yang <xiyuyang19@fudan.edu.cn>,
Xin Tan <tanxin.ctf@gmail.com>, Xin Xiong <xiongx18@fudan.edu.cn>,
Tom Parkin <tparkin@katalix.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] l2tp: fix possible use-after-free
Date: Wed, 8 Jun 2022 00:16:27 +0800 [thread overview]
Message-ID: <20220607161627.25035-1-xiaohuizhang@ruc.edu.cn> (raw)
We detected a suspected bug with our code clone detection tool.
Similar to the handling of l2tp_tunnel_get in commit a622b40035d1
("l2ip: fix possible use-after-free"), we thought a patch might
be needed here as well.
Before taking a refcount on a rcu protected structure,
we need to make sure the refcount is not zero.
Signed-off-by: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>
---
net/l2tp/l2tp_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index b759fbd09b65..c5de6d4e0818 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -273,8 +273,8 @@ struct l2tp_session *l2tp_session_get(const struct net *net, u32 session_id)
rcu_read_lock_bh();
hlist_for_each_entry_rcu(session, session_list, global_hlist)
- if (session->session_id == session_id) {
- l2tp_session_inc_refcount(session);
+ if (session->session_id == session_id &&
+ refcount_inc_not_zero(&session->ref_count)) {
rcu_read_unlock_bh();
return session;
--
2.17.1
next reply other threads:[~2022-06-07 16:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 16:16 Xiaohui Zhang [this message]
2022-06-07 17:28 ` Eric Dumazet
-- strict thread matches above, loose matches on Subject: below --
2022-06-05 11:54 Xiaohui Zhang
2022-06-06 8:10 ` Paolo Abeni
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=20220607161627.25035-1-xiaohuizhang@ruc.edu.cn \
--to=xiaohuizhang@ruc.edu.cn \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tanxin.ctf@gmail.com \
--cc=tparkin@katalix.com \
--cc=xiongx18@fudan.edu.cn \
--cc=xiyuyang19@fudan.edu.cn \
/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®