Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2032536iof; Tue, 7 Jun 2022 17:36:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQg1Jgx6Lo5y5RVg6NeyoAnwRCLm5F5GMRBM/9As10ZUjOtEwns/nThasjSJ/PEuB5f77p X-Received: by 2002:a17:902:7282:b0:164:17f6:e36a with SMTP id d2-20020a170902728200b0016417f6e36amr30826429pll.139.1654648580626; Tue, 07 Jun 2022 17:36:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654648580; cv=none; d=google.com; s=arc-20160816; b=vCeo/zIaxNzpNqFcdLZ29YhQZPJSLJRm3KXlh0btrIR4r0RxhLmYW5O2vjqjxSgB9f 9MsiJmXyRfGW/0jzxI5uMbLARGQtxqjxnza4EMzbf2vCOX9CRKidWXHA6cF1O6V9dQyi P39jctCwWqRF5IW/LzNZzydEWt2pcQgDYcDcqj5Dtdr+kg53jqRV1671FlIr+piKjhV9 Y6GGCzcxgdNlAinlVPvDd7rf5YwputeLkc3Ek7THDMv/BJ+KXC/9Ow9X2YT9hlFoqW7O +LAm0Hy0IDPGmn+Vf032cdNVGThR+aDjyyVTBNK9i/BLZ+qmrnqqlelLac3fnAmTODqx mYnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=NDYS9BRUjm3IOMcDKXFKodrgAZWOBS9zWanOZQ0nMbI=; b=jeDLM/e1Avnc3SRYCPFqjY5hoQUKvyfjD45shjf91sM6hU/7axFt/HHVNnp0zTwWCJ 7XYXfn4mKJ7O8IrFDhqCMMgQkRbCT+JAO0cCEobUCza39dCV/FfdaTI7jRuMhoVeZv4E v7zViHvfN6OLtqVFE991hm0CV+kdRh5/YD3xuKRmOwX0G6sVfmh7V44Rf4eh58AITJY0 //5TdwoMnIs/KOQxULcoDdAxnwXwM4VwigZfJG/Y+sWKb0HAeboLubZx/BwhGk4m7yMk aFARAGeFBSFyUfn/zbOH1Yq3uSpmb9dKvoZYvpGq8YOvh2ow37AasSDLsyKKlJNprOTx j5sg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 5-20020a630d45000000b003fb238f8ea1si25062741pgn.609.2022.06.07.17.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 17:36:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 37DD91AD5A3; Tue, 7 Jun 2022 17:25:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242017AbiFGLCJ (ORCPT + 99 others); Tue, 7 Jun 2022 07:02:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242469AbiFGLAJ (ORCPT ); Tue, 7 Jun 2022 07:00:09 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5811654028 for ; Tue, 7 Jun 2022 03:56:50 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nyWt5-00072I-Dw; Tue, 07 Jun 2022 12:56:39 +0200 Received: from pengutronix.de (unknown [IPv6:2a01:4f8:1c1c:29e9:22:41ff:fe00:1400]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 99EDB8DBC5; Tue, 7 Jun 2022 10:56:37 +0000 (UTC) Date: Tue, 7 Jun 2022 12:56:37 +0200 From: Marc Kleine-Budde To: Dario Binacchi Cc: linux-kernel@vger.kernel.org, Amarula patchwork , michael@amarulasolutions.com, "David S. Miller" , Eric Dumazet , Greg Kroah-Hartman , Jakub Kicinski , Jiri Slaby , Paolo Abeni , Sebastian Andrzej Siewior , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [RFC PATCH 12/13] can: slcan: extend the protocol with error info Message-ID: <20220607105637.4vnqtv4vbnczva73@pengutronix.de> References: <20220607094752.1029295-1-dario.binacchi@amarulasolutions.com> <20220607094752.1029295-13-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ssxfwmq3jxhh5und" Content-Disposition: inline In-Reply-To: <20220607094752.1029295-13-dario.binacchi@amarulasolutions.com> X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ssxfwmq3jxhh5und Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 07.06.2022 11:47:51, Dario Binacchi wrote: > It extends the protocol to receive the adapter CAN communication errors > and forward them to the netdev upper levels. >=20 > Signed-off-by: Dario Binacchi > --- >=20 > drivers/net/can/slcan/slcan-core.c | 104 ++++++++++++++++++++++++++++- > 1 file changed, 103 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/s= lcan-core.c > index b813a59534a3..02e7c14de45c 100644 > --- a/drivers/net/can/slcan/slcan-core.c > +++ b/drivers/net/can/slcan/slcan-core.c > @@ -182,8 +182,92 @@ int slcan_enable_err_rst_on_open(struct net_device *= ndev, bool on) > * STANDARD SLCAN DECAPSULATION * > **********************************************************************= **/ > =20 > +static void slc_bump_err(struct slcan *sl) > +{ > + struct net_device *dev =3D sl->dev; > + struct sk_buff *skb; > + struct can_frame *cf; > + char *cmd =3D sl->rbuff; > + bool rx_errors =3D false, tx_errors =3D false; > + int i, len; > + > + if (*cmd !=3D 'e') > + return; > + > + cmd +=3D SLC_CMD_LEN; > + /* get len from sanitized ASCII value */ What happens is a malicious device sends a wrong len value, that's longer than the RX'ed data? > + len =3D *cmd++; > + if (len >=3D '0' && len < '9') > + len -=3D '0'; > + else > + return; > + > + skb =3D alloc_can_err_skb(dev, &cf); Please continue error handling, even if no skb can be allocated. > + if (unlikely(!skb)) > + return; > + > + cf->can_id |=3D CAN_ERR_PROT | CAN_ERR_BUSERROR; > + for (i =3D 0; i < len; i++, cmd++) { > + switch (*cmd) { > + case 'a': > + netdev_dbg(dev, "ACK error\n"); > + cf->can_id |=3D CAN_ERR_ACK; > + cf->data[3] =3D CAN_ERR_PROT_LOC_ACK; > + tx_errors =3D true; > + break; > + case 'b': > + netdev_dbg(dev, "Bit0 error\n"); > + cf->data[2] |=3D CAN_ERR_PROT_BIT0; > + tx_errors =3D true; > + break; > + case 'B': > + netdev_dbg(dev, "Bit1 error\n"); > + cf->data[2] |=3D CAN_ERR_PROT_BIT1; > + tx_errors =3D true; > + break; > + case 'c': > + netdev_dbg(dev, "CRC error\n"); > + cf->data[2] |=3D CAN_ERR_PROT_BIT; > + cf->data[3] =3D CAN_ERR_PROT_LOC_CRC_SEQ; > + rx_errors =3D true; > + break; > + case 'f': > + netdev_dbg(dev, "Form Error\n"); > + cf->data[2] |=3D CAN_ERR_PROT_FORM; > + rx_errors =3D true; > + break; > + case 'o': > + netdev_dbg(dev, "Rx overrun error\n"); > + cf->can_id |=3D CAN_ERR_CRTL; > + cf->data[1] =3D CAN_ERR_CRTL_RX_OVERFLOW; > + dev->stats.rx_over_errors++; > + dev->stats.rx_errors++; > + break; > + case 'O': > + netdev_dbg(dev, "Tx overrun error\n"); > + cf->can_id |=3D CAN_ERR_CRTL; > + cf->data[1] =3D CAN_ERR_CRTL_TX_OVERFLOW; > + dev->stats.tx_errors++; > + break; > + case 's': > + netdev_dbg(dev, "Stuff error\n"); > + cf->data[2] |=3D CAN_ERR_PROT_STUFF; > + rx_errors =3D true; > + break; > + } > + } > + > + if (rx_errors) > + dev->stats.rx_errors++; > + > + if (tx_errors) > + dev->stats.tx_errors++; > + > + netif_rx(skb); > +} > + Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | --ssxfwmq3jxhh5und Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEBsvAIBsPu6mG7thcrX5LkNig010FAmKfLuIACgkQrX5LkNig 013hsQgAghzB45G5T/d9COtfEWCcub/p6KFBW8Pt5SQfvSlUfEh7yuScPV/B8tum Uek/ORPZAes9xoBuNo3UMPsHPCZvaOvbYfY1oNJJuw+rGDYL4v40UismcGr9M9nr mqEGUj03KjJDPlf1RPNxDsuH2irS05TOKjpXq90ZaN5zB5f6SZlNvfFDHkGMn+Zm 1z0ZZCpWNO9+VS/ZfoUJoY6OgXQxMm3Pw3pdwJqGMelFaD9BAw1f6RK2ceRcvGLi tY06Tf3mzhzFLAlY856+yPKw8eh7bP2PBLDfa+CVCraCcicUNzEz0a7h8Nf0TaWx ZaZdTg/teBjBCYq/cnW2z1NOqD86aA== =emqs -----END PGP SIGNATURE----- --ssxfwmq3jxhh5und--