Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5021800ybl; Tue, 14 Jan 2020 02:07:29 -0800 (PST) X-Google-Smtp-Source: APXvYqwezXFrlsThuahTsb8Og84OYBZ5/fd58lG64zk0adtvHvOLEPtOfLvysOI+qd5Yui0YOLMK X-Received: by 2002:a9d:68d3:: with SMTP id i19mr15151387oto.71.1578996449678; Tue, 14 Jan 2020 02:07:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578996449; cv=none; d=google.com; s=arc-20160816; b=gwU+4JXlrZOttqyVTtWDDcELQ0KRfobwLenU8egjoTF210PPvLG25iWtFCaS1J5ds9 pQ7KG1782AubUlJsPHK+LfgZMpfvHkhi9QDJwXJZdQ2p1tkN3thdd32mQ19QuxKO7qFc wHcuOezCV503My3kTcwKCziFfIUjuHnQKLo20p2ZFRa1odvvfqeIq7U7svYaKosZ+JMX u56QvzcQ0eQ3afyW+CDZhx6gSVjYa3XOjSjJFfW1gPEOBnlTsxUTn9eh+OBUq58Rr/9k MkFtz3SlfmDSyutu3aqJFow9kwP+X5yr0qsnJNRQJmv9RMHp3PWtLAo7+4nL3bjo4XEM cRiA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hijgDoePQP+HhcSB0R60uz3nv3/4XwMYdd7rKh0Aaww=; b=bUe5GYPddUvpxYk+Msco7ughJfU2Cg7D5xwEhn0v90Qk4MGbMK/fTEeEVuzm5sByW7 KcldiQ4i+uv/Zf5uIlkU2hOQNphoEhKVEqGLaQsPyf+YvwogEiree9sDKqgISBHDvWx3 wnx/PT6LDciJ9WQFDKC6pBgdnkN6Kafou7W+XyNglIb07HnsTBJNomsRyi1o63ISzzsN 0FUnHAw44MtE8ST6piXyT9D94ZBgXYyp21tPIRDl9e7JUwm5Dyf44Hy85K+pZym8XOQk 1On9B/Ya+5p5aYRKf/MObslcFTgwNFKhPFoZa5ps1ngeUVSn9xk+VyGDFuBKVuJGHCLj RMPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=snuwBmex; 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 d17si6943191oij.136.2020.01.14.02.07.18; Tue, 14 Jan 2020 02:07:29 -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=pass header.i=@kernel.org header.s=default header.b=snuwBmex; 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 S1730287AbgANKGE (ORCPT + 99 others); Tue, 14 Jan 2020 05:06:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:34726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729225AbgANKGC (ORCPT ); Tue, 14 Jan 2020 05:06:02 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B4B02467A; Tue, 14 Jan 2020 10:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578996362; bh=EzNgiiWZ33n+Hg8gPGnUEB6TwMW3CwgI6GJIxqhBaLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=snuwBmexcIroCTXFUWFwaiZYdkfPt0ci1370m2WzsbMqHnBVmdP53czc7Lx+j023a o9lHK0kywDAD5f7f+fIDnNN3e9yKSvoZCAQjVbKP6nL7Nr5R34Zo5UJ8iwZdxhdpDa X6lvPYsHC9OxDY64E/cGF3z2Ql4TwH11RWc/d8J0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+b02ff0707a97e4e79ebb@syzkaller.appspotmail.com, Oliver Hartkopp , Marc Kleine-Budde Subject: [PATCH 5.4 36/78] can: can_dropped_invalid_skb(): ensure an initialized headroom in outgoing CAN sk_buffs Date: Tue, 14 Jan 2020 11:01:10 +0100 Message-Id: <20200114094358.465829190@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114094352.428808181@linuxfoundation.org> References: <20200114094352.428808181@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oliver Hartkopp commit e7153bf70c3496bac00e7e4f395bb8d8394ac0ea upstream. KMSAN sysbot detected a read access to an untinitialized value in the headroom of an outgoing CAN related sk_buff. When using CAN sockets this area is filled appropriately - but when using a packet socket this initialization is missing. The problematic read access occurs in the CAN receive path which can only be triggered when the sk_buff is sent through a (virtual) CAN interface. So we check in the sending path whether we need to perform the missing initializations. Fixes: d3b58c47d330d ("can: replace timestamp as unique skb attribute") Reported-by: syzbot+b02ff0707a97e4e79ebb@syzkaller.appspotmail.com Signed-off-by: Oliver Hartkopp Tested-by: Oliver Hartkopp Cc: linux-stable # >= v4.1 Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- include/linux/can/dev.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -18,6 +18,7 @@ #include #include #include +#include #include /* @@ -91,6 +92,36 @@ struct can_priv { #define get_can_dlc(i) (min_t(__u8, (i), CAN_MAX_DLC)) #define get_canfd_dlc(i) (min_t(__u8, (i), CANFD_MAX_DLC)) +/* Check for outgoing skbs that have not been created by the CAN subsystem */ +static inline bool can_skb_headroom_valid(struct net_device *dev, + struct sk_buff *skb) +{ + /* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */ + if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv))) + return false; + + /* af_packet does not apply CAN skb specific settings */ + if (skb->ip_summed == CHECKSUM_NONE) { + /* init headroom */ + can_skb_prv(skb)->ifindex = dev->ifindex; + can_skb_prv(skb)->skbcnt = 0; + + skb->ip_summed = CHECKSUM_UNNECESSARY; + + /* preform proper loopback on capable devices */ + if (dev->flags & IFF_ECHO) + skb->pkt_type = PACKET_LOOPBACK; + else + skb->pkt_type = PACKET_HOST; + + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb_reset_transport_header(skb); + } + + return true; +} + /* Drop a given socketbuffer if it does not contain a valid CAN frame. */ static inline bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) @@ -108,6 +139,9 @@ static inline bool can_dropped_invalid_s } else goto inval_skb; + if (!can_skb_headroom_valid(dev, skb)) + goto inval_skb; + return false; inval_skb: