OSDN Git Service

Merge tag 'v4.4.214' into 10
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / drivers / net / bonding / bond_alb.c
index 82d23bd..0615522 100644 (file)
@@ -1371,26 +1371,31 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
        bool do_tx_balance = true;
        u32 hash_index = 0;
        const u8 *hash_start = NULL;
-       struct ipv6hdr *ip6hdr;
 
        skb_reset_mac_header(skb);
        eth_data = eth_hdr(skb);
 
        switch (ntohs(skb->protocol)) {
        case ETH_P_IP: {
-               const struct iphdr *iph = ip_hdr(skb);
+               const struct iphdr *iph;
 
                if (ether_addr_equal_64bits(eth_data->h_dest, mac_bcast) ||
-                   (iph->daddr == ip_bcast) ||
-                   (iph->protocol == IPPROTO_IGMP)) {
+                   (!pskb_network_may_pull(skb, sizeof(*iph)))) {
+                       do_tx_balance = false;
+                       break;
+               }
+               iph = ip_hdr(skb);
+               if (iph->daddr == ip_bcast || iph->protocol == IPPROTO_IGMP) {
                        do_tx_balance = false;
                        break;
                }
                hash_start = (char *)&(iph->daddr);
                hash_size = sizeof(iph->daddr);
-       }
                break;
-       case ETH_P_IPV6:
+       }
+       case ETH_P_IPV6: {
+               const struct ipv6hdr *ip6hdr;
+
                /* IPv6 doesn't really use broadcast mac address, but leave
                 * that here just in case.
                 */
@@ -1407,7 +1412,11 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
                        break;
                }
 
-               /* Additianally, DAD probes should not be tx-balanced as that
+               if (!pskb_network_may_pull(skb, sizeof(*ip6hdr))) {
+                       do_tx_balance = false;
+                       break;
+               }
+               /* Additionally, DAD probes should not be tx-balanced as that
                 * will lead to false positives for duplicate addresses and
                 * prevent address configuration from working.
                 */
@@ -1417,17 +1426,26 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
                        break;
                }
 
-               hash_start = (char *)&(ipv6_hdr(skb)->daddr);
-               hash_size = sizeof(ipv6_hdr(skb)->daddr);
+               hash_start = (char *)&ip6hdr->daddr;
+               hash_size = sizeof(ip6hdr->daddr);
                break;
-       case ETH_P_IPX:
-               if (ipx_hdr(skb)->ipx_checksum != IPX_NO_CHECKSUM) {
+       }
+       case ETH_P_IPX: {
+               const struct ipxhdr *ipxhdr;
+
+               if (pskb_network_may_pull(skb, sizeof(*ipxhdr))) {
+                       do_tx_balance = false;
+                       break;
+               }
+               ipxhdr = (struct ipxhdr *)skb_network_header(skb);
+
+               if (ipxhdr->ipx_checksum != IPX_NO_CHECKSUM) {
                        /* something is wrong with this packet */
                        do_tx_balance = false;
                        break;
                }
 
-               if (ipx_hdr(skb)->ipx_type != IPX_TYPE_NCP) {
+               if (ipxhdr->ipx_type != IPX_TYPE_NCP) {
                        /* The only protocol worth balancing in
                         * this family since it has an "ARP" like
                         * mechanism
@@ -1436,9 +1454,11 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
                        break;
                }
 
+               eth_data = eth_hdr(skb);
                hash_start = (char *)eth_data->h_dest;
                hash_size = ETH_ALEN;
                break;
+       }
        case ETH_P_ARP:
                do_tx_balance = false;
                if (bond_info->rlb_enabled)