Commit 1162563f82b434e3099c9e6c1bbdba846d792f0d

Authored by Jiri Pirko
Committed by David S. Miller
1 parent 9fe969345b

af_packet: move strict addr_len check right before dev_[mc/unicast]_[add/del]

My previous patch 914c8ad2d18b62ad1420f518c0cab0b0b90ab308 incorrectly changed
the length check in packet_mc_add to be more strict. The problem is that
userspace is not filling this field (and it stays zeroed) in case of setting
PACKET_MR_PROMISC or PACKET_MR_ALLMULTI. So move the strict check to the point
in path where the addr_len must be set correctly.

Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Reported-by: Pavel Roskin <proski@gnu.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 5 additions and 1 deletions Side-by-side Diff

net/packet/af_packet.c
... ... @@ -1688,6 +1688,8 @@
1688 1688 {
1689 1689 switch (i->type) {
1690 1690 case PACKET_MR_MULTICAST:
  1691 + if (i->alen != dev->addr_len)
  1692 + return -EINVAL;
1691 1693 if (what > 0)
1692 1694 return dev_mc_add(dev, i->addr, i->alen, 0);
1693 1695 else
... ... @@ -1700,6 +1702,8 @@
1700 1702 return dev_set_allmulti(dev, what);
1701 1703 break;
1702 1704 case PACKET_MR_UNICAST:
  1705 + if (i->alen != dev->addr_len)
  1706 + return -EINVAL;
1703 1707 if (what > 0)
1704 1708 return dev_unicast_add(dev, i->addr);
1705 1709 else
... ... @@ -1734,7 +1738,7 @@
1734 1738 goto done;
1735 1739  
1736 1740 err = -EINVAL;
1737   - if (mreq->mr_alen != dev->addr_len)
  1741 + if (mreq->mr_alen > dev->addr_len)
1738 1742 goto done;
1739 1743  
1740 1744 err = -ENOBUFS;