Netdev List
 help / color / mirror / Atom feed
From: Benedict Wong <benedictwong@google.com>
To: steffen.klassert@secunet.com, netdev@vger.kernel.org
Cc: nharold@google.com, benedictwong@google.com, lorenzo@google.com
Subject: [PATCH ipsec 1/2] xfrm: Check policy for nested XFRM packets in xfrm_input
Date: Wed, 10 Aug 2022 18:22:09 +0000	[thread overview]
Message-ID: <20220810182210.721493-2-benedictwong@google.com> (raw)
In-Reply-To: <20220810182210.721493-1-benedictwong@google.com>

This change ensures that all nested XFRM packets have their policy
checked before decryption of the next layer, so that policies are
verified at each intermediate step of the decryption process.

This is necessary especially for nested tunnels, as the IP addresses,
protocol and ports may all change, thus not matching the previous
policies. In order to ensure that packets match the relevant inbound
templates, the xfrm_policy_check should be done before handing off to
the inner XFRM protocol to decrypt and decapsulate.

Test: Tested against Android Kernel Unit Tests
Signed-off-by: Benedict Wong <benedictwong@google.com>
Change-Id: I20c5abf39512d7f6cf438c0921a78a84e281b4e9
---
 net/xfrm/xfrm_input.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 144238a50f3d..b24df8a44585 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -585,6 +585,13 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 			goto drop;
 		}
 
+		// If nested tunnel, check outer states before context is lost.
+		if (x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL
+				&& sp->len > 0
+				&& !xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family)) {
+			goto drop;
+		}
+
 		skb->mark = xfrm_smark_get(skb->mark, x);
 
 		sp->xvec[sp->len++] = x;
-- 
2.37.1.595.g718a3a8f04-goog


  reply	other threads:[~2022-08-10 18:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-10 18:22 [PATCH ipsec 0/2] xfrm: Fix bugs in stacked XFRM-I tunnels Benedict Wong
2022-08-10 18:22 ` Benedict Wong [this message]
2022-08-15  8:45   ` [PATCH ipsec 1/2] xfrm: Check policy for nested XFRM packets in xfrm_input Steffen Klassert
     [not found]     ` <CANrj0baLB5a5QpdmmcNYZLyxe1r0gySLhT3krXVFXKOzBb8aww@mail.gmail.com>
2022-08-16  8:53       ` Steffen Klassert
2022-08-10 18:22 ` [PATCH ipsec 2/2] xfrm: Skip checking of already-verified secpath entries Benedict Wong
2022-08-15  8:50   ` Steffen Klassert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220810182210.721493-2-benedictwong@google.com \
    --to=benedictwong@google.com \
    --cc=lorenzo@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=nharold@google.com \
    --cc=steffen.klassert@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox