Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1238154pxu; Mon, 23 Nov 2020 15:36:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxyVVnKY6LjC0V5hQM2ZTm0UhEKpN8sn0GC5GUHTWx4n+U7UCUfqkXsuma0+BmPvgBnvghz X-Received: by 2002:a17:906:4495:: with SMTP id y21mr1813112ejo.209.1606174577432; Mon, 23 Nov 2020 15:36:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606174577; cv=none; d=google.com; s=arc-20160816; b=Qgr8wtAGZkk0ZF7CsUxRU//5MdIxcNnSHehpLAP3DJ6+p4Sw8l0iy8obkVulTTjF3X 49bJC/fKnpjVRzW5fAuA2wfFwv07y6q6KXombph/xj6DPZaDO7VovqMjMnVmiDZ0CShf yS05U8sXamGj2fVvDVur/AiWWhU1U9ZH/lewrimq3TD+rK+bLLHmYDMwrzel1EnBt2w1 +r+0MGNMMOmIXZoIwjkd/3COJgiyJ4bMq1zue+u1XDxETMrEM85n8klJNGtQLqdX4AMM rgdwbMrH5bu5CvIcdSETQeScGoPtfbmGGfyPYJnrGCkmrtIlpMRul84M9czB/fsAE8wd xHSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PyELE0+xitmSEB+qYS0qHvXc4E7Iofk7BMMLj3BiboQ=; b=RxzE1lOGoWz/GIKiOEwxzDJQL1gRwhUU9bbVrUXvHxvqJ6ADPEj3j7OgnMesq9Pofm LcTSOYwAR2DO05bk9ssBm8ubE/gCGZGjjXLz9Dy+IEEjvCqs5km4ZfflrGJZFW3cugFO g4WpzGB4bak2aA3hLozeRIfeIj1LXoc0ItvnUfWSZmTUqn2rcLT62W8seMOUI8927xB9 YVkFbe09B4hlQ2LZ/MUs0oW0arCpDzgi7N7ZWW3y0kZRrAjmpL6DQ/iMhDCzJI7eiuBz X7PnegCV/XbZLdFEG9S+SFhQJOJKk2XH1K9x4/1g2XDY0pQQ3R2cAqrscJcdM6EX3aE/ ZnMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FwxTUjzG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f18si7569769eds.8.2020.11.23.15.35.54; Mon, 23 Nov 2020 15:36:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FwxTUjzG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731875AbgKWMhG (ORCPT + 99 others); Mon, 23 Nov 2020 07:37:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:49154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731852AbgKWMhB (ORCPT ); Mon, 23 Nov 2020 07:37:01 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 09FD62076E; Mon, 23 Nov 2020 12:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135020; bh=f31GyTFKZwGV9LB58bMPchShsBodOSwsNdYE+5SE1Ps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FwxTUjzGCD6tUDqtPGQJOwzb+u9u9EFNCvbgw4JmJzIZov2qmDOkTuqKcC0iTu2wV 2mqZD69XH7bvwVdWiOhv1SopemHU/QWo2OvRmZvo5lNAAFaA5YRSU5Z0O67u9RAkAv QN9nReDrTqa3qqrPhYCdQiiarYBOT6L+a6jqF4qI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+9bcb0c9409066696d3aa@syzkaller.appspotmail.com, Anant Thazhemadam , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.4 075/158] can: af_can: prevent potential access of uninitialized member in can_rcv() Date: Mon, 23 Nov 2020 13:21:43 +0100 Message-Id: <20201123121823.557093324@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anant Thazhemadam [ Upstream commit c8c958a58fc67f353289986850a0edf553435702 ] In can_rcv(), cfd->len is uninitialized when skb->len = 0, and this uninitialized cfd->len is accessed nonetheless by pr_warn_once(). Fix this uninitialized variable access by checking cfd->len's validity condition (cfd->len > CAN_MAX_DLEN) separately after the skb->len's condition is checked, and appropriately modify the log messages that are generated as well. In case either of the required conditions fail, the skb is freed and NET_RX_DROP is returned, same as before. Fixes: 8cb68751c115 ("can: af_can: can_rcv(): replace WARN_ONCE by pr_warn_once") Reported-by: syzbot+9bcb0c9409066696d3aa@syzkaller.appspotmail.com Tested-by: Anant Thazhemadam Signed-off-by: Anant Thazhemadam Link: https://lore.kernel.org/r/20201103213906.24219-2-anant.thazhemadam@gmail.com Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- net/can/af_can.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/net/can/af_can.c b/net/can/af_can.c index 128d37a4c2e0b..09d2329719c17 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -675,16 +675,25 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev, { struct canfd_frame *cfd = (struct canfd_frame *)skb->data; - if (unlikely(dev->type != ARPHRD_CAN || skb->len != CAN_MTU || - cfd->len > CAN_MAX_DLEN)) { - pr_warn_once("PF_CAN: dropped non conform CAN skbuf: dev type %d, len %d, datalen %d\n", + if (unlikely(dev->type != ARPHRD_CAN || skb->len != CAN_MTU)) { + pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n", + dev->type, skb->len); + goto free_skb; + } + + /* This check is made separately since cfd->len would be uninitialized if skb->len = 0. */ + if (unlikely(cfd->len > CAN_MAX_DLEN)) { + pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d, datalen %d\n", dev->type, skb->len, cfd->len); - kfree_skb(skb); - return NET_RX_DROP; + goto free_skb; } can_receive(skb, dev); return NET_RX_SUCCESS; + +free_skb: + kfree_skb(skb); + return NET_RX_DROP; } static int canfd_rcv(struct sk_buff *skb, struct net_device *dev, -- 2.27.0