From: Eric Dumazet <eric.dumazet@gmail.com>
To: Oliver Hartkopp <socketcan@hartkopp.net>,
Eric Dumazet <eric.dumazet@gmail.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
syzbot <syzbot+b02ff0707a97e4e79ebb@syzkaller.appspotmail.com>,
davem@davemloft.net, glider@google.com,
linux-can@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Re: KMSAN: uninit-value in can_receive
Date: Tue, 19 Nov 2019 13:09:16 -0800 [thread overview]
Message-ID: <92c04159-b83a-3e33-91da-25a727a692d0@gmail.com> (raw)
In-Reply-To: <3142c032-e46a-531c-d1b8-d532e5b403a6@hartkopp.net>
On 11/19/19 12:24 PM, Oliver Hartkopp wrote:
> Hi Eric,
>
> On 19/11/2019 17.53, Eric Dumazet wrote:
>>
>>
>> On 11/18/19 11:35 PM, Oliver Hartkopp wrote:
>>>
>>
>>>
>>> See ioctl$ifreq https://syzkaller.appspot.com/x/log.txt?x=14563416e00000
>>>
>>> 23:11:34 executing program 2:
>>> r0 = socket(0x200000000000011, 0x3, 0x0)
>>> ioctl$ifreq_SIOCGIFINDEX_vcan(r0, 0x8933, &(0x7f0000000040)={'vxcan1\x00', <r1=>0x0})
>>> bind$packet(r0, &(0x7f0000000300)={0x11, 0xc, r1}, 0x14)
>>> sendmmsg(r0, &(0x7f0000000d00), 0x400004e, 0x0)
>>>
>>> We only can receive skbs from (v(x))can devices.
>>> No matter if someone wrote to them via PF_CAN or PF_PACKET.
>>> We check for ETH_P_CAN(FD) type and ARPHRD_CAN dev type at rx time.
>>
>> And what entity sets the can_skb_prv(skb)->skbcnt to zero exactly ?
>>
>>>
>>>>> We additionally might think about introducing a check whether we have a
>>>>> can_skb_reserve() created skbuff.
>>>>>
>>>>> But even if someone forged a skbuff without this reserved space the
>>>>> access to can_skb_prv(skb)->skbcnt would point into some CAN frame
>>>>> content - which is still no access to uninitialized content, right?
>>>
>>> So this question remains still valid whether we have a false positive from KMSAN here.
>>
>> I do not believe it is a false positive.
>>
>> It seems CAN relies on some properties of low level drivers using alloc_can_skb() or similar function.
>>
>> Why not simply fix this like that ?
>>
>> diff --git a/net/can/af_can.c b/net/can/af_can.c
>> index 128d37a4c2e0ba5d8db69fcceec8cbd6a79380df..3e71a78d82af84caaacd0ef512b5e894efbf4852 100644
>> --- a/net/can/af_can.c
>> +++ b/net/can/af_can.c
>> @@ -647,8 +647,9 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev)
>> pkg_stats->rx_frames_delta++;
>> /* create non-zero unique skb identifier together with *skb */
>> - while (!(can_skb_prv(skb)->skbcnt))
>> + do {
>> can_skb_prv(skb)->skbcnt = atomic_inc_return(&skbcounter);
>> + } while (!(can_skb_prv(skb)->skbcnt));
>> rcu_read_lock();
>>
>
> Please check commit d3b58c47d330d ("can: replace timestamp as unique skb attribute").
Oh well... This notion of 'unique skb attribute' is interesting...
>
> can_skb_prv(skb)->skbcnt is set to 0 at skb creation time when sending CAN frames from local host or receiving CAN frames from a real CAN interface.
We can not enforce this to happen with a virtual interface.
>
> When a CAN skb is received by the net layer the *first* time it gets a unique value which we need for a per-cpu filter mechanism in raw_rcv().
>
> So where's the problem to check for (!(can_skb_prv(skb)->skbcnt)) in a while statement? I can't see a chance for an uninitialized value there.
You have to make sure the packet has been properly cooked by a 'real CAN interface' then, and reject them if not.
next prev parent reply other threads:[~2019-11-19 21:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-18 19:05 KMSAN: uninit-value in can_receive syzbot
2019-11-18 20:25 ` Oliver Hartkopp
2019-11-18 20:29 ` Marc Kleine-Budde
2019-11-18 20:49 ` Oliver Hartkopp
2019-11-18 21:15 ` Marc Kleine-Budde
2019-11-19 7:35 ` Oliver Hartkopp
2019-11-19 9:00 ` Oleksij Rempel
2019-11-19 10:08 ` Dmitry Vyukov
2019-11-19 13:06 ` Alexander Potapenko
2019-11-19 16:53 ` Eric Dumazet
2019-11-19 20:24 ` Oliver Hartkopp
2019-11-19 21:09 ` Eric Dumazet [this message]
2019-11-20 20:10 ` Oliver Hartkopp
2019-12-03 10:09 ` Marc Kleine-Budde
2019-12-03 10:37 ` Oliver Hartkopp
2019-12-03 10:40 ` Marc Kleine-Budde
2019-11-26 9:00 ` syzbot
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=92c04159-b83a-3e33-91da-25a727a692d0@gmail.com \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=glider@google.com \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=socketcan@hartkopp.net \
--cc=syzbot+b02ff0707a97e4e79ebb@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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;
as well as URLs for NNTP newsgroup(s).