ip: ip_options_compile() resilient to NULL skb route

Scot Doyle demonstrated ip_options_compile() could be called with an skb
without an attached route, using a setup involving a bridge, netfilter,
and forged IP packets.

Let's make ip_options_compile() and ip_options_rcv_srr() a bit more
robust, instead of changing bridge/netfilter code.

With help from Hiroaki SHIMODA.

Reported-by: Scot Doyle <lkml@scotdoyle.com>
Tested-by: Scot Doyle <lkml@scotdoyle.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Hiroaki SHIMODA <shimoda.hiroaki@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Eric Dumazet and committed by David S. Miller c65353da 49b4947a

+3 -3
+3 -3
net/ipv4/ip_options.c
··· 329 329 pp_ptr = optptr + 2; 330 330 goto error; 331 331 } 332 - if (skb) { 332 + if (rt) { 333 333 memcpy(&optptr[optptr[2]-1], &rt->rt_spec_dst, 4); 334 334 opt->is_changed = 1; 335 335 } ··· 371 371 goto error; 372 372 } 373 373 opt->ts = optptr - iph; 374 - if (skb) { 374 + if (rt) { 375 375 memcpy(&optptr[optptr[2]-1], &rt->rt_spec_dst, 4); 376 376 timeptr = (__be32*)&optptr[optptr[2]+3]; 377 377 } ··· 603 603 unsigned long orefdst; 604 604 int err; 605 605 606 - if (!opt->srr) 606 + if (!opt->srr || !rt) 607 607 return 0; 608 608 609 609 if (skb->pkt_type != PACKET_HOST)