All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/l2tp: Fix reference count leak in l2tp_udp_recv_core
@ 2021-09-09  4:32 Xiyu Yang
  2021-09-09  9:01 ` Tom Parkin
  2021-09-09 10:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Xiyu Yang @ 2021-09-09  4:32 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Cong Wang, Randy Dunlap,
	Tom Parkin, Xin Xiong, Gong, Sishuai, Matthias Schiffer,
	Xiyu Yang, Bhaskar Chowdhury, netdev, linux-kernel
  Cc: yuanxzhang, Xin Tan

The reference count leak issue may take place in an error handling
path. If both conditions of tunnel->version == L2TP_HDR_VER_3 and the
return value of l2tp_v3_ensure_opt_in_linear is nonzero, the function
would directly jump to label invalid, without decrementing the reference
count of the l2tp_session object session increased earlier by
l2tp_tunnel_get_session(). This may result in refcount leaks.

Fix this issue by decrease the reference count before jumping to the
label invalid.

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
---
 net/l2tp/l2tp_core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 53486b162f01..93271a2632b8 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -869,8 +869,10 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
 	}
 
 	if (tunnel->version == L2TP_HDR_VER_3 &&
-	    l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr))
+	    l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr)) {
+		l2tp_session_dec_refcount(session);
 		goto invalid;
+	}
 
 	l2tp_recv_common(session, skb, ptr, optr, hdrflags, length);
 	l2tp_session_dec_refcount(session);
-- 
2.7.4


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

* Re: [PATCH] net/l2tp: Fix reference count leak in l2tp_udp_recv_core
  2021-09-09  4:32 [PATCH] net/l2tp: Fix reference count leak in l2tp_udp_recv_core Xiyu Yang
@ 2021-09-09  9:01 ` Tom Parkin
  2021-09-09  9:10   ` Tom Parkin
  2021-09-09 10:10 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Tom Parkin @ 2021-09-09  9:01 UTC (permalink / raw)
  To: Xiyu Yang
  Cc: David S. Miller, Jakub Kicinski, Cong Wang, Randy Dunlap,
	Xin Xiong, Gong, Sishuai, Matthias Schiffer, Bhaskar Chowdhury,
	netdev, linux-kernel, yuanxzhang, Xin Tan

[-- Attachment #1: Type: text/plain, Size: 2036 bytes --]

On  Thu, Sep 09, 2021 at 12:32:00 +0800, Xiyu Yang wrote:
> The reference count leak issue may take place in an error handling
> path. If both conditions of tunnel->version == L2TP_HDR_VER_3 and the
> return value of l2tp_v3_ensure_opt_in_linear is nonzero, the function
> would directly jump to label invalid, without decrementing the reference
> count of the l2tp_session object session increased earlier by
> l2tp_tunnel_get_session(). This may result in refcount leaks.

I agree with your analysis.  Thanks for catching this!

> 
> Fix this issue by decrease the reference count before jumping to the
> label invalid.
> 
> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
> ---
>  net/l2tp/l2tp_core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
> index 53486b162f01..93271a2632b8 100644
> --- a/net/l2tp/l2tp_core.c
> +++ b/net/l2tp/l2tp_core.c
> @@ -869,8 +869,10 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
>  	}
>  
>  	if (tunnel->version == L2TP_HDR_VER_3 &&
> -	    l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr))
> +	    l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr)) {
> +		l2tp_session_dec_refcount(session);
>  		goto invalid;
> +	}

The error paths in l2tp_udp_recv_core are a bit convoluted because of
the check (!session || !session->recv_skb) which may or may not need
to drop a session reference if triggered.

I think it could be simplified since session->recv_skb is always set
for all the current session types in the tree, but doing that is probably
a little patch series on its own.

>  
>  	l2tp_recv_common(session, skb, ptr, optr, hdrflags, length);
>  	l2tp_session_dec_refcount(session);
> -- 
> 2.7.4
> 

-- 
Tom Parkin
Katalix Systems Ltd
https://katalix.com
Catalysts for your Embedded Linux software development

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] net/l2tp: Fix reference count leak in l2tp_udp_recv_core
  2021-09-09  9:01 ` Tom Parkin
@ 2021-09-09  9:10   ` Tom Parkin
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Parkin @ 2021-09-09  9:10 UTC (permalink / raw)
  To: Xiyu Yang
  Cc: David S. Miller, Jakub Kicinski, Cong Wang, Randy Dunlap,
	Xin Xiong, Gong, Sishuai, Matthias Schiffer, Bhaskar Chowdhury,
	netdev, linux-kernel, yuanxzhang, Xin Tan

[-- Attachment #1: Type: text/plain, Size: 2442 bytes --]

On  Thu, Sep 09, 2021 at 10:01:56 +0100, Tom Parkin wrote:
> On  Thu, Sep 09, 2021 at 12:32:00 +0800, Xiyu Yang wrote:
> > The reference count leak issue may take place in an error handling
> > path. If both conditions of tunnel->version == L2TP_HDR_VER_3 and the
> > return value of l2tp_v3_ensure_opt_in_linear is nonzero, the function
> > would directly jump to label invalid, without decrementing the reference
> > count of the l2tp_session object session increased earlier by
> > l2tp_tunnel_get_session(). This may result in refcount leaks.
> 
> I agree with your analysis.  Thanks for catching this!
> 

Also: I forgot to mention I think this fixes:

4522a70db7aa ("l2tp: fix reading optional fields of L2TPv3")

> > 
> > Fix this issue by decrease the reference count before jumping to the
> > label invalid.
> > 
> > Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> > Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
> > Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
> > ---
> >  net/l2tp/l2tp_core.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
> > index 53486b162f01..93271a2632b8 100644
> > --- a/net/l2tp/l2tp_core.c
> > +++ b/net/l2tp/l2tp_core.c
> > @@ -869,8 +869,10 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
> >  	}
> >  
> >  	if (tunnel->version == L2TP_HDR_VER_3 &&
> > -	    l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr))
> > +	    l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr)) {
> > +		l2tp_session_dec_refcount(session);
> >  		goto invalid;
> > +	}
> 
> The error paths in l2tp_udp_recv_core are a bit convoluted because of
> the check (!session || !session->recv_skb) which may or may not need
> to drop a session reference if triggered.
> 
> I think it could be simplified since session->recv_skb is always set
> for all the current session types in the tree, but doing that is probably
> a little patch series on its own.
> 
> >  
> >  	l2tp_recv_common(session, skb, ptr, optr, hdrflags, length);
> >  	l2tp_session_dec_refcount(session);
> > -- 
> > 2.7.4
> > 
> 
> -- 
> Tom Parkin
> Katalix Systems Ltd
> https://katalix.com
> Catalysts for your Embedded Linux software development



-- 
Tom Parkin
Katalix Systems Ltd
https://katalix.com
Catalysts for your Embedded Linux software development

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] net/l2tp: Fix reference count leak in l2tp_udp_recv_core
  2021-09-09  4:32 [PATCH] net/l2tp: Fix reference count leak in l2tp_udp_recv_core Xiyu Yang
  2021-09-09  9:01 ` Tom Parkin
@ 2021-09-09 10:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-09-09 10:10 UTC (permalink / raw)
  To: Xiyu Yang
  Cc: davem, kuba, cong.wang, rdunlap, tparkin, xiongx18, sishuai,
	mschiffer, unixbhaskar, netdev, linux-kernel, yuanxzhang,
	tanxin.ctf

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Thu,  9 Sep 2021 12:32:00 +0800 you wrote:
> The reference count leak issue may take place in an error handling
> path. If both conditions of tunnel->version == L2TP_HDR_VER_3 and the
> return value of l2tp_v3_ensure_opt_in_linear is nonzero, the function
> would directly jump to label invalid, without decrementing the reference
> count of the l2tp_session object session increased earlier by
> l2tp_tunnel_get_session(). This may result in refcount leaks.
> 
> [...]

Here is the summary with links:
  - net/l2tp: Fix reference count leak in l2tp_udp_recv_core
    https://git.kernel.org/netdev/net/c/9b6ff7eb6664

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-09-09 10:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09  4:32 [PATCH] net/l2tp: Fix reference count leak in l2tp_udp_recv_core Xiyu Yang
2021-09-09  9:01 ` Tom Parkin
2021-09-09  9:10   ` Tom Parkin
2021-09-09 10:10 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.