Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp988679ybc; Tue, 19 Nov 2019 12:32:57 -0800 (PST) X-Google-Smtp-Source: APXvYqwfbxmlHT2tTRvCovk1aPYbcZw7OldM+BkDJOijaFRgUJmzOsihjqEHGXQDKVSR19pZuf2J X-Received: by 2002:a17:906:e087:: with SMTP id gh7mr33079889ejb.278.1574195577025; Tue, 19 Nov 2019 12:32:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574195577; cv=none; d=google.com; s=arc-20160816; b=kMSbiLtHjHqClg1Mh+b0JUrxwEFtkn9sfVaK/k4vdvPeBzxca+8yJmPXAW6jKcbwbR n+dfF7jRnvBB4/Xp7VaN6HaQWyQnOKWBTDzPc39UybpKvFEFbxugP9f9fxqCLtGGmhzS flZmKWJVfQaFpqxoSmC7bXLUjbk3rkjNeiXuhq8mDRQV36ZGjfjR2rl0sNWARzPwyD+o ZBfpNS0FeIqwrIEifSB3X9qkHo6yo3p7OhwcrwkiU88razDVZMiN20XyyJfUOesTTFhk 98LFb4ZVWtIEoYFSAos/ACpFEFgeCToYduhuc7aGIxu3sly+nAeAOjv0WlF4RCRTNW8f W8nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=WB13vBsyEr7/Hk93hoXjpA0FmbMZk0HVGJEgs02Tlxs=; b=HBir+0IoqD37JzYDvIsASzh72SVlDOpksn7hm0eO4hP8eRinjpUf22McuKk+QRoex1 r1OjLVpeQQzv6WGJ8WyYM7kJOt2SPEQuHF/vsGnYV+x3EBHRZNfcQ5EpNEBaRN4Nojd+ G+xYf88KbAGUHt/7Pm97kIBnjrzZgR/MqUJlfN3OInX5pXeQaarK4AAHPPnB37vnQD5e OU5LKA87aFYaQy2RsEhmkQIJM5+31iUM7rWjTnwWwDZiaZq0nWEXMYYvej1RJEgo1PYx 9D5V45i4TOrOA5aPXm1N2e0P0N5zSw+etQxbr62ZMAcYMWdmQDiReWTtXfTZGKvWyLMN K/qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hartkopp.net header.s=strato-dkim-0002 header.b=BPIZmvde; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b18si14513340eje.20.2019.11.19.12.32.31; Tue, 19 Nov 2019 12:32:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@hartkopp.net header.s=strato-dkim-0002 header.b=BPIZmvde; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727436AbfKSUbH (ORCPT + 99 others); Tue, 19 Nov 2019 15:31:07 -0500 Received: from mo4-p01-ob.smtp.rzone.de ([81.169.146.164]:28244 "EHLO mo4-p01-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726711AbfKSUbG (ORCPT ); Tue, 19 Nov 2019 15:31:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1574195464; s=strato-dkim-0002; d=hartkopp.net; h=In-Reply-To:Date:Message-ID:From:References:To:Subject: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=WB13vBsyEr7/Hk93hoXjpA0FmbMZk0HVGJEgs02Tlxs=; b=BPIZmvdeBEFw5U85Je6pSvMKg/8XfUwgNs5o5D/2nvruakyzvxe+tJIkIEIev8SxvO hZSJjzU95XltVXS163ROrdvmIB6ar25FCg6tf9uHTqEEhb/ieWdkE4U2Aznp1gI8GQ4z FomjRpcl8utzL72VDu3EiTctJQKe9C1RfE7dpeG58avOqBIYUo79/WrFnttw73oNS6XI xGEAk44boVWhNNPFdgdnwq29p5QowXf4BTmBW9KhgF2lyhT5UF6I9VkuJHScYg23BZAn vyySRSTXnzAClWNC+VVkYseTeU3sFSip7EvL+joMlkORTkTO/M61aZpDjJ7jhp/GYw0w RGXA== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjG14FZxedJy6qgO1o3PMaViOoLMJVch5l0xf" X-RZG-CLASS-ID: mo00 Received: from [192.168.1.177] by smtp.strato.de (RZmta 44.29.0 DYNA|AUTH) with ESMTPSA id C03a03vAJKOx5a0 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Tue, 19 Nov 2019 21:24:59 +0100 (CET) Subject: Re: KMSAN: uninit-value in can_receive To: Eric Dumazet , Marc Kleine-Budde , syzbot , davem@davemloft.net, glider@google.com, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com References: <0000000000005c08d10597a3a05d@google.com> <7934bc2b-597f-0bb3-be2d-32f3b07b4de9@hartkopp.net> <7f5c4546-0c1a-86ae-581e-0203b5fca446@pengutronix.de> <1f7d6ea7-152e-ff18-549c-b196d8b5e3a7@hartkopp.net> <9e06266a-67f3-7352-7b87-2b9144c7c9a9@gmail.com> From: Oliver Hartkopp Message-ID: <3142c032-e46a-531c-d1b8-d532e5b403a6@hartkopp.net> Date: Tue, 19 Nov 2019 21:24:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <9e06266a-67f3-7352-7b87-2b9144c7c9a9@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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', 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"). 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. 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. Regards, Oliver