Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp689539pxb; Mon, 25 Oct 2021 16:42:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0fuEAvEjw0t6fazjn6AYc1hq6b5eXNSprCsOUu6WHpM4BLP2FnXWLX8FOyADxDhuYq8on X-Received: by 2002:a17:907:3f8a:: with SMTP id hr10mr9501091ejc.373.1635205371247; Mon, 25 Oct 2021 16:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635205371; cv=none; d=google.com; s=arc-20160816; b=AsE+jsd4BO6+aZ6Rexa1/Vp26Irc8+5ikonWI5XGpbXST/Q0NjrNwAZJRq8asKBCHi Mjs8HPP1YAW/tmG2yZ4YIxBNQV2Eg7gKccG2XN14e5duDAAWpKWOSSFhNCioffVzW39C KUkonN827PpKN6CD099Q1U4pgMjAXyj7ZR9ixRnikxGPnVzz1RpKtRDRzPJdIhS/FHN1 +UyrHyd4XxPTPa3BXpzn6LCn6/GpbGTLDtYXb7yKcMvSplmuJG9DnbYpXa77UDA1/09G v+lmrv9Ra2WUcHWrb5yKL8ZsQTPK3YXMliDRZSdgoEcvfVgodYHVq0uuYWT6k99R7u+W pGPw== 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=kxFUFBSKfhS1ZJoYIEYnXKCeIRBjqcWpuP4iUkkpLAw=; b=nbzSRonkfgPsrt0gOb1rjP/tcd9Np3UMXvX44HbdUdHhLUDKiJaeGsWldkuQ1cXfQh p3kla37ixUX49bAdWN3eJHsCadjOAsqYpF0U8XrmQK+lpZsiO00L0KCRBpaDLlUNfuW9 h0eZ6BNH26Gg5IpXtwHc+owD3MXQjWbtb6Lr5sm3A89g2BPUtjpyZ0qA2ox7VUjQTV3m v5//WN27MPRtO0lUmL40z91lMFQBpOe6bgIVSnBQbqDPhU95aQUgJ0mRD3RfM+4hJLsB b/F9JXc5AvMcKJ9XOZxnTS30wJgDWU6j8/2FbE6yWsTUi1XCqDtwEe0O7i1JSo70yqb8 A5mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=15hhqTc7; 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 p4si20417533eju.502.2021.10.25.16.42.27; Mon, 25 Oct 2021 16:42:51 -0700 (PDT) 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=15hhqTc7; 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 S236277AbhJYThG (ORCPT + 99 others); Mon, 25 Oct 2021 15:37:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:49322 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235369AbhJYT3o (ORCPT ); Mon, 25 Oct 2021 15:29:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D78C6610C7; Mon, 25 Oct 2021 19:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635190008; bh=TD6/T9X43wYxT6EJ6NjhoPf92aJMxzpa2w4AK3IGcK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=15hhqTc7+dTGrRKYpbBYWOYcKJeXj4MOSNKyL7Lw/WAR6+XHJx8DHQFLHjPbpN47Y WSARUIfMaVRsvZs7E8G8N+7Pi48KPwuhEpsWTVHTOFdr7LDOqmfwYNbKubuI60L6pa UCFvBsBxYmwMYWxdby0PR6eSUeG9+8GkXi32qop0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Changzhong , Oleksij Rempel , Marc Kleine-Budde Subject: [PATCH 5.4 25/58] can: j1939: j1939_xtp_rx_rts_session_new(): abort TP less than 9 bytes Date: Mon, 25 Oct 2021 21:14:42 +0200 Message-Id: <20211025190941.650975292@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025190937.555108060@linuxfoundation.org> References: <20211025190937.555108060@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: Zhang Changzhong commit a4fbe70c5cb746441d56b28cf88161d9e0e25378 upstream. The receiver should abort TP if 'total message size' in TP.CM_RTS and TP.CM_BAM is less than 9 or greater than 1785 [1], but currently the j1939 stack only checks the upper bound and the receiver will accept the following broadcast message: vcan1 18ECFF00 [8] 20 08 00 02 FF 00 23 01 vcan1 18EBFF00 [8] 01 00 00 00 00 00 00 00 vcan1 18EBFF00 [8] 02 00 FF FF FF FF FF FF This patch adds check for the lower bound and abort illegal TP. [1] SAE-J1939-82 A.3.4 Row 2 and A.3.6 Row 6. Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Link: https://lore.kernel.org/all/1634203601-3460-1-git-send-email-zhangchangzhong@huawei.com Cc: stable@vger.kernel.org Signed-off-by: Zhang Changzhong Acked-by: Oleksij Rempel Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- net/can/j1939/j1939-priv.h | 1 + net/can/j1939/transport.c | 2 ++ 2 files changed, 3 insertions(+) --- a/net/can/j1939/j1939-priv.h +++ b/net/can/j1939/j1939-priv.h @@ -326,6 +326,7 @@ int j1939_session_activate(struct j1939_ void j1939_tp_schedule_txtimer(struct j1939_session *session, int msec); void j1939_session_timers_cancel(struct j1939_session *session); +#define J1939_MIN_TP_PACKET_SIZE 9 #define J1939_MAX_TP_PACKET_SIZE (7 * 0xff) #define J1939_MAX_ETP_PACKET_SIZE (7 * 0x00ffffff) --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -1596,6 +1596,8 @@ j1939_session *j1939_xtp_rx_rts_session_ abort = J1939_XTP_ABORT_FAULT; else if (len > priv->tp_max_packet_size) abort = J1939_XTP_ABORT_RESOURCE; + else if (len < J1939_MIN_TP_PACKET_SIZE) + abort = J1939_XTP_ABORT_FAULT; } if (abort != J1939_XTP_NO_ABORT) {