All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ipsec] xfrm: fix a NULL-ptr deref in xfrm_local_error
@ 2020-05-26  9:41 Xin Long
  2020-05-29 10:40 ` Steffen Klassert
  0 siblings, 1 reply; 2+ messages in thread
From: Xin Long @ 2020-05-26  9:41 UTC (permalink / raw)
  To: netdev; +Cc: Steffen Klassert, Herbert Xu, David S. Miller, Sabrina Dubroca

This patch is to fix a crash:

  [ ] kasan: GPF could be caused by NULL-ptr deref or user memory access
  [ ] general protection fault: 0000 [#1] SMP KASAN PTI
  [ ] RIP: 0010:ipv6_local_error+0xac/0x7a0
  [ ] Call Trace:
  [ ]  xfrm6_local_error+0x1eb/0x300
  [ ]  xfrm_local_error+0x95/0x130
  [ ]  __xfrm6_output+0x65f/0xb50
  [ ]  xfrm6_output+0x106/0x46f
  [ ]  udp_tunnel6_xmit_skb+0x618/0xbf0 [ip6_udp_tunnel]
  [ ]  vxlan_xmit_one+0xbc6/0x2c60 [vxlan]
  [ ]  vxlan_xmit+0x6a0/0x4276 [vxlan]
  [ ]  dev_hard_start_xmit+0x165/0x820
  [ ]  __dev_queue_xmit+0x1ff0/0x2b90
  [ ]  ip_finish_output2+0xd3e/0x1480
  [ ]  ip_do_fragment+0x182d/0x2210
  [ ]  ip_output+0x1d0/0x510
  [ ]  ip_send_skb+0x37/0xa0
  [ ]  raw_sendmsg+0x1b4c/0x2b80
  [ ]  sock_sendmsg+0xc0/0x110

This occurred when sending a v4 skb over vxlan6 over ipsec, in which case
skb->protocol == htons(ETH_P_IPV6) while skb->sk->sk_family == AF_INET in
xfrm_local_error(). Then it will go to xfrm6_local_error() where it tries
to get ipv6 info from a ipv4 sk.

This issue was actually fixed by Commit 628e341f319f ("xfrm: make local
error reporting more robust"), but brought back by Commit 844d48746e4b
("xfrm: choose protocol family by skb protocol").

So to fix it, we should call xfrm6_local_error() only when skb->protocol
is htons(ETH_P_IPV6) and skb->sk->sk_family is AF_INET6.

Fixes: 844d48746e4b ("xfrm: choose protocol family by skb protocol")
Reported-by: Xiumei Mu <xmu@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/xfrm/xfrm_output.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index 69c33ca..69c4900 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -642,7 +642,8 @@ void xfrm_local_error(struct sk_buff *skb, int mtu)
 
 	if (skb->protocol == htons(ETH_P_IP))
 		proto = AF_INET;
-	else if (skb->protocol == htons(ETH_P_IPV6))
+	else if (skb->protocol == htons(ETH_P_IPV6) &&
+		 skb->sk->sk_family == AF_INET6)
 		proto = AF_INET6;
 	else
 		return;
-- 
2.1.0


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

* Re: [PATCH ipsec] xfrm: fix a NULL-ptr deref in xfrm_local_error
  2020-05-26  9:41 [PATCH ipsec] xfrm: fix a NULL-ptr deref in xfrm_local_error Xin Long
@ 2020-05-29 10:40 ` Steffen Klassert
  0 siblings, 0 replies; 2+ messages in thread
From: Steffen Klassert @ 2020-05-29 10:40 UTC (permalink / raw)
  To: Xin Long; +Cc: netdev, Herbert Xu, David S. Miller, Sabrina Dubroca

On Tue, May 26, 2020 at 05:41:46PM +0800, Xin Long wrote:
> This patch is to fix a crash:
> 
>   [ ] kasan: GPF could be caused by NULL-ptr deref or user memory access
>   [ ] general protection fault: 0000 [#1] SMP KASAN PTI
>   [ ] RIP: 0010:ipv6_local_error+0xac/0x7a0
>   [ ] Call Trace:
>   [ ]  xfrm6_local_error+0x1eb/0x300
>   [ ]  xfrm_local_error+0x95/0x130
>   [ ]  __xfrm6_output+0x65f/0xb50
>   [ ]  xfrm6_output+0x106/0x46f
>   [ ]  udp_tunnel6_xmit_skb+0x618/0xbf0 [ip6_udp_tunnel]
>   [ ]  vxlan_xmit_one+0xbc6/0x2c60 [vxlan]
>   [ ]  vxlan_xmit+0x6a0/0x4276 [vxlan]
>   [ ]  dev_hard_start_xmit+0x165/0x820
>   [ ]  __dev_queue_xmit+0x1ff0/0x2b90
>   [ ]  ip_finish_output2+0xd3e/0x1480
>   [ ]  ip_do_fragment+0x182d/0x2210
>   [ ]  ip_output+0x1d0/0x510
>   [ ]  ip_send_skb+0x37/0xa0
>   [ ]  raw_sendmsg+0x1b4c/0x2b80
>   [ ]  sock_sendmsg+0xc0/0x110
> 
> This occurred when sending a v4 skb over vxlan6 over ipsec, in which case
> skb->protocol == htons(ETH_P_IPV6) while skb->sk->sk_family == AF_INET in
> xfrm_local_error(). Then it will go to xfrm6_local_error() where it tries
> to get ipv6 info from a ipv4 sk.
> 
> This issue was actually fixed by Commit 628e341f319f ("xfrm: make local
> error reporting more robust"), but brought back by Commit 844d48746e4b
> ("xfrm: choose protocol family by skb protocol").
> 
> So to fix it, we should call xfrm6_local_error() only when skb->protocol
> is htons(ETH_P_IPV6) and skb->sk->sk_family is AF_INET6.
> 
> Fixes: 844d48746e4b ("xfrm: choose protocol family by skb protocol")
> Reported-by: Xiumei Mu <xmu@redhat.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Patch applied, thanks Xin!

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

end of thread, other threads:[~2020-05-29 10:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26  9:41 [PATCH ipsec] xfrm: fix a NULL-ptr deref in xfrm_local_error Xin Long
2020-05-29 10:40 ` Steffen Klassert

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.