Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp837219pxu; Mon, 23 Nov 2020 05:33:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzg45IG1k5B9Re83MEgfhA5EdrmHhYKTOENX4JFZ+0ItIx1busc3PqNLCgJ2kmIC4yHT151 X-Received: by 2002:aa7:c34c:: with SMTP id j12mr48245971edr.17.1606138389895; Mon, 23 Nov 2020 05:33:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606138389; cv=none; d=google.com; s=arc-20160816; b=FFuN/jZN8aq84DzNeS082YKQ6ZbF8n2l8QMMZTAobffP/S//c3mfXoiCD3Us+NcAw4 +pXkkhVogKTcxNgRhIWAqqhlXL3fQKzw2JInO9Dog4CYuxSMIRbQ94byZ3psvAGD8jKl FeGgORTnCp5gW6nBMoudQ0501j5bHBWGe5M8jJBQe/axN5Rx870XgxRUzDHYAZy2U7yP ECKnP6HVCQv1SVGDDYelWsY1ecAQnQ9Ui669IVc6fUh8FocpDaiFx4/ZHULHES7llKs9 YSdPefZM/t1B06YEI9PP+TH4JMiwuDAUaH+p3Yya0fOHiHGA6wfIuUxEEHJVPsU5xDPN 5M4g== 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=o8gyq3GsjuEGwj4fC2XUQDXpIIBZxIWp02on+O3tGy4=; b=hqYHINoCx57hiFFLJ7MqTxXpqUffPRhaOc9EolhLMe3iBP3UdQAk3NwprNsGxQuCPk VgK1IRMOW/5f9QYTlDpVkKh32vOYrlYX22RGcBlhpy4jxVRwwFFfTJbc5Z9AJS53DOAR xf21OwAuG3HG1u1pwarsYRP41ZC8/6uI3lPkoC+0S+YWVIqMZjA34fsPXst7Kur30HJH fxt+0zDLiZrj7NWahNNK8NrD8MD2yuuEjbsOh3DTl06yDZbWzHQz3HjuWNdNp3QIVsSg RntnVGdGen9SKUF6B310eDmRJsE/DDs7ZO5kXphWqiEjy54AutbClUWqXvoEDW78tybY AY6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CDWfUG4J; 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 q4si6241168edb.455.2020.11.23.05.32.46; Mon, 23 Nov 2020 05:33:09 -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=CDWfUG4J; 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 S2389217AbgKWN2T (ORCPT + 99 others); Mon, 23 Nov 2020 08:28:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:42504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730860AbgKWMbb (ORCPT ); Mon, 23 Nov 2020 07:31:31 -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 041C320857; Mon, 23 Nov 2020 12:31:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606134690; bh=JebXyaG8AOx3e6mcFoy7vDXsbNBvHFjpRgy9hjHiqfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CDWfUG4J9yfpXuJZKH+epAetQ+DNDU2y/gghE1E+FLvNbdtKvApHfCJd7P1HTDsXN Q+nPgoFTh5BXo4bYwpCV1lvTGxxSZy6l1Os4h4fZimoa+vx5dVZyXgFXMjkUxEhLl9 IeAbChI/YaRkqHyeJg3BDN07pgtVJFabbqvDb0X8= 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 4.19 48/91] can: af_can: prevent potential access of uninitialized member in can_rcv() Date: Mon, 23 Nov 2020 13:22:08 +0100 Message-Id: <20201123121811.653964670@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121809.285416732@linuxfoundation.org> References: <20201123121809.285416732@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 04132b0b5d360..1201846dc07e3 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -722,16 +722,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