From patchwork Thu Oct 21 14:04:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Changzhong X-Patchwork-Id: 12575163 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1162AC4332F for ; Thu, 21 Oct 2021 13:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2CFA61130 for ; Thu, 21 Oct 2021 13:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbhJUN4g (ORCPT ); Thu, 21 Oct 2021 09:56:36 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:25308 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbhJUN4c (ORCPT ); Thu, 21 Oct 2021 09:56:32 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HZpkT2yb6zbfXP; Thu, 21 Oct 2021 21:49:37 +0800 (CST) Received: from dggpeml500006.china.huawei.com (7.185.36.76) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 21 Oct 2021 21:54:11 +0800 Received: from compute.localdomain (10.175.112.70) by dggpeml500006.china.huawei.com (7.185.36.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 21 Oct 2021 21:54:11 +0800 From: Zhang Changzhong To: Robin van der Gracht , Oleksij Rempel , , Oliver Hartkopp , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski CC: Zhang Changzhong , , , Subject: [PATCH net 1/3] can: j1939: j1939_tp_cmd_recv(): ignore abort message in the BAM transport Date: Thu, 21 Oct 2021 22:04:15 +0800 Message-ID: <1634825057-47915-2-git-send-email-zhangchangzhong@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1634825057-47915-1-git-send-email-zhangchangzhong@huawei.com> References: <1634825057-47915-1-git-send-email-zhangchangzhong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500006.china.huawei.com (7.185.36.76) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch prevents BAM transport from being closed by receiving abort message, as specified in SAE-J1939-82 2015 (A.3.3 Row 4). Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Signed-off-by: Zhang Changzhong Acked-by: Oleksij Rempel --- net/can/j1939/transport.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index bb5c4b8..2efa606 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -2081,6 +2081,9 @@ static void j1939_tp_cmd_recv(struct j1939_priv *priv, struct sk_buff *skb) break; case J1939_ETP_CMD_ABORT: /* && J1939_TP_CMD_ABORT */ + if (j1939_cb_is_broadcast(skcb)) + return; + if (j1939_tp_im_transmitter(skcb)) j1939_xtp_rx_abort(priv, skb, true); From patchwork Thu Oct 21 14:04:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Changzhong X-Patchwork-Id: 12575159 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53683C4332F for ; Thu, 21 Oct 2021 13:54:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B26C60E05 for ; Thu, 21 Oct 2021 13:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231520AbhJUN4c (ORCPT ); Thu, 21 Oct 2021 09:56:32 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:29923 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231331AbhJUN4c (ORCPT ); Thu, 21 Oct 2021 09:56:32 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HZpkV4CwwzbnFr; Thu, 21 Oct 2021 21:49:38 +0800 (CST) Received: from dggpeml500006.china.huawei.com (7.185.36.76) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 21 Oct 2021 21:54:12 +0800 Received: from compute.localdomain (10.175.112.70) by dggpeml500006.china.huawei.com (7.185.36.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 21 Oct 2021 21:54:12 +0800 From: Zhang Changzhong To: Robin van der Gracht , Oleksij Rempel , , Oliver Hartkopp , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski CC: Zhang Changzhong , , , Subject: [PATCH net 2/3] can: j1939: j1939_can_recv(): ignore messages with invalid source address Date: Thu, 21 Oct 2021 22:04:16 +0800 Message-ID: <1634825057-47915-3-git-send-email-zhangchangzhong@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1634825057-47915-1-git-send-email-zhangchangzhong@huawei.com> References: <1634825057-47915-1-git-send-email-zhangchangzhong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500006.china.huawei.com (7.185.36.76) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org According to SAE-J1939-82 2015 (A.3.6 Row 2), a receiver should never send TP.CM_CTS to the global address, so we can add a check in j1939_can_recv() to drop messages with invalid source address. Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Signed-off-by: Zhang Changzhong --- net/can/j1939/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/can/j1939/main.c b/net/can/j1939/main.c index 08c8606..4f1e4bb 100644 --- a/net/can/j1939/main.c +++ b/net/can/j1939/main.c @@ -75,6 +75,10 @@ static void j1939_can_recv(struct sk_buff *iskb, void *data) skcb->addr.pgn = (cf->can_id >> 8) & J1939_PGN_MAX; /* set default message type */ skcb->addr.type = J1939_TP; + if (!j1939_address_is_valid(skcb->addr.sa)) + /* ignore messages whose sa is broadcast address */ + goto done; + if (j1939_pgn_is_pdu1(skcb->addr.pgn)) { /* Type 1: with destination address */ skcb->addr.da = skcb->addr.pgn; From patchwork Thu Oct 21 14:04:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Changzhong X-Patchwork-Id: 12575161 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59404C43217 for ; Thu, 21 Oct 2021 13:54:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E11B6112D for ; Thu, 21 Oct 2021 13:54:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231550AbhJUN4d (ORCPT ); Thu, 21 Oct 2021 09:56:33 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:29924 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbhJUN4c (ORCPT ); Thu, 21 Oct 2021 09:56:32 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HZpkW3tcdzbnJm; Thu, 21 Oct 2021 21:49:39 +0800 (CST) Received: from dggpeml500006.china.huawei.com (7.185.36.76) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 21 Oct 2021 21:54:13 +0800 Received: from compute.localdomain (10.175.112.70) by dggpeml500006.china.huawei.com (7.185.36.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 21 Oct 2021 21:54:13 +0800 From: Zhang Changzhong To: Robin van der Gracht , Oleksij Rempel , , Oliver Hartkopp , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski CC: Zhang Changzhong , , , Subject: [PATCH net 3/3] can: j1939: j1939_tp_cmd_recv(): check the dst address of TP.CM_BAM Date: Thu, 21 Oct 2021 22:04:17 +0800 Message-ID: <1634825057-47915-4-git-send-email-zhangchangzhong@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1634825057-47915-1-git-send-email-zhangchangzhong@huawei.com> References: <1634825057-47915-1-git-send-email-zhangchangzhong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500006.china.huawei.com (7.185.36.76) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The TP.CM_BAM message must be sent to the global address [1], so add a check to drop TP.CM_BAM sent to a non-global address. Without this patch, the receiver will treat the following packets as normal RTS/CTS tranport: 18EC0102#20090002FF002301 18EB0102#0100000000000000 18EB0102#020000FFFFFFFFFF [1] SAE-J1939-82 2015 A.3.3 Row 1. Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Signed-off-by: Zhang Changzhong --- net/can/j1939/transport.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index 2efa606..93ec0c3 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -2019,6 +2019,8 @@ static void j1939_tp_cmd_recv(struct j1939_priv *priv, struct sk_buff *skb) extd = J1939_ETP; fallthrough; case J1939_TP_CMD_BAM: + if (!j1939_cb_is_broadcast(skcb)) + return; fallthrough; case J1939_TP_CMD_RTS: if (skcb->addr.type != extd)