Skip to content

Commit 1160472

Browse files
committed
ipv4: Fix crashes in ip_options_compile().
The spec_dst uses should be guarded by skb_rtable() being non-NULL not just the SKB being non-null. Reported-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e87183c commit 1160472

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

net/ipv4/ip_options.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,15 @@ int ip_options_compile(struct net *net,
253253
{
254254
__be32 spec_dst = (__force __be32) 0;
255255
unsigned char *pp_ptr = NULL;
256+
struct rtable *rt = NULL;
256257
unsigned char *optptr;
257258
unsigned char *iph;
258259
int optlen, l;
259260

260261
if (skb != NULL) {
261-
spec_dst = fib_compute_spec_dst(skb);
262+
rt = skb_rtable(skb);
263+
if (rt)
264+
spec_dst = fib_compute_spec_dst(skb);
262265
optptr = (unsigned char *)&(ip_hdr(skb)[1]);
263266
} else
264267
optptr = opt->__data;
@@ -330,7 +333,7 @@ int ip_options_compile(struct net *net,
330333
pp_ptr = optptr + 2;
331334
goto error;
332335
}
333-
if (skb) {
336+
if (rt) {
334337
memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
335338
opt->is_changed = 1;
336339
}
@@ -372,7 +375,7 @@ int ip_options_compile(struct net *net,
372375
goto error;
373376
}
374377
opt->ts = optptr - iph;
375-
if (skb) {
378+
if (rt) {
376379
memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
377380
timeptr = &optptr[optptr[2]+3];
378381
}

0 commit comments

Comments
 (0)