浏览代码

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 <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
David S. Miller 13 年之前
父节点
当前提交
11604721a3
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      net/ipv4/ip_options.c

+ 6 - 3
net/ipv4/ip_options.c

@@ -253,12 +253,15 @@ int ip_options_compile(struct net *net,
 {
 {
 	__be32 spec_dst = (__force __be32) 0;
 	__be32 spec_dst = (__force __be32) 0;
 	unsigned char *pp_ptr = NULL;
 	unsigned char *pp_ptr = NULL;
+	struct rtable *rt = NULL;
 	unsigned char *optptr;
 	unsigned char *optptr;
 	unsigned char *iph;
 	unsigned char *iph;
 	int optlen, l;
 	int optlen, l;
 
 
 	if (skb != NULL) {
 	if (skb != NULL) {
-		spec_dst = fib_compute_spec_dst(skb);
+		rt = skb_rtable(skb);
+		if (rt)
+			spec_dst = fib_compute_spec_dst(skb);
 		optptr = (unsigned char *)&(ip_hdr(skb)[1]);
 		optptr = (unsigned char *)&(ip_hdr(skb)[1]);
 	} else
 	} else
 		optptr = opt->__data;
 		optptr = opt->__data;
@@ -330,7 +333,7 @@ int ip_options_compile(struct net *net,
 					pp_ptr = optptr + 2;
 					pp_ptr = optptr + 2;
 					goto error;
 					goto error;
 				}
 				}
-				if (skb) {
+				if (rt) {
 					memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
 					memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
 					opt->is_changed = 1;
 					opt->is_changed = 1;
 				}
 				}
@@ -372,7 +375,7 @@ int ip_options_compile(struct net *net,
 						goto error;
 						goto error;
 					}
 					}
 					opt->ts = optptr - iph;
 					opt->ts = optptr - iph;
-					if (skb)  {
+					if (rt)  {
 						memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
 						memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
 						timeptr = &optptr[optptr[2]+3];
 						timeptr = &optptr[optptr[2]+3];
 					}
 					}