Commit 99e5acae authored by Ziyang Xuan's avatar Ziyang Xuan Committed by David S. Miller

ipv4: Fix potential uninit variable access bug in __ip_make_skb()

Like commit ea30388b ("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: 96793b48 ("[IPV4]: Add ICMPMsgStats MIB (RFC 4293)")
Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarZiyang Xuan <william.xuanziyang@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6e79bd28
...@@ -1570,9 +1570,19 @@ struct sk_buff *__ip_make_skb(struct sock *sk, ...@@ -1570,9 +1570,19 @@ struct sk_buff *__ip_make_skb(struct sock *sk,
cork->dst = NULL; cork->dst = NULL;
skb_dst_set(skb, &rt->dst); skb_dst_set(skb, &rt->dst);
if (iph->protocol == IPPROTO_ICMP) if (iph->protocol == IPPROTO_ICMP) {
icmp_out_count(net, ((struct icmphdr *) u8 icmp_type;
skb_transport_header(skb))->type);
/* For such sockets, transhdrlen is zero when do ip_append_data(),
* so icmphdr does not in skb linear region and can not get icmp_type
* by icmp_hdr(skb)->type.
*/
if (sk->sk_type == SOCK_RAW && !inet_sk(sk)->hdrincl)
icmp_type = fl4->fl4_icmp_type;
else
icmp_type = icmp_hdr(skb)->type;
icmp_out_count(net, icmp_type);
}
ip_cork_release(cork); ip_cork_release(cork);
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment