]> Git Repo - J-linux.git/commitdiff
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec
authorDavid S. Miller <[email protected]>
Wed, 23 Jun 2021 19:34:15 +0000 (12:34 -0700)
committerDavid S. Miller <[email protected]>
Wed, 23 Jun 2021 19:34:15 +0000 (12:34 -0700)
Steffen Klassert says:

====================
pull request (net): ipsec 2021-06-23

1) Don't return a mtu smaller than 1280 on IPv6 pmtu discovery.
   From Sabrina Dubroca

2) Fix seqcount rcu-read side in xfrm_policy_lookup_bytype
   for the PREEMPT_RT case. From Varad Gautam.

3) Remove a repeated declaration of xfrm_parse_spi.
   From Shaokun Zhang.

4) IPv4 beet mode can't handle fragments, but IPv6 does.
   commit 68dc022d04eb ("xfrm: BEET mode doesn't support
   fragments for inner packets") handled IPv4 and IPv6
   the same way. Relax the check for IPv6 because fragments
   are possible here. From Xin Long.

5) Memory allocation failures are not reported for
   XFRMA_ENCAP and XFRMA_COADDR in xfrm_state_construct.
   Fix this by moving both cases in front of the function.

6) Fix a missing initialization in the xfrm offload fallback
   fail case for bonding devices. From Ayush Sawal.

Please pull or let me know if there are problems.
====================

Signed-off-by: David S. Miller <[email protected]>
1  2 
net/ipv4/esp4.c
net/ipv6/esp6.c
net/xfrm/xfrm_policy.c
net/xfrm/xfrm_user.c

diff --combined net/ipv4/esp4.c
index 35803ab7ac8048397227340c7c675c3cb7a95c5e,ed9857b2875dcfbd302f96711396419cc83d10eb..26171dec08c4d97021f162a276d71dc1caba99c1
@@@ -309,7 -309,7 +309,7 @@@ static struct ip_esp_hdr *esp_output_se
                                               struct esp_output_extra *extra)
  {
        /* For ESN we move the header forward by 4 bytes to
 -       * accomodate the high bits.  We will move it back after
 +       * accommodate the high bits.  We will move it back after
         * encryption.
         */
        if ((x->props.flags & XFRM_STATE_ESN)) {
@@@ -673,7 -673,7 +673,7 @@@ static int esp_output(struct xfrm_stat
                struct xfrm_dst *dst = (struct xfrm_dst *)skb_dst(skb);
                u32 padto;
  
-               padto = min(x->tfcpad, xfrm_state_mtu(x, dst->child_mtu_cached));
+               padto = min(x->tfcpad, __xfrm_state_mtu(x, dst->child_mtu_cached));
                if (skb->len < padto)
                        esp.tfclen = padto - skb->len;
        }
@@@ -754,7 -754,7 +754,7 @@@ int esp_input_done2(struct sk_buff *skb
        int hlen = sizeof(struct ip_esp_hdr) + crypto_aead_ivsize(aead);
        int ihl;
  
 -      if (!xo || (xo && !(xo->flags & CRYPTO_DONE)))
 +      if (!xo || !(xo->flags & CRYPTO_DONE))
                kfree(ESP_SKB_CB(skb)->tmp);
  
        if (unlikely(err))
@@@ -854,7 -854,7 +854,7 @@@ static void esp_input_set_header(struc
        struct ip_esp_hdr *esph;
  
        /* For ESN we move the header forward by 4 bytes to
 -       * accomodate the high bits.  We will move it back after
 +       * accommodate the high bits.  We will move it back after
         * decryption.
         */
        if ((x->props.flags & XFRM_STATE_ESN)) {
diff --combined net/ipv6/esp6.c
index 393ae2b78e7d4b79c5bb04c14ae3054906bcba57,9d1327b36bd3ba8725d53b2e03ee3084ad6bfb64..1654e4ce094f31757786c730bbf4cd15eea2a6e2
@@@ -708,7 -708,7 +708,7 @@@ static int esp6_output(struct xfrm_stat
                struct xfrm_dst *dst = (struct xfrm_dst *)skb_dst(skb);
                u32 padto;
  
-               padto = min(x->tfcpad, xfrm_state_mtu(x, dst->child_mtu_cached));
+               padto = min(x->tfcpad, __xfrm_state_mtu(x, dst->child_mtu_cached));
                if (skb->len < padto)
                        esp.tfclen = padto - skb->len;
        }
@@@ -1147,7 -1147,7 +1147,7 @@@ static int esp_init_authenc(struct xfrm
                err = -EINVAL;
                if (aalg_desc->uinfo.auth.icv_fullbits / 8 !=
                    crypto_aead_authsize(aead)) {
 -                      pr_info("ESP: %s digestsize %u != %hu\n",
 +                      pr_info("ESP: %s digestsize %u != %u\n",
                                x->aalg->alg_name,
                                crypto_aead_authsize(aead),
                                aalg_desc->uinfo.auth.icv_fullbits / 8);
diff --combined net/xfrm/xfrm_policy.c
index ce500f847b99118b1ee50afcfa101856943d2d91,8c56e3e59c3cc7da41588ed6644cc37b8690510d..e9d0df2a2ab1722a3301414069252a2c9ecaa69a
@@@ -688,7 -688,7 +688,7 @@@ static void xfrm_hash_resize(struct wor
  }
  
  /* Make sure *pol can be inserted into fastbin.
 - * Useful to check that later insert requests will be sucessful
 + * Useful to check that later insert requests will be successful
   * (provided xfrm_policy_lock is held throughout).
   */
  static struct xfrm_pol_inexact_bin *
@@@ -2092,12 -2092,15 +2092,15 @@@ static struct xfrm_policy *xfrm_policy_
        if (unlikely(!daddr || !saddr))
                return NULL;
  
-       rcu_read_lock();
   retry:
-       do {
-               sequence = read_seqcount_begin(&xfrm_policy_hash_generation);
-               chain = policy_hash_direct(net, daddr, saddr, family, dir);
-       } while (read_seqcount_retry(&xfrm_policy_hash_generation, sequence));
+       sequence = read_seqcount_begin(&xfrm_policy_hash_generation);
+       rcu_read_lock();
+       chain = policy_hash_direct(net, daddr, saddr, family, dir);
+       if (read_seqcount_retry(&xfrm_policy_hash_generation, sequence)) {
+               rcu_read_unlock();
+               goto retry;
+       }
  
        ret = NULL;
        hlist_for_each_entry_rcu(pol, chain, bydst) {
        }
  
  skip_inexact:
-       if (read_seqcount_retry(&xfrm_policy_hash_generation, sequence))
+       if (read_seqcount_retry(&xfrm_policy_hash_generation, sequence)) {
+               rcu_read_unlock();
                goto retry;
+       }
  
-       if (ret && !xfrm_pol_hold_rcu(ret))
+       if (ret && !xfrm_pol_hold_rcu(ret)) {
+               rcu_read_unlock();
                goto retry;
+       }
  fail:
        rcu_read_unlock();
  
@@@ -3326,6 -3333,39 +3333,6 @@@ decode_session4(struct sk_buff *skb, st
                                fl4->fl4_icmp_code = icmp[1];
                        }
                        break;
 -              case IPPROTO_ESP:
 -                      if (xprth + 4 < skb->data ||
 -                          pskb_may_pull(skb, xprth + 4 - skb->data)) {
 -                              __be32 *ehdr;
 -
 -                              xprth = skb_network_header(skb) + ihl * 4;
 -                              ehdr = (__be32 *)xprth;
 -
 -                              fl4->fl4_ipsec_spi = ehdr[0];
 -                      }
 -                      break;
 -              case IPPROTO_AH:
 -                      if (xprth + 8 < skb->data ||
 -                          pskb_may_pull(skb, xprth + 8 - skb->data)) {
 -                              __be32 *ah_hdr;
 -
 -                              xprth = skb_network_header(skb) + ihl * 4;
 -                              ah_hdr = (__be32 *)xprth;
 -
 -                              fl4->fl4_ipsec_spi = ah_hdr[1];
 -                      }
 -                      break;
 -              case IPPROTO_COMP:
 -                      if (xprth + 4 < skb->data ||
 -                          pskb_may_pull(skb, xprth + 4 - skb->data)) {
 -                              __be16 *ipcomp_hdr;
 -
 -                              xprth = skb_network_header(skb) + ihl * 4;
 -                              ipcomp_hdr = (__be16 *)xprth;
 -
 -                              fl4->fl4_ipsec_spi = htonl(ntohs(ipcomp_hdr[1]));
 -                      }
 -                      break;
                case IPPROTO_GRE:
                        if (xprth + 12 < skb->data ||
                            pskb_may_pull(skb, xprth + 12 - skb->data)) {
                        }
                        break;
                default:
 -                      fl4->fl4_ipsec_spi = 0;
                        break;
                }
        }
@@@ -3436,7 -3477,12 +3443,7 @@@ decode_session6(struct sk_buff *skb, st
                        fl6->flowi6_proto = nexthdr;
                        return;
  #endif
 -              /* XXX Why are there these headers? */
 -              case IPPROTO_AH:
 -              case IPPROTO_ESP:
 -              case IPPROTO_COMP:
                default:
 -                      fl6->fl6_ipsec_spi = 0;
                        fl6->flowi6_proto = nexthdr;
                        return;
                }
@@@ -4134,6 -4180,9 +4141,6 @@@ void __init xfrm_init(void
  #ifdef CONFIG_XFRM_ESPINTCP
        espintcp_init();
  #endif
 -
 -      RCU_INIT_POINTER(xfrm_if_cb, NULL);
 -      synchronize_rcu();
  }
  
  #ifdef CONFIG_AUDITSYSCALL
diff --combined net/xfrm/xfrm_user.c
index f0aecee4d5392f24b4bacb366ea728d823aa50a7,817e714dedea020de66cb33a2a6e2293090a102d..b47d613409b70ad2c290c8542474ea2ea7e8b678
@@@ -580,6 -580,20 +580,20 @@@ static struct xfrm_state *xfrm_state_co
  
        copy_from_user_state(x, p);
  
+       if (attrs[XFRMA_ENCAP]) {
+               x->encap = kmemdup(nla_data(attrs[XFRMA_ENCAP]),
+                                  sizeof(*x->encap), GFP_KERNEL);
+               if (x->encap == NULL)
+                       goto error;
+       }
+       if (attrs[XFRMA_COADDR]) {
+               x->coaddr = kmemdup(nla_data(attrs[XFRMA_COADDR]),
+                                   sizeof(*x->coaddr), GFP_KERNEL);
+               if (x->coaddr == NULL)
+                       goto error;
+       }
        if (attrs[XFRMA_SA_EXTRA_FLAGS])
                x->props.extra_flags = nla_get_u32(attrs[XFRMA_SA_EXTRA_FLAGS]);
  
                                   attrs[XFRMA_ALG_COMP])))
                goto error;
  
-       if (attrs[XFRMA_ENCAP]) {
-               x->encap = kmemdup(nla_data(attrs[XFRMA_ENCAP]),
-                                  sizeof(*x->encap), GFP_KERNEL);
-               if (x->encap == NULL)
-                       goto error;
-       }
        if (attrs[XFRMA_TFCPAD])
                x->tfcpad = nla_get_u32(attrs[XFRMA_TFCPAD]);
  
-       if (attrs[XFRMA_COADDR]) {
-               x->coaddr = kmemdup(nla_data(attrs[XFRMA_COADDR]),
-                                   sizeof(*x->coaddr), GFP_KERNEL);
-               if (x->coaddr == NULL)
-                       goto error;
-       }
        xfrm_mark_get(attrs, &x->mark);
  
        xfrm_smark_init(attrs, &x->props.smark);
@@@ -1761,7 -1761,7 +1761,7 @@@ static int xfrm_add_policy(struct sk_bu
  
        /* shouldn't excl be based on nlh flags??
         * Aha! this is anti-netlink really i.e  more pfkey derived
 -       * in netlink excl is a flag and you wouldnt need
 +       * in netlink excl is a flag and you wouldn't need
         * a type XFRM_MSG_UPDPOLICY - JHS */
        excl = nlh->nlmsg_type == XFRM_MSG_NEWPOLICY;
        err = xfrm_policy_insert(p->dir, xp, excl);
@@@ -3480,22 -3480,18 +3480,22 @@@ static int __net_init xfrm_user_net_ini
        return 0;
  }
  
 +static void __net_exit xfrm_user_net_pre_exit(struct net *net)
 +{
 +      RCU_INIT_POINTER(net->xfrm.nlsk, NULL);
 +}
 +
  static void __net_exit xfrm_user_net_exit(struct list_head *net_exit_list)
  {
        struct net *net;
 -      list_for_each_entry(net, net_exit_list, exit_list)
 -              RCU_INIT_POINTER(net->xfrm.nlsk, NULL);
 -      synchronize_net();
 +
        list_for_each_entry(net, net_exit_list, exit_list)
                netlink_kernel_release(net->xfrm.nlsk_stash);
  }
  
  static struct pernet_operations xfrm_user_net_ops = {
        .init       = xfrm_user_net_init,
 +      .pre_exit   = xfrm_user_net_pre_exit,
        .exit_batch = xfrm_user_net_exit,
  };
  
This page took 0.096107 seconds and 4 git commands to generate.