netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] l2tp: fix possible use-after-free
@ 2022-06-07 16:16 Xiaohui Zhang
  2022-06-07 17:28 ` Eric Dumazet
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaohui Zhang @ 2022-06-07 16:16 UTC (permalink / raw)
  To: Xiaohui Zhang, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Xiyu Yang, Xin Tan, Xin Xiong, Tom Parkin, netdev,
	linux-kernel

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] l2tp: fix possible use-after-free
  2022-06-07 16:16 [PATCH 2/2] l2tp: fix possible use-after-free Xiaohui Zhang
@ 2022-06-07 17:28 ` Eric Dumazet
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Dumazet @ 2022-06-07 17:28 UTC (permalink / raw)
  To: Xiaohui Zhang
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Xiyu Yang,
	Xin Tan, Xin Xiong, Tom Parkin, netdev, LKML

On Tue, Jun 7, 2022 at 9:16 AM Xiaohui Zhang <xiaohuizhang@ruc.edu.cn> wrote:
>
> 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
>

Please fix all bugs in a single patch.

net/l2tp/l2tp_core.c contains four suspect calls to l2tp_session_inc_refcount()

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-07 17:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07 16:16 [PATCH 2/2] l2tp: fix possible use-after-free Xiaohui Zhang
2022-06-07 17:28 ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).