bonding: fix bond_arp_rcv() race of curr_active_slave
[firefly-linux-kernel-4.4.55.git] / drivers / net / bonding / bond_main.c
index afae7cab5cf64d376127ae905317a23e4c275383..bd70bbc7992cfea6aaaf49333316d280e7d152ce 100644 (file)
@@ -674,8 +674,8 @@ static void bond_do_fail_over_mac(struct bonding *bond,
 
                if (old_active) {
                        ether_addr_copy(tmp_mac, new_active->dev->dev_addr);
-                       memcpy(saddr.sa_data, old_active->dev->dev_addr,
-                              ETH_ALEN);
+                       ether_addr_copy(saddr.sa_data,
+                                       old_active->dev->dev_addr);
                        saddr.sa_family = new_active->dev->type;
                } else {
                        ether_addr_copy(saddr.sa_data, bond->dev->dev_addr);
@@ -1139,7 +1139,7 @@ static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
                        kfree_skb(skb);
                        return RX_HANDLER_CONSUMED;
                }
-               memcpy(eth_hdr(skb)->h_dest, bond->dev->dev_addr, ETH_ALEN);
+               ether_addr_copy(eth_hdr(skb)->h_dest, bond->dev->dev_addr);
        }
 
        return ret;
@@ -2254,6 +2254,7 @@ int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
                 struct slave *slave)
 {
        struct arphdr *arp = (struct arphdr *)skb->data;
+       struct slave *curr_active_slave;
        unsigned char *arp_ptr;
        __be32 sip, tip;
        int alen, is_arp = skb->protocol == __cpu_to_be16(ETH_P_ARP);
@@ -2299,6 +2300,8 @@ int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
                 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
                 &sip, &tip);
 
+       curr_active_slave = rcu_dereference(bond->curr_active_slave);
+
        /*
         * Backup slaves won't see the ARP reply, but do come through
         * here for each ARP probe (so we swap the sip/tip to validate
@@ -2312,11 +2315,12 @@ int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
         * is done to avoid endless looping when we can't reach the
         * arp_ip_target and fool ourselves with our own arp requests.
         */
+
        if (bond_is_active_slave(slave))
                bond_validate_arp(bond, slave, sip, tip);
-       else if (bond->curr_active_slave &&
-                time_after(slave_last_rx(bond, bond->curr_active_slave),
-                           bond->curr_active_slave->last_link_up))
+       else if (curr_active_slave &&
+                time_after(slave_last_rx(bond, curr_active_slave),
+                           curr_active_slave->last_link_up))
                bond_validate_arp(bond, slave, tip, sip);
 
 out_unlock: