Commit 143a8526 authored by Guillaume Nault's avatar Guillaume Nault Committed by Jakub Kicinski

bareudp: Fix invalid read beyond skb's linear data

Data beyond the UDP header might not be part of the skb's linear data.
Use skb_copy_bits() instead of direct access to skb->data+X, so that
we read the correct bytes even on a fragmented skb.

Fixes: 4b5f6723 ("net: Special handling for IP & MPLS.")
Signed-off-by: default avatarGuillaume Nault <gnault@redhat.com>
Link: https://lore.kernel.org/r/7741c46545c6ef02e70c80a9b32814b22d9616b3.1628264975.git.gnault@redhat.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d6e712aa
...@@ -71,12 +71,18 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb) ...@@ -71,12 +71,18 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
family = AF_INET6; family = AF_INET6;
if (bareudp->ethertype == htons(ETH_P_IP)) { if (bareudp->ethertype == htons(ETH_P_IP)) {
struct iphdr *iphdr; __u8 ipversion;
iphdr = (struct iphdr *)(skb->data + BAREUDP_BASE_HLEN); if (skb_copy_bits(skb, BAREUDP_BASE_HLEN, &ipversion,
if (iphdr->version == 4) { sizeof(ipversion))) {
proto = bareudp->ethertype; bareudp->dev->stats.rx_dropped++;
} else if (bareudp->multi_proto_mode && (iphdr->version == 6)) { goto drop;
}
ipversion >>= 4;
if (ipversion == 4) {
proto = htons(ETH_P_IP);
} else if (ipversion == 6 && bareudp->multi_proto_mode) {
proto = htons(ETH_P_IPV6); proto = htons(ETH_P_IPV6);
} else { } else {
bareudp->dev->stats.rx_dropped++; bareudp->dev->stats.rx_dropped++;
......
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