Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1237672pxu; Mon, 23 Nov 2020 15:35:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwPT2jl9xhPMj/WNJ6nfSHfI61q7Ml78VdL1FbyyNMs/t+dGlBO6P6QqR0uZA/Vpmkcp0zH X-Received: by 2002:a17:906:c826:: with SMTP id dd6mr1807433ejb.191.1606174531491; Mon, 23 Nov 2020 15:35:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606174531; cv=none; d=google.com; s=arc-20160816; b=dPNmydh3DZbkWTgwELZX0aPRVzsjgAnlcqPOD4JERVRH86HuKXrxSi0vFASMzAX7lW 6iVml4sYnIejo77WtxDnPcAe5AhzGK1P8xG5oETNdlhwhO1YoLhFTWzt1qqJJewahVF9 kUdswPL7VguQtak1wq7lb0I4dbwpEHf3bQ1fl3YQqptBaXirf2uM9/PRMsPIN2Lwq2xq ODoQ1fW48Yl40AiQ3C9JL54lzlT97is4JerMxeZ7GH/ODPmvaH0aoh2yi85riQo6l8Ts GdMhtXMfv91zJu+JusdUihPCkAEkfxRA88sXMmRubQd3RXYBJ8K+4UnhkUZyXDNjTYHh m1tw== 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=8g7Viphb1fNB1hk+25q1pRBqqpHXkY6F//YJ0kdtijo=; b=ubdeLRUPWr+HplYgG3E+TfQHVJJScB+vLsHwLLMCVdodxiFMj0BFGhNH14m49IPkQX m/XB0OqbB4FR83eM6K/NV2ssDGj9POWN8/vf/o/EoegYu3QvgUKYSNfnVr9UoJq6X2N7 At1ljDqBxpQG2+N9v4cuUhVlVlMcPW1jsTBah/x1trrfJdOY1g0/PDtwf4GY18eTix+J wUfJxST8Hcl0FCHe+L+EMjhgV8wmtwffMP5v9Z8a5+UVfNIwLY7JVNoNeWImcphn4sG9 h3dbm+IUQyqxX6CGiH0FXkdgYTRHJlV64Hfr0PrRCwwU5eL6fBHNt2cKYSpca4lKMBYk RReg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2d69OnQF; 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 bx23si7312487ejb.257.2020.11.23.15.35.09; Mon, 23 Nov 2020 15:35:31 -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=2d69OnQF; 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 S1730991AbgKWMcA (ORCPT + 99 others); Mon, 23 Nov 2020 07:32:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:42666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730194AbgKWMbe (ORCPT ); Mon, 23 Nov 2020 07:31:34 -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 D5A2721D7E; Mon, 23 Nov 2020 12:31:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606134693; bh=tfAf0+7EwoYlWdov5kICKScbg39EvHobteHX7ndjaZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2d69OnQFHU0t7mg8A8mlpkNiIPlkf8xU2+QL7JLkCoohjKZTuUy2VlFymQGba3tII 28dtq/anG6r4977YnE+rsXU6ipsGqP2Jt/IAefUoGB1QBbneGlzKo9dKz9ZznEnMat WbSmnBaB4FGON8VjRsy6KvmklMPIYQD3rw4j35dQ= 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 49/91] can: af_can: prevent potential access of uninitialized member in canfd_rcv() Date: Mon, 23 Nov 2020 13:22:09 +0100 Message-Id: <20201123121811.703579099@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 9aa9379d8f868e91719333a7f063ccccc0579acc ] In canfd_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 > CANFD_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: d4689846881d ("can: af_can: canfd_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-3-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 1201846dc07e3..b3edb80921248 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -748,16 +748,25 @@ static int canfd_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 != CANFD_MTU || - cfd->len > CANFD_MAX_DLEN)) { - pr_warn_once("PF_CAN: dropped non conform CAN FD skbuf: dev type %d, len %d, datalen %d\n", + if (unlikely(dev->type != ARPHRD_CAN || skb->len != CANFD_MTU)) { + pr_warn_once("PF_CAN: dropped non conform CAN FD 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 > CANFD_MAX_DLEN)) { + pr_warn_once("PF_CAN: dropped non conform CAN FD 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; } /* -- 2.27.0