Commit 825b517a authored by Willem de Bruijn's avatar Willem de Bruijn Committed by Kamal Mostafa

packet: validate variable length ll headers

[ Upstream commit 9ed988cd ]

Replace link layer header validation check ll_header_truncate with
more generic dev_validate_header.

Validation based on hard_header_len incorrectly drops valid packets
in variable length protocols, such as AX25. dev_validate_header
calls header_ops.validate for such protocols to ensure correctness
below hard_header_len.

See also http://comments.gmane.org/gmane.linux.network/401064

Fixes 9c707762 ("packet: make packet_snd fail on len smaller than l2 header")
Signed-off-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent 602307c5
...@@ -1797,6 +1797,10 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg, ...@@ -1797,6 +1797,10 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
goto retry; goto retry;
} }
if (!dev_validate_header(dev, skb->data, len)) {
err = -EINVAL;
goto out_unlock;
}
if (len > (dev->mtu + dev->hard_header_len + extra_len) && if (len > (dev->mtu + dev->hard_header_len + extra_len) &&
!packet_extra_vlan_len_allowed(dev, skb)) { !packet_extra_vlan_len_allowed(dev, skb)) {
err = -EMSGSIZE; err = -EMSGSIZE;
...@@ -2207,18 +2211,6 @@ static void tpacket_destruct_skb(struct sk_buff *skb) ...@@ -2207,18 +2211,6 @@ static void tpacket_destruct_skb(struct sk_buff *skb)
sock_wfree(skb); sock_wfree(skb);
} }
static bool ll_header_truncated(const struct net_device *dev, int len)
{
/* net device doesn't like empty head */
if (unlikely(len <= dev->hard_header_len)) {
net_warn_ratelimited("%s: packet size is too short (%d <= %d)\n",
current->comm, len, dev->hard_header_len);
return true;
}
return false;
}
static void tpacket_set_protocol(const struct net_device *dev, static void tpacket_set_protocol(const struct net_device *dev,
struct sk_buff *skb) struct sk_buff *skb)
{ {
...@@ -2301,19 +2293,19 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, ...@@ -2301,19 +2293,19 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
if (unlikely(err < 0)) if (unlikely(err < 0))
return -EINVAL; return -EINVAL;
} else if (dev->hard_header_len) { } else if (dev->hard_header_len) {
if (ll_header_truncated(dev, tp_len)) int hdrlen = min_t(int, dev->hard_header_len, tp_len);
return -EINVAL;
skb_push(skb, dev->hard_header_len); skb_push(skb, dev->hard_header_len);
err = skb_store_bits(skb, 0, data, err = skb_store_bits(skb, 0, data, hdrlen);
dev->hard_header_len);
if (unlikely(err)) if (unlikely(err))
return err; return err;
if (!dev_validate_header(dev, skb->data, hdrlen))
return -EINVAL;
if (!skb->protocol) if (!skb->protocol)
tpacket_set_protocol(dev, skb); tpacket_set_protocol(dev, skb);
data += dev->hard_header_len; data += hdrlen;
to_write -= dev->hard_header_len; to_write -= hdrlen;
} }
offset = offset_in_page(data); offset = offset_in_page(data);
...@@ -2636,9 +2628,6 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) ...@@ -2636,9 +2628,6 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len); offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len);
if (unlikely(offset < 0)) if (unlikely(offset < 0))
goto out_free; goto out_free;
} else {
if (ll_header_truncated(dev, len))
goto out_free;
} }
/* Returns -EFAULT on error */ /* Returns -EFAULT on error */
...@@ -2646,6 +2635,12 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) ...@@ -2646,6 +2635,12 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
if (err) if (err)
goto out_free; goto out_free;
if (sock->type == SOCK_RAW &&
!dev_validate_header(dev, skb->data, len)) {
err = -EINVAL;
goto out_free;
}
sock_tx_timestamp(sk, &skb_shinfo(skb)->tx_flags); sock_tx_timestamp(sk, &skb_shinfo(skb)->tx_flags);
if (!gso_type && (len > dev->mtu + reserve + extra_len) && if (!gso_type && (len > dev->mtu + reserve + extra_len) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment