Skip to content

Commit 99e5aca

Browse files
Ziyang Xuandavem330
Ziyang Xuan
authored andcommitted
ipv4: Fix potential uninit variable access bug in __ip_make_skb()
Like commit ea30388 ("ipv6: Fix an uninit variable access bug in __ip6_make_skb()"). icmphdr does not in skb linear region under the scenario of SOCK_RAW socket. Access icmp_hdr(skb)->type directly will trigger the uninit variable access bug. Use a local variable icmp_type to carry the correct value in different scenarios. Fixes: 96793b4 ("[IPV4]: Add ICMPMsgStats MIB (RFC 4293)") Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6e79bd2 commit 99e5aca

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

net/ipv4/ip_output.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -1570,9 +1570,19 @@ struct sk_buff *__ip_make_skb(struct sock *sk,
15701570
cork->dst = NULL;
15711571
skb_dst_set(skb, &rt->dst);
15721572

1573-
if (iph->protocol == IPPROTO_ICMP)
1574-
icmp_out_count(net, ((struct icmphdr *)
1575-
skb_transport_header(skb))->type);
1573+
if (iph->protocol == IPPROTO_ICMP) {
1574+
u8 icmp_type;
1575+
1576+
/* For such sockets, transhdrlen is zero when do ip_append_data(),
1577+
* so icmphdr does not in skb linear region and can not get icmp_type
1578+
* by icmp_hdr(skb)->type.
1579+
*/
1580+
if (sk->sk_type == SOCK_RAW && !inet_sk(sk)->hdrincl)
1581+
icmp_type = fl4->fl4_icmp_type;
1582+
else
1583+
icmp_type = icmp_hdr(skb)->type;
1584+
icmp_out_count(net, icmp_type);
1585+
}
15761586

15771587
ip_cork_release(cork);
15781588
out:

0 commit comments

Comments
 (0)