Skip to content

Commit

Permalink
udp: ipv4: fix potential use after free in udp_v4_early_demux()
Browse files Browse the repository at this point in the history
pskb_may_pull() can reallocate skb->head, we need to move the
initialization of iph and uh pointers after its call.

Fixes: 421b388 ("udp: ipv4: Add udp early demux")
Signed-off-by: Eric Dumazet <[email protected]>
Cc: Shawn Bohrer <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Dec 11, 2013
1 parent ce232ce commit 610438b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1909,17 +1909,20 @@ static struct sock *__udp4_lib_demux_lookup(struct net *net,

void udp_v4_early_demux(struct sk_buff *skb)
{
const struct iphdr *iph = ip_hdr(skb);
const struct udphdr *uh = udp_hdr(skb);
struct net *net = dev_net(skb->dev);
const struct iphdr *iph;
const struct udphdr *uh;
struct sock *sk;
struct dst_entry *dst;
struct net *net = dev_net(skb->dev);
int dif = skb->dev->ifindex;

/* validate the packet */
if (!pskb_may_pull(skb, skb_transport_offset(skb) + sizeof(struct udphdr)))
return;

iph = ip_hdr(skb);
uh = udp_hdr(skb);

if (skb->pkt_type == PACKET_BROADCAST ||
skb->pkt_type == PACKET_MULTICAST)
sk = __udp4_lib_mcast_demux_lookup(net, uh->dest, iph->daddr,
Expand Down

0 comments on commit 610438b

Please sign in to comment.