Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4565789imu; Tue, 29 Jan 2019 03:55:45 -0800 (PST) X-Google-Smtp-Source: ALg8bN6jbQV+BGIwFrowcy5KxqPrKEUYlVTUVPTXj4NwLu/6sPsXB8MeS6E+KUtGgP+InuQBjPit X-Received: by 2002:a62:444b:: with SMTP id r72mr26266284pfa.184.1548762945624; Tue, 29 Jan 2019 03:55:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548762945; cv=none; d=google.com; s=arc-20160816; b=nkh061X68Mgj/Kkh7yieLXsIclJ7YxYn5+4pItNhviZ0HhOTBjkh7xoApKUQup3gG+ K24W/7vEQS/5wHRpKNCKsavqbzchKJeoQxNKKxf3FTh1eaWY108Y2VQZKsY1+W/Mw1l/ amhvSOAfijjUqbW3SCuCG8cLvJNbTesRhLSLA5N1N/o+fJ3t1Em7FWamx5AV9fd9F87v 8WrafwCWAXT4ks+V9SUfzQChfSyLwBKzgAeG46UDeLaLxoKA4XgtBjy5dmVul/V5vWhO 7O4OqWsrtueioFe/8s2YZTzmLfnXZmJOwAn/OoNWxlu4cfOeZSU8W+X+4IsU6Y+uq/VW XWHw== 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=S4CJjXJ7G8z8+EqI8jBJvMOxW1VGV/LBibVHfFs7VpA=; b=MDVS1d9i67QjL2KZVexOkBcLfBIs4M06QeMCetoAaoG/tuV0eGB1jjAKzbE8lvpgN+ 8AJ6SVehminU2SkxEj05FtDx4zZIUrXfhOceeyVCjFy02M/mWAiPA5aICmQCs/r52hCb Ku2K5XJM79IPWkfgJmcZN5H7jSH1eXeiBg0whLKmhldg6+J9qpprPfjaRKMlV5rQuAIZ THXmEPPEbv8L4ztN+5ewOl9kuv3DxATwMDY4mUKjT/w9RzLoC1XsFmFrAmprwBq0wPZS 4Nh7SC08crBN0eGvIHd+3ewHSNw4M18We3Y6fdVVfwpmDl3uydhQgNCJE2W5LN1dkcUm xAoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mOimAeya; 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 q5si31978672pgg.204.2019.01.29.03.55.30; Tue, 29 Jan 2019 03:55:45 -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=mOimAeya; 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 S1731988AbfA2Lv6 (ORCPT + 99 others); Tue, 29 Jan 2019 06:51:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:43530 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728628AbfA2Lvy (ORCPT ); Tue, 29 Jan 2019 06:51:54 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 B15042083B; Tue, 29 Jan 2019 11:51:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548762713; bh=JR5SBGDdoYg27Z3dHFypnCVYlYHXnefEUzIv5LbmiTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mOimAeyath1Kuro5OOiFtDfZT2TkslClRhpzIpu/dmjDuZIfOX5QsoEKhbLVr/CPD D4+rAbXammZMv61dgzcA/LxFU08RcAQ+coROrozwBudup+xBc1U9IfWPM3bP57OsQZ 99x1nH3NDcjUvWu0c28/b8TLuqXZ57oJDMWAZuCU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Manfred Schlaegl , Marc Kleine-Budde Subject: [PATCH 4.9 33/44] can: dev: __can_get_echo_skb(): fix bogous check for non-existing skb by removing it Date: Tue, 29 Jan 2019 12:36:28 +0100 Message-Id: <20190129113142.592477940@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129113139.826927690@linuxfoundation.org> References: <20190129113139.826927690@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Manfred Schlaegl commit 7b12c8189a3dc50638e7d53714c88007268d47ef upstream. This patch revert commit 7da11ba5c506 ("can: dev: __can_get_echo_skb(): print error message, if trying to echo non existing skb") After introduction of this change we encountered following new error message on various i.MX plattforms (flexcan): | flexcan 53fc8000.can can0: __can_get_echo_skb: BUG! Trying to echo non | existing skb: can_priv::echo_skb[0] The introduction of the message was a mistake because priv->echo_skb[idx] = NULL is a perfectly valid in following case: If CAN_RAW_LOOPBACK is disabled (setsockopt) in applications, the pkt_type of the tx skb's given to can_put_echo_skb is set to PACKET_LOOPBACK. In this case can_put_echo_skb will not set priv->echo_skb[idx]. It is therefore kept NULL. As additional argument for revert: The order of check and usage of idx was changed. idx is used to access an array element before checking it's boundaries. Signed-off-by: Manfred Schlaegl Fixes: 7da11ba5c506 ("can: dev: __can_get_echo_skb(): print error message, if trying to echo non existing skb") Cc: linux-stable Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/dev.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) --- a/drivers/net/can/dev.c +++ b/drivers/net/can/dev.c @@ -456,8 +456,6 @@ EXPORT_SYMBOL_GPL(can_put_echo_skb); struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr) { struct can_priv *priv = netdev_priv(dev); - struct sk_buff *skb = priv->echo_skb[idx]; - struct canfd_frame *cf; if (idx >= priv->echo_skb_max) { netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n", @@ -465,20 +463,21 @@ struct sk_buff *__can_get_echo_skb(struc return NULL; } - if (!skb) { - netdev_err(dev, "%s: BUG! Trying to echo non existing skb: can_priv::echo_skb[%u]\n", - __func__, idx); - return NULL; - } + if (priv->echo_skb[idx]) { + /* Using "struct canfd_frame::len" for the frame + * length is supported on both CAN and CANFD frames. + */ + struct sk_buff *skb = priv->echo_skb[idx]; + struct canfd_frame *cf = (struct canfd_frame *)skb->data; + u8 len = cf->len; - /* Using "struct canfd_frame::len" for the frame - * length is supported on both CAN and CANFD frames. - */ - cf = (struct canfd_frame *)skb->data; - *len_ptr = cf->len; - priv->echo_skb[idx] = NULL; + *len_ptr = len; + priv->echo_skb[idx] = NULL; + + return skb; + } - return skb; + return NULL; } /*