Skip to contentSkip to conversation

xfrm: Fix NULL pointer dereference on policy lookup

PATCH In review Steffen Klassert 1 participant 2 messages Mar 23, 2021 – Mar 25, 2021

Subsystems (3)
lore
Share & tools
lore

Steffen Klassert

author maintainer
#0 lore raw

PATCH 1/1 xfrm: Fix NULL pointer dereference on policy lookup

When xfrm interfaces are used in combination with namespaces and ESP offload, we get a dst_entry NULL pointer dereference. This is because we don't have a dst_entry attached in the ESP offloading case and we need to do a policy lookup before the namespace transition.

Fix this by expicit checking of skb_dst(skb) before accessing it.

Fixes f203b76d78092 ("xfrm: Add virtual xfrm interfaces")
---
 include/net/xfrm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/xfrm.h +1 -1
index b2a06f10b62c..fdb7e40a61e9 100644
@@ -1097,7 +1097,7 @@ static inline int __xfrm_policy_check2(struct sock *sk, int dir,
 		return __xfrm_policy_check(sk, ndir, skb, family);
 
 	return	(!net->xfrm.policy_count[dir] && !secpath_exists(skb)) ||
-		(skb_dst(skb)->flags & DST_NOPOLICY) ||
+		(skb_dst(skb) && (skb_dst(skb)->flags & DST_NOPOLICY)) ||
 		__xfrm_policy_check(sk, ndir, skb, family);
 }
 
Signature · 1 line
2.25.1
author maintainer
#1 lore raw
Quoted 10 lines · Steffen Klassert

When xfrm interfaces are used in combination with namespaces and ESP offload, we get a dst_entry NULL pointer dereference. This is because we don't have a dst_entry attached in the ESP offloading case and we need to do a policy lookup before the namespace transition.

Fix this by expicit checking of skb_dst(skb) before accessing it.

Fixes f203b76d78092 ("xfrm: Add virtual xfrm interfaces")

Now applied.