From: "Ziyang Xuan (William)" <william.xuanziyang@huawei.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
<davem@davemloft.net>, <dsahern@kernel.org>,
<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
<netdev@vger.kernel.org>
Subject: Re: [PATCH net v2] ipv4: Fix potential uninit variable access buf in __ip_make_skb()
Date: Wed, 19 Apr 2023 17:41:04 +0800 [thread overview]
Message-ID: <47a697fb-1f69-3a47-e6ee-6a6c2a3a3cdc@huawei.com> (raw)
In-Reply-To: <643ea8ff510b2_332aa4294c4@willemb.c.googlers.com.notmuch>
> Ziyang Xuan (William) wrote:
>>>> 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 <william.xuanziyang@huawei.com>
>>>>> ---
>>>>> 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?
>
> Thanks. Yes, that explains. Would you mind adding a comment to that
> effect. Sommething like
>
> /* for such sockets, transport hlen is zero and icmp_hdr incorrect */
> if (sk->sk_type == SOCK_RAW && !inet_sk(sk)->hdrincl)
>
That is fine. It will make other developers understand the logic here quickly.
> I missed your previous response, William. Sorry about that.
>
>> 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
>>>>>
>>>>
>>>>
>>>> .
>>>>
>>>
>>> .
>>>
>
>
> .
>
next prev parent reply other threads:[~2023-04-19 9:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-10 1:45 [PATCH net v2] ipv4: Fix potential uninit variable access buf in __ip_make_skb() Ziyang Xuan
2023-04-10 14:30 ` Willem de Bruijn
2023-04-11 9:39 ` Ziyang Xuan (William)
2023-04-18 12:58 ` Ziyang Xuan (William)
2023-04-18 14:28 ` Willem de Bruijn
2023-04-19 9:41 ` Ziyang Xuan (William) [this message]
2023-04-19 14:02 ` Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47a697fb-1f69-3a47-e6ee-6a6c2a3a3cdc@huawei.com \
--to=william.xuanziyang@huawei.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox