From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60682C6FD18 for ; Tue, 18 Apr 2023 12:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231209AbjDRM6h (ORCPT ); Tue, 18 Apr 2023 08:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbjDRM6g (ORCPT ); Tue, 18 Apr 2023 08:58:36 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DDC23581 for ; Tue, 18 Apr 2023 05:58:34 -0700 (PDT) Received: from canpemm500006.china.huawei.com (unknown [7.192.105.130]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Q13m91qTwznbW1; Tue, 18 Apr 2023 20:54:49 +0800 (CST) Received: from [10.174.179.200] (10.174.179.200) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 18 Apr 2023 20:58:31 +0800 Subject: Re: [PATCH net v2] ipv4: Fix potential uninit variable access buf in __ip_make_skb() From: "Ziyang Xuan (William)" To: Willem de Bruijn , , , , , , References: <20230410014526.4035442-1-william.xuanziyang@huawei.com> <64341d839d862_7d2a4294d@willemb.c.googlers.com.notmuch> Message-ID: Date: Tue, 18 Apr 2023 20:58:31 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.200] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500006.china.huawei.com (7.192.105.130) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org >> Ziyang Xuan wrote: >>> Like commit ea30388baebc ("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: 96793b482540 ("[IPV4]: Add ICMPMsgStats MIB (RFC 4293)") >>> Signed-off-by: Ziyang Xuan >>> --- >>> v2: >>> - Use sk->sk_type not sk->sk_socket->type. >> >> This is reached through >> >> raw_sendmsg >> raw_probe_proto_opt >> ip_push_pending_frames >> ip_finish_skb >> __ip_make_skb >> >> At this point, the icmp header has already been copied into skb linear >> area. Is the isue that icmp_hdr/skb_transport_header is not set in >> this path? >> > Hello Willem, > > raw_sendmsg > ip_append_data(..., transhdrlen==0, ...) // !inet->hdrincl > > Parameter "transhdrlen" of ip_append_data() equals to 0 in raw_sendmsg() > not sizeof(struct icmphdr) as in ping_v4_sendmsg(). > > William Xuan. Hello Willem, Does my answer answer your doubts? William Xuan >>> --- >>> net/ipv4/ip_output.c | 12 +++++++++--- >>> 1 file changed, 9 insertions(+), 3 deletions(-) >>> >>> diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c >>> index 4e4e308c3230..21507c9ce0fc 100644 >>> --- a/net/ipv4/ip_output.c >>> +++ b/net/ipv4/ip_output.c >>> @@ -1570,9 +1570,15 @@ struct sk_buff *__ip_make_skb(struct sock *sk, >>> cork->dst = NULL; >>> skb_dst_set(skb, &rt->dst); >>> >>> - if (iph->protocol == IPPROTO_ICMP) >>> - icmp_out_count(net, ((struct icmphdr *) >>> - skb_transport_header(skb))->type); >>> + if (iph->protocol == IPPROTO_ICMP) { >>> + u8 icmp_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); >>> out: >>> -- >>> 2.25.1 >>> >> >> >> . >> > > . >