]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/net/macsec.c
vxlan: check tun_info options_len properly
[mirror_ubuntu-bionic-kernel.git] / drivers / net / macsec.c
index 5ab1b8849c30496966be05115f752bfcf3385950..27936229c60df6ca6b7e7548ee696ebbcc3ebee5 100644 (file)
@@ -16,6 +16,7 @@
 #include <crypto/aead.h>
 #include <linux/etherdevice.h>
 #include <linux/rtnetlink.h>
+#include <linux/refcount.h>
 #include <net/genetlink.h>
 #include <net/sock.h>
 #include <net/gro_cells.h>
@@ -146,7 +147,7 @@ struct macsec_rx_sa {
        struct macsec_key key;
        spinlock_t lock;
        u32 next_pn;
-       atomic_t refcnt;
+       refcount_t refcnt;
        bool active;
        struct macsec_rx_sa_stats __percpu *stats;
        struct macsec_rx_sc *sc;
@@ -171,7 +172,7 @@ struct macsec_rx_sc {
        bool active;
        struct macsec_rx_sa __rcu *sa[MACSEC_NUM_AN];
        struct pcpu_rx_sc_stats __percpu *stats;
-       atomic_t refcnt;
+       refcount_t refcnt;
        struct rcu_head rcu_head;
 };
 
@@ -187,7 +188,7 @@ struct macsec_tx_sa {
        struct macsec_key key;
        spinlock_t lock;
        u32 next_pn;
-       atomic_t refcnt;
+       refcount_t refcnt;
        bool active;
        struct macsec_tx_sa_stats __percpu *stats;
        struct rcu_head rcu;
@@ -314,7 +315,7 @@ static struct macsec_rx_sa *macsec_rxsa_get(struct macsec_rx_sa __rcu *ptr)
        if (!sa || !sa->active)
                return NULL;
 
-       if (!atomic_inc_not_zero(&sa->refcnt))
+       if (!refcount_inc_not_zero(&sa->refcnt))
                return NULL;
 
        return sa;
@@ -330,12 +331,12 @@ static void free_rx_sc_rcu(struct rcu_head *head)
 
 static struct macsec_rx_sc *macsec_rxsc_get(struct macsec_rx_sc *sc)
 {
-       return atomic_inc_not_zero(&sc->refcnt) ? sc : NULL;
+       return refcount_inc_not_zero(&sc->refcnt) ? sc : NULL;
 }
 
 static void macsec_rxsc_put(struct macsec_rx_sc *sc)
 {
-       if (atomic_dec_and_test(&sc->refcnt))
+       if (refcount_dec_and_test(&sc->refcnt))
                call_rcu(&sc->rcu_head, free_rx_sc_rcu);
 }
 
@@ -350,7 +351,7 @@ static void free_rxsa(struct rcu_head *head)
 
 static void macsec_rxsa_put(struct macsec_rx_sa *sa)
 {
-       if (atomic_dec_and_test(&sa->refcnt))
+       if (refcount_dec_and_test(&sa->refcnt))
                call_rcu(&sa->rcu, free_rxsa);
 }
 
@@ -361,7 +362,7 @@ static struct macsec_tx_sa *macsec_txsa_get(struct macsec_tx_sa __rcu *ptr)
        if (!sa || !sa->active)
                return NULL;
 
-       if (!atomic_inc_not_zero(&sa->refcnt))
+       if (!refcount_inc_not_zero(&sa->refcnt))
                return NULL;
 
        return sa;
@@ -378,7 +379,7 @@ static void free_txsa(struct rcu_head *head)
 
 static void macsec_txsa_put(struct macsec_tx_sa *sa)
 {
-       if (atomic_dec_and_test(&sa->refcnt))
+       if (refcount_dec_and_test(&sa->refcnt))
                call_rcu(&sa->rcu, free_txsa);
 }
 
@@ -865,6 +866,7 @@ static void macsec_reset_skb(struct sk_buff *skb, struct net_device *dev)
 
 static void macsec_finalize_skb(struct sk_buff *skb, u8 icv_len, u8 hdr_len)
 {
+       skb->ip_summed = CHECKSUM_NONE;
        memmove(skb->data + hdr_len, skb->data, 2 * ETH_ALEN);
        skb_pull(skb, hdr_len);
        pskb_trim_unique(skb, skb->len - icv_len);
@@ -1099,10 +1101,9 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
        }
 
        skb = skb_unshare(skb, GFP_ATOMIC);
-       if (!skb) {
-               *pskb = NULL;
+       *pskb = skb;
+       if (!skb)
                return RX_HANDLER_CONSUMED;
-       }
 
        pulled_sci = pskb_may_pull(skb, macsec_extra_len(true));
        if (!pulled_sci) {
@@ -1234,6 +1235,7 @@ deliver:
                macsec_rxsa_put(rx_sa);
        macsec_rxsc_put(rx_sc);
 
+       skb_orphan(skb);
        ret = gro_cells_receive(&macsec->gro_cells, skb);
        if (ret == NET_RX_SUCCESS)
                count_rx(dev, skb->len);
@@ -1341,7 +1343,7 @@ static int init_rx_sa(struct macsec_rx_sa *rx_sa, char *sak, int key_len,
 
        rx_sa->active = false;
        rx_sa->next_pn = 1;
-       atomic_set(&rx_sa->refcnt, 1);
+       refcount_set(&rx_sa->refcnt, 1);
        spin_lock_init(&rx_sa->lock);
 
        return 0;
@@ -1412,7 +1414,7 @@ static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci)
 
        rx_sc->sci = sci;
        rx_sc->active = true;
-       atomic_set(&rx_sc->refcnt, 1);
+       refcount_set(&rx_sc->refcnt, 1);
 
        secy = &macsec_priv(dev)->secy;
        rcu_assign_pointer(rx_sc->next, secy->rx_sc);
@@ -1438,7 +1440,7 @@ static int init_tx_sa(struct macsec_tx_sa *tx_sa, char *sak, int key_len,
        }
 
        tx_sa->active = false;
-       atomic_set(&tx_sa->refcnt, 1);
+       refcount_set(&tx_sa->refcnt, 1);
        spin_lock_init(&tx_sa->lock);
 
        return 0;
@@ -2410,7 +2412,7 @@ static int dump_secy(struct macsec_secy *secy, struct net_device *dev,
        if (!hdr)
                return -EMSGSIZE;
 
-       genl_dump_check_consistent(cb, hdr, &macsec_fam);
+       genl_dump_check_consistent(cb, hdr);
 
        if (nla_put_u32(skb, MACSEC_ATTR_IFINDEX, dev->ifindex))
                goto nla_put_failure;
@@ -3246,7 +3248,7 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
                                       &macsec_netdev_addr_lock_key,
                                       macsec_get_nest_level(dev));
 
-       err = netdev_upper_dev_link(real_dev, dev);
+       err = netdev_upper_dev_link(real_dev, dev, extack);
        if (err < 0)
                goto unregister;