From patchwork Fri Nov 17 12:49:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 166150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp501433vqn; Fri, 17 Nov 2023 04:50:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGMHyYumpMD3XMkfz6pO6gAWFf/o7RsoZnAQF4gR4w57PoVQMA/WFaGuKKNWUUkoRjl1Y0 X-Received: by 2002:a05:6a20:548c:b0:188:1df7:9afe with SMTP id i12-20020a056a20548c00b001881df79afemr1505166pzk.30.1700225429567; Fri, 17 Nov 2023 04:50:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700225429; cv=none; d=google.com; s=arc-20160816; b=m+OEVhQrSVDQgZWcep4gHjlRlm7Dx5nu21sMSi6x5hqX/bAp88qXp1S0zNnILTzzb5 cfAUo7pA9Ym6ZfE5c65vK6PhQhFOruN7cdoKVMHZvldaVLsuNbkmrf2tE1UmBMS/bodK zZK2GT1WtYCVzHdFfsoZt9MpIv5MKe/Kqxc9O7hsljjT6ccKuZWMowOY6ldtuxJyZevF QPzRL8KmBzd1Ar2CL8uitz6+srdwJ/TH0LeVMScocerIeJeKGEIQuzmZ4ezeRPK0Gcz3 c/R1AK8RH/fi1oaN6bAi4bdhrQysklLCnKqWT6S5pgcn22uivi7i5y6V5QRe8LjqKnAM Qu8A== 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 :message-id:date:subject:cc:to:from; bh=e2Xe3RP1wjiWbfip+HrhEGmyTF6GTyCknCE6Q+Mjaqg=; fh=qDL05+zlv15ge3TTk1pNBdi2pI5mhoXajX+4qnLUpVY=; b=0FmqJ+l+W2ibgmSNcvrKxes1dntGnKGOodWNT+vsqiJYbaSkEr2l256xG8m/SEQqOt xsozdMMgRlAJ0+BnmvZWckxHje18q5VF7U7a8UdJ3UCoamZE52iZymxbmG5RSdYmu8m8 ZFaNJ/aeoRdSLyOBcg6iJ9Yl+Y0kOFv+X1ke2S2jDhjgCn9NHPVuDVAGIGETjUka0vJw Zdyr4IMk6wyfXzkeHwCy9N1P98ea7S/XocHa+zUt+1lYfW/aOm0ZoFb+yRCeZ7dR76PW u0pK7yxks3stWgdegYgtesvhfIowOxTNxU6CyDPMLmbaW0DsW5QkHXN1vKViGvwqPCgk xM4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q69-20020a17090a17cb00b00274d6373fe1si4152341pja.120.2023.11.17.04.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 04:50:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5EAC981ECCEF; Fri, 17 Nov 2023 04:50:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345984AbjKQMuN (ORCPT + 30 others); Fri, 17 Nov 2023 07:50:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbjKQMuL (ORCPT ); Fri, 17 Nov 2023 07:50:11 -0500 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F57D55 for ; Fri, 17 Nov 2023 04:50:08 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r3yIL-0005eC-Co; Fri, 17 Nov 2023 13:50:01 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r3yIK-009gMy-L2; Fri, 17 Nov 2023 13:50:00 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1r3yIK-00423C-1v; Fri, 17 Nov 2023 13:50:00 +0100 From: Oleksij Rempel To: Robin van der Gracht , Oliver Hartkopp , Marc Kleine-Budde Cc: Oleksij Rempel , syzbot+daa36413a5cedf799ae4@syzkaller.appspotmail.com, stable@vger.kernel.org, kernel@pengutronix.de, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] net: can: j1939: enhanced error handling for tightly received RTS messages in xtp_rx_rts_session_new Date: Fri, 17 Nov 2023 13:49:59 +0100 Message-Id: <20231117124959.961171-1-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 17 Nov 2023 04:50:27 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782815579986134752 X-GMAIL-MSGID: 1782815579986134752 This patch enhances error handling in scenarios with RTS (Request to Send) messages arriving closely. It replaces the less informative WARN_ON_ONCE backtraces with a new error handling method. This provides clearer error messages and allows for the early termination of problematic sessions. Previously, sessions were only released at the end of j1939_xtp_rx_rts(). Potentially this could be reproduced with something like: testj1939 -r vcan0:0x80 & while true; do # send first RTS cansend vcan0 18EC8090#1014000303002301; # send second RTS cansend vcan0 18EC8090#1014000303002301; # send abort cansend vcan0 18EC8090#ff00000000002301; done Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Reported-by: syzbot+daa36413a5cedf799ae4@syzkaller.appspotmail.com Cc: stable@vger.kernel.org Signed-off-by: Oleksij Rempel --- net/can/j1939/transport.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c index fe3df23a2595..c6569f98d251 100644 --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -1593,8 +1593,8 @@ j1939_session *j1939_xtp_rx_rts_session_new(struct j1939_priv *priv, struct j1939_sk_buff_cb skcb = *j1939_skb_to_cb(skb); struct j1939_session *session; const u8 *dat; + int len, ret; pgn_t pgn; - int len; netdev_dbg(priv->ndev, "%s\n", __func__); @@ -1653,7 +1653,22 @@ j1939_session *j1939_xtp_rx_rts_session_new(struct j1939_priv *priv, session->tskey = priv->rx_tskey++; j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_RTS); - WARN_ON_ONCE(j1939_session_activate(session)); + ret = j1939_session_activate(session); + if (ret) { + /* Entering this scope indicates an issue with the J1939 bus. + * Possible scenarios include: + * - A time lapse occurred, and a new session was initiated + * due to another packet being sent correctly. This could + * have been caused by too long interrupt, debugger, or being + * out-scheduled by another task. + * - The bus is receiving numerous erroneous packets, either + * from a malfunctioning device or during a test scenario. + */ + netdev_alert(priv->ndev, "%s: 0x%p: concurrent session with same addr (%02x %02x) is already active.\n", + __func__, session, skcb.addr.sa, skcb.addr.da); + j1939_session_put(session); + return NULL; + } return session; }