Skip to content

Commit

Permalink
netfilter: ipset: Make invalid MAC address checks consistent
Browse files Browse the repository at this point in the history
Set types bitmap:ipmac and hash:ipmac check that MAC addresses
are not all zeroes.

Introduce one missing check, and make the remaining ones
consistent, using is_zero_ether_addr() instead of comparing
against an array containing zeroes.

This was already done for hash:mac sets in commit 26c97c5
("netfilter: ipset: Use is_zero_ether_addr instead of static and
memcmp").

Signed-off-by: Stefano Brivio <[email protected]>
Signed-off-by: Jozsef Kadlecsik <[email protected]>
  • Loading branch information
sbrivio-rh authored and Jozsef Kadlecsik committed Oct 22, 2018
1 parent 8cc4ccf commit 29edbc3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 3 additions & 0 deletions net/netfilter/ipset/ip_set_bitmap_ipmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ bitmap_ipmac_kadt(struct ip_set *set, const struct sk_buff *skb,
else
ether_addr_copy(e.ether, eth_hdr(skb)->h_dest);

if (is_zero_ether_addr(e.ether))
return -EINVAL;

return adtfn(set, &e, &ext, &opt->ext, opt->cmdflags);
}

Expand Down
11 changes: 4 additions & 7 deletions net/netfilter/ipset/ip_set_hash_ipmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ MODULE_ALIAS("ip_set_hash:ip,mac");
/* Type specific function prefix */
#define HTYPE hash_ipmac

/* Zero valued element is not supported */
static const unsigned char invalid_ether[ETH_ALEN] = { 0 };

/* IPv4 variant */

/* Member elements */
Expand Down Expand Up @@ -108,7 +105,7 @@ hash_ipmac4_kadt(struct ip_set *set, const struct sk_buff *skb,
else
ether_addr_copy(e.ether, eth_hdr(skb)->h_dest);

if (ether_addr_equal(e.ether, invalid_ether))
if (is_zero_ether_addr(e.ether))
return -EINVAL;

ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &e.ip);
Expand Down Expand Up @@ -144,7 +141,7 @@ hash_ipmac4_uadt(struct ip_set *set, struct nlattr *tb[],
if (ret)
return ret;
memcpy(e.ether, nla_data(tb[IPSET_ATTR_ETHER]), ETH_ALEN);
if (ether_addr_equal(e.ether, invalid_ether))
if (is_zero_ether_addr(e.ether))
return -IPSET_ERR_HASH_ELEM;

return adtfn(set, &e, &ext, &ext, flags);
Expand Down Expand Up @@ -224,7 +221,7 @@ hash_ipmac6_kadt(struct ip_set *set, const struct sk_buff *skb,
else
ether_addr_copy(e.ether, eth_hdr(skb)->h_dest);

if (ether_addr_equal(e.ether, invalid_ether))
if (is_zero_ether_addr(e.ether))
return -EINVAL;

ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &e.ip.in6);
Expand Down Expand Up @@ -264,7 +261,7 @@ hash_ipmac6_uadt(struct ip_set *set, struct nlattr *tb[],
return ret;

memcpy(e.ether, nla_data(tb[IPSET_ATTR_ETHER]), ETH_ALEN);
if (ether_addr_equal(e.ether, invalid_ether))
if (is_zero_ether_addr(e.ether))
return -IPSET_ERR_HASH_ELEM;

return adtfn(set, &e, &ext, &ext, flags);
Expand Down

0 comments on commit 29edbc3

Please sign in to comment.