Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp281051ybc; Tue, 19 Nov 2019 01:03:19 -0800 (PST) X-Google-Smtp-Source: APXvYqyPXrxsbL6uUvmf3N3km1ODLJQ0PYBC9fyj4TKu7ZBPS4guk659Gs0aeFjGrzxKsJOIidlR X-Received: by 2002:a19:7b18:: with SMTP id w24mr2970202lfc.48.1574154199774; Tue, 19 Nov 2019 01:03:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574154199; cv=none; d=google.com; s=arc-20160816; b=0l4aAJqx8QsrQSFvFfJwamVguND3bvSdidF+hEf/yzydIBfL2oifyTirq2WPjKOg+k X5t+TqP87FvP+SjOEhZ1WDOncv9EQJIrYPww4wHH8j6JP0bJ0xsgU5TKYKwnp6Lbk9Wk FcJHndLL4C0ofDIpGE3UaVL4JkZXpqG83R1tyk9LO53VudfHGsWnGpiHiU8x3LSwWmrE ZiagXuo2tSkFff+T+RkQZ043xmmI+n8UnbO4zzQ2DMOLreAV4MrRc58f1fI3PKmXMsLz pfwMQ4Kw+X5a2VXZbrkaWgy0oCKu9tMw+WIoWIFw4UOMj2H9xrkTFCdAD6X1/6sgLqS9 raDA== 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; bh=wx1kqWzdvcqLDDK0OMtIY5Dg62ni/DJWLTwdZyYv7hw=; b=L/k1uYOaGCs5FKH6qtaufwVQCBQhGwDtQObH9F1HIjz4sZOuvNvSpE8c8o9MZUk+fh ZR4d+sx8mLBlWaoEMQCiITSPzDaJtJWRX5Dxc2Jd8+A5W3xtcoPTDvlQ/Hc78ustRozU 3LOyLPPcoZZCTXjf/5uIUck4cxdhL3u2nJYOvrIqU5LimT/Zi1YK8jtecbxPXrxTt34W /JDC00NMN7NJCH9QJghZwXzA0vrfkGIACh14TxC53v8WuL+DBtUJXj5b8jCxQgEzTvYV U/2IwPE27znjbJX0UYPv6fCO1RxHp0jP0ptkpJzJelEO4Nt3PagjD1ksJTg3syYvdpUA iAzA== ARC-Authentication-Results: i=1; mx.google.com; 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 f12si13409614edy.41.2019.11.19.01.02.54; Tue, 19 Nov 2019 01:03:19 -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; 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 S1727082AbfKSJBF (ORCPT + 99 others); Tue, 19 Nov 2019 04:01:05 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:60017 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726833AbfKSJBD (ORCPT ); Tue, 19 Nov 2019 04:01:03 -0500 Received: from soja.hi.pengutronix.de ([2001:67c:670:100:3ad5:47ff:feaf:13da]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iWzNa-0002sl-E9; Tue, 19 Nov 2019 10:00:58 +0100 Subject: Re: KMSAN: uninit-value in can_receive To: Oliver Hartkopp , 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> From: Oleksij Rempel Message-ID: Date: Tue, 19 Nov 2019 10:00:56 +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: <1f7d6ea7-152e-ff18-549c-b196d8b5e3a7@hartkopp.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:3ad5:47ff:feaf:13da X-SA-Exim-Mail-From: o.rempel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 19.11.19 08:35, Oliver Hartkopp wrote: > > > On 18/11/2019 22.15, Marc Kleine-Budde wrote: >> On 11/18/19 9:49 PM, Oliver Hartkopp wrote: >>> >>> >>> On 18/11/2019 21.29, Marc Kleine-Budde wrote: >>>> On 11/18/19 9:25 PM, Oliver Hartkopp wrote: >>> >>>>>> IMPORTANT: if you fix the bug, please add the following tag to the commit: >>>>>> Reported-by: syzbot+b02ff0707a97e4e79ebb@syzkaller.appspotmail.com >>>>>> >>>>>> ===================================================== >>>>>> BUG: KMSAN: uninit-value in can_receive+0x23c/0x5e0 net/can/af_can.c:649 >>>>>> CPU: 1 PID: 3490 Comm: syz-executor.2 Not tainted 5.4.0-rc5+ #0 >>> >>>>> >>>>> In line 649 of 5.4.0-rc5+ we can find a while() statement: >>>>> >>>>> while (!(can_skb_prv(skb)->skbcnt)) >>>>>     can_skb_prv(skb)->skbcnt = atomic_inc_return(&skbcounter); >>>>> >>>>> In linux/include/linux/can/skb.h we see: >>>>> >>>>> static inline struct can_skb_priv *can_skb_prv(struct sk_buff *skb) >>>>> { >>>>>     return (struct can_skb_priv *)(skb->head); >>>>> } >>>>> >>>>> IMO accessing can_skb_prv(skb)->skbcnt at this point is a valid >>>>> operation which has no uninitialized value. >>>>> >>>>> Can this probably be a false positive of KMSAN? >>>> >>>> The packet is injected via the packet socket into the kernel. Where does >>>> skb->head point to in this case? When the skb is a proper >>>> kernel-generated skb containing a CAN-2.0 or CAN-FD frame skb->head is >>>> maybe properly initialized? >>> >>> The packet is either received via vcan or vxcan which checks via >>> can_dropped_invalid_skb() if we have a valid ETH_P_CAN type skb. >> >> According to the call stack it's injected into the kernel via a packet >> socket and not via v(x)can. > > 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. > >>> 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. It can be other incornation of this bug: https://github.com/linux-can/linux/issues/1 The echo skd was free, because socket which send this skb was closed before it was received. Kind regards, Oleksij Rempel -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |