]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfrm: Support crypto offload for inbound IPv6 ESP packets not in GRO path
authorMike Yu <yumike@google.com>
Fri, 12 Jul 2024 02:51:22 +0000 (10:51 +0800)
committerSteffen Klassert <steffen.klassert@secunet.com>
Fri, 12 Jul 2024 06:43:28 +0000 (08:43 +0200)
IPsec crypt offload supports outbound IPv6 ESP packets, but it doesn't
support inbound IPv6 ESP packets.

This change enables the crypto offload for inbound IPv6 ESP packets
that are not handled through GRO code path. If HW drivers add the
offload information to the skb, the packet will be handled in the
crypto offload rx code path.

Apart from the change in crypto offload rx code path, the change
in xfrm_policy_check is also needed.

Exampe of RX data path:

  +-----------+   +-------+
  | HW Driver |-->| wlan0 |--------+
  +-----------+   +-------+        |
                                   v
                             +---------------+   +------+
                     +------>| Network Stack |-->| Apps |
                     |       +---------------+   +------+
                     |             |
                     |             v
                 +--------+   +------------+
                 | ipsec1 |<--| XFRM Stack |
                 +--------+   +------------+

Test: Enabled both in/out IPsec crypto offload, and verified IPv6
      ESP packets on Android device on both wifi/cellular network
Signed-off-by: Mike Yu <yumike@google.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_input.c
net/xfrm/xfrm_policy.c

index d2ea18dcb0cb584ecceb2681276791f1c10a0802..ba8deb0235ba691f91adcc9c4bb2c1f13ee470b0 100644 (file)
@@ -471,7 +471,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
        struct xfrm_offload *xo = xfrm_offload(skb);
        struct sec_path *sp;
 
-       if (encap_type < 0 || (xo && xo->flags & XFRM_GRO)) {
+       if (encap_type < 0 || (xo && (xo->flags & XFRM_GRO || encap_type == 0))) {
                x = xfrm_input_state(skb);
 
                if (unlikely(x->dir && x->dir != XFRM_SA_DIR_IN)) {
index 6603d3bd171f2ca048d7c667985c44a607e33f2e..2a9a31f2a9c125113b1c259959bd05bdf159626e 100644 (file)
@@ -3718,12 +3718,15 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
                pol = xfrm_in_fwd_icmp(skb, &fl, family, if_id);
 
        if (!pol) {
+               const bool is_crypto_offload = sp &&
+                       (xfrm_input_state(skb)->xso.type == XFRM_DEV_OFFLOAD_CRYPTO);
+
                if (net->xfrm.policy_default[dir] == XFRM_USERPOLICY_BLOCK) {
                        XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOPOLS);
                        return 0;
                }
 
-               if (sp && secpath_has_nontransport(sp, 0, &xerr_idx)) {
+               if (sp && secpath_has_nontransport(sp, 0, &xerr_idx) && !is_crypto_offload) {
                        xfrm_secpath_reject(xerr_idx, skb, &fl);
                        XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOPOLS);
                        return 0;