Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2963502rwd; Mon, 29 May 2023 03:50:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Hk2R0I/Kg/3ExVJh8ekHtBIi/2sRdt2rV2dtnMGNRqKAjoHqSZu9KNM6TrE+RB/6mArgj X-Received: by 2002:a17:90a:b88d:b0:255:f113:48f4 with SMTP id o13-20020a17090ab88d00b00255f11348f4mr9495555pjr.24.1685357429764; Mon, 29 May 2023 03:50:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685357429; cv=none; d=google.com; s=arc-20160816; b=rFHdCGMBv/43JmYuPBbEqhvqaqTnH7zSowM+No6B6LBG0TZif0diaIpa2VXgoVxBi8 tjAnkDk5yIWKh+AjDPtpy1ZX2sgS+PxRkRB2YeKyFwSIXRT8J8Qum+FAYsngNgyi9an7 BfnG7hAJf2/g158e7PHzyIxaAIHeyhYHhOYsq8jQAriw07XxNBgj/QJEN//zAGlPIdMK WipsN2yWbQG6+fdBPmubmh+NKgmOoYjw8IkpmJv8RjiCpP+Yq9Wo8lPG6gfdBiplj9lk E2U5gootjYPwei7RW3kiSYC0BEKthGcHDJWbDid9AS/Git0x4/6tA3AT018YuuRuFSV6 NrPA== 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=okGmckR/m3UDpmLLqwUrNzvqpmjg9PFymksDk9dYoj0=; b=emNsACql6QXvUuz2nyTQ3kDYkfNcuPHTrQm1nbQ/eXmBNBp4h1aI0wWLFQ81I5GJXK tGYD7wdYfO9ysqcV/rGSYrHkQ79YcSSk938WOi5L7kQhati1JWYzJdCB9Pw7zJD+csL1 S5N6fY81xkKflJfmiz035WemUyCrFua9dolwEUGJlm++U51fYheORnW6or+RQpw75/k8 k/X/O2lg0YsDa0IHNgg7igItzuU81ymCmzYKmtM1TnxB4HU5bupBsAOO45I5y7fXlSFI h1l6qfUPYlUYcUCX1wp2u5e9NB526udNs5zqvdyv28yB0Diz0jN9Y5ONIcmc6J1cz1o9 +hjw== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i123-20020a639d81000000b0053eee173732si3872039pgd.161.2023.05.29.03.50.16; Mon, 29 May 2023 03:50:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231984AbjE2KPW (ORCPT + 99 others); Mon, 29 May 2023 06:15:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231816AbjE2KPT (ORCPT ); Mon, 29 May 2023 06:15:19 -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 8212CD9 for ; Mon, 29 May 2023 03:15:14 -0700 (PDT) Received: from moin.white.stw.pengutronix.de ([2a0a:edc0:0:b01:1d::7b] 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 1q3ZuA-0000jf-C7; Mon, 29 May 2023 12:15:10 +0200 Received: from pengutronix.de (unknown [172.20.34.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) 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 EE7461CDDD2; Mon, 29 May 2023 10:15:08 +0000 (UTC) Date: Mon, 29 May 2023 12:15:08 +0200 From: Marc Kleine-Budde To: Oleksij Rempel Cc: Robin van der Gracht , Oliver Hartkopp , David Jander , kernel@pengutronix.de, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] can: j1939: j1939_sk_send_loop_abort(): improved error queue handling in J1939 Socket Message-ID: <20230529-escalate-petticoat-976947c5ff2c-mkl@pengutronix.de> References: <20230526081946.715190-1-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mvongy46xmtqqt6x" Content-Disposition: inline In-Reply-To: <20230526081946.715190-1-o.rempel@pengutronix.de> X-SA-Exim-Connect-IP: 2a0a:edc0:0:b01:1d::7b 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=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --mvongy46xmtqqt6x Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 26.05.2023 10:19:46, Oleksij Rempel wrote: > This patch addresses an issue within the j1939_sk_send_loop_abort() > function in the j1939/socket.c file, specifically in the context of > Transport Protocol (TP) sessions. >=20 > Without this patch, when a TP session is initiated and a Clear To Send > (CTS) frame is received from the remote side requesting one data packet, > the kernel dispatches the first Data Transport (DT) frame and then waits > for the next CTS. If the remote side doesn't respond with another CTS, > the kernel aborts due to a timeout. This leads to the user-space > receiving an EPOLLERR on the socket, and the socket becomes active. >=20 > However, when trying to read the error queue from the socket with > sock.recvmsg(, , socket.MSG_ERRQUEUE), it returns -EAGAIN, > given that the socket is non-blocking. This situation results in an > infinite loop: the user-space repeatedly calls epoll(), epoll() returns > the socket file descriptor with EPOLLERR, but the socket then blocks on > the recv() of ERRQUEUE. >=20 > This patch introduces an additional check for the J1939_SOCK_ERRQUEUE > flag within the j1939_sk_send_loop_abort() function. If the flag is set, > it indicates that the application has subscribed to receive error queue > messages. In such cases, the kernel can communicate the current transfer > state via the error queue. This allows for the function to return early, > preventing the unnecessary setting of the socket into an error state, > and breaking the infinite loop. It is crucial to note that a socket > error is only needed if the application isn't using the error queue, as, > without it, the application wouldn't be aware of transfer issues. >=20 > Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") > Reported-by: David Jander > Tested-by: David Jander > Signed-off-by: Oleksij Rempel Applied to linux-can, added stable on Cc. Thanks, Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung N=C3=BCrnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 | --mvongy46xmtqqt6x Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEDs2BvajyNKlf9TJQvlAcSiqKBOgFAmR0eykACgkQvlAcSiqK BOgQiggAquFQWp8JcNGEW3M8XDLDriPJI++T9TNxvt18R2mvq9dp3avKNDso7B0b PA6A8m3RwS/gb7ibqOJtIOKt8fh0RGcraKEuYgUvEijNGfQ8L1WtjJjIV9o+gAfz aNeXUrdf+Nq+4s3TlZpvdPQfOIuLxuxX6mIeauq2rYmTEJLrAX8Wzqrh8H/l+Qy4 zutQnmixVDiefKLi3Gm8/Sj7J1EtepjVa6E6e5VKdM/JdGEZ6SRzwXAtTviGy8BX yP7z/ced3z0C31lXnyR4oxpCYPSEfbGm1iGqZJz/jQVy+tWKLWRZ9vZCIK1tGbrG bcIGjG9vVvt3fkmjpTHT09ZtqcVoCw== =6eIq -----END PGP SIGNATURE----- --mvongy46xmtqqt6x--