diff mbox series

[ipsec] xfrm: Fix NULL pointer dereference on policy lookup

Message ID 20210323082644.GP62598@gauss3.secunet.de (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [ipsec] xfrm: Fix NULL pointer dereference on policy lookup | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers fail 4 blamed authors not CCed: benedictwong@google.com eyal.birger@gmail.com lorenzo@google.com shannon.nelson@oracle.com; 7 maintainers not CCed: lorenzo@google.com shannon.nelson@oracle.com benedictwong@google.com herbert@gondor.apana.org.au eyal.birger@gmail.com davem@davemloft.net kuba@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 319 this patch: 319
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 274 this patch: 274
netdev/header_inline success Link

Commit Message

Steffen Klassert March 23, 2021, 8:26 a.m. UTC
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")
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/net/xfrm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Steffen Klassert March 25, 2021, 8:45 a.m. UTC | #1
On Tue, Mar 23, 2021 at 09:26:44AM +0100, Steffen Klassert wrote:
> 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")
> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Now applied.
diff mbox series

Patch

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index b2a06f10b62c..fdb7e40a61e9 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -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);
 }