These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / net / xfrm / xfrm_user.c
index 2091664..805681a 100644 (file)
@@ -31,6 +31,7 @@
 #if IS_ENABLED(CONFIG_IPV6)
 #include <linux/in6.h>
 #endif
+#include <asm/unaligned.h>
 
 static int verify_one_alg(struct nlattr **attrs, enum xfrm_attr_type_t type)
 {
@@ -289,6 +290,31 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props,
        return 0;
 }
 
+static int attach_crypt(struct xfrm_state *x, struct nlattr *rta)
+{
+       struct xfrm_algo *p, *ualg;
+       struct xfrm_algo_desc *algo;
+
+       if (!rta)
+               return 0;
+
+       ualg = nla_data(rta);
+
+       algo = xfrm_ealg_get_byname(ualg->alg_name, 1);
+       if (!algo)
+               return -ENOSYS;
+       x->props.ealgo = algo->desc.sadb_alg_id;
+
+       p = kmemdup(ualg, xfrm_alg_len(ualg), GFP_KERNEL);
+       if (!p)
+               return -ENOMEM;
+
+       strcpy(p->alg_name, algo->name);
+       x->ealg = p;
+       x->geniv = algo->uinfo.encr.geniv;
+       return 0;
+}
+
 static int attach_auth(struct xfrm_algo_auth **algpp, u8 *props,
                       struct nlattr *rta)
 {
@@ -349,8 +375,7 @@ static int attach_auth_trunc(struct xfrm_algo_auth **algpp, u8 *props,
        return 0;
 }
 
-static int attach_aead(struct xfrm_algo_aead **algpp, u8 *props,
-                      struct nlattr *rta)
+static int attach_aead(struct xfrm_state *x, struct nlattr *rta)
 {
        struct xfrm_algo_aead *p, *ualg;
        struct xfrm_algo_desc *algo;
@@ -363,14 +388,15 @@ static int attach_aead(struct xfrm_algo_aead **algpp, u8 *props,
        algo = xfrm_aead_get_byname(ualg->alg_name, ualg->alg_icv_len, 1);
        if (!algo)
                return -ENOSYS;
-       *props = algo->desc.sadb_alg_id;
+       x->props.ealgo = algo->desc.sadb_alg_id;
 
        p = kmemdup(ualg, aead_len(ualg), GFP_KERNEL);
        if (!p)
                return -ENOMEM;
 
        strcpy(p->alg_name, algo->name);
-       *algpp = p;
+       x->aead = p;
+       x->geniv = algo->uinfo.aead.geniv;
        return 0;
 }
 
@@ -515,8 +541,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
        if (attrs[XFRMA_SA_EXTRA_FLAGS])
                x->props.extra_flags = nla_get_u32(attrs[XFRMA_SA_EXTRA_FLAGS]);
 
-       if ((err = attach_aead(&x->aead, &x->props.ealgo,
-                              attrs[XFRMA_ALG_AEAD])))
+       if ((err = attach_aead(x, attrs[XFRMA_ALG_AEAD])))
                goto error;
        if ((err = attach_auth_trunc(&x->aalg, &x->props.aalgo,
                                     attrs[XFRMA_ALG_AUTH_TRUNC])))
@@ -526,9 +551,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
                                       attrs[XFRMA_ALG_AUTH])))
                        goto error;
        }
-       if ((err = attach_one_algo(&x->ealg, &x->props.ealgo,
-                                  xfrm_ealg_get_byname,
-                                  attrs[XFRMA_ALG_CRYPT])))
+       if ((err = attach_crypt(x, attrs[XFRMA_ALG_CRYPT])))
                goto error;
        if ((err = attach_one_algo(&x->calg, &x->props.calgo,
                                   xfrm_calg_get_byname,
@@ -706,7 +729,9 @@ static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p)
        memcpy(&p->sel, &x->sel, sizeof(p->sel));
        memcpy(&p->lft, &x->lft, sizeof(p->lft));
        memcpy(&p->curlft, &x->curlft, sizeof(p->curlft));
-       memcpy(&p->stats, &x->stats, sizeof(p->stats));
+       put_unaligned(x->stats.replay_window, &p->stats.replay_window);
+       put_unaligned(x->stats.replay, &p->stats.replay);
+       put_unaligned(x->stats.integrity_failed, &p->stats.integrity_failed);
        memcpy(&p->saddr, &x->props.saddr, sizeof(p->saddr));
        p->mode = x->props.mode;
        p->replay_window = x->props.replay_window;
@@ -903,12 +928,10 @@ static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb)
                        return err;
 
                if (attrs[XFRMA_ADDRESS_FILTER]) {
-                       filter = kmalloc(sizeof(*filter), GFP_KERNEL);
+                       filter = kmemdup(nla_data(attrs[XFRMA_ADDRESS_FILTER]),
+                                        sizeof(*filter), GFP_KERNEL);
                        if (filter == NULL)
                                return -ENOMEM;
-
-                       memcpy(filter, nla_data(attrs[XFRMA_ADDRESS_FILTER]),
-                              sizeof(*filter));
                }
 
                if (attrs[XFRMA_PROTO])
@@ -1908,8 +1931,10 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
        struct nlattr *rp = attrs[XFRMA_REPLAY_VAL];
        struct nlattr *re = attrs[XFRMA_REPLAY_ESN_VAL];
        struct nlattr *lt = attrs[XFRMA_LTIME_VAL];
+       struct nlattr *et = attrs[XFRMA_ETIMER_THRESH];
+       struct nlattr *rt = attrs[XFRMA_REPLAY_THRESH];
 
-       if (!lt && !rp && !re)
+       if (!lt && !rp && !re && !et && !rt)
                return err;
 
        /* pedantic mode - thou shalt sayeth replaceth */
@@ -2026,7 +2051,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
                xfrm_audit_policy_delete(xp, 1, true);
        } else {
                // reset the timers here?
-               WARN(1, "Dont know what to do with soft policy expire\n");
+               WARN(1, "Don't know what to do with soft policy expire\n");
        }
        km_policy_expired(xp, p->dir, up->hard, nlh->nlmsg_pid);