lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250512012748.79749-11-damien.riegel@silabs.com>
Date: Sun, 11 May 2025 21:27:43 -0400
From: Damien Riégel <damien.riegel@...abs.com>
To: Andrew Lunn <andrew+netdev@...n.ch>,
        "David S . Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>, Rob Herring <robh@...nel.org>,
        Krzysztof Kozlowski <krzk+dt@...nel.org>,
        Conor Dooley <conor+dt@...nel.org>,
        Silicon Labs Kernel Team <linux-devel@...abs.com>,
        netdev@...r.kernel.org, devicetree@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [RFC net-next 10/15] net: cpc: make disconnect blocking

In order to make life easier for consumer drivers, make
cpc_endpoint_disconnect() blocking. Once the call returns, it guarantees
that endpoint's rx callback won't be called anymore, making driver's
teardown simpler to implement.

Signed-off-by: Damien Riégel <damien.riegel@...abs.com>
---
 drivers/net/cpc/cpc.h       |  1 +
 drivers/net/cpc/endpoint.c  | 19 ++++++++++++++++++-
 drivers/net/cpc/interface.c |  4 ++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/net/cpc/cpc.h b/drivers/net/cpc/cpc.h
index 34ee519d907..8a761856deb 100644
--- a/drivers/net/cpc/cpc.h
+++ b/drivers/net/cpc/cpc.h
@@ -21,6 +21,7 @@ extern const struct bus_type cpc_bus;
 /* CPC endpoint flags */
 enum {
 	CPC_ENDPOINT_UP,	/* Connection is established with remote counterpart. */
+	CPC_ENDPOINT_RECEIVING,	/* Interface RX work is processing a frame for this endpoint. */
 };
 
 /**
diff --git a/drivers/net/cpc/endpoint.c b/drivers/net/cpc/endpoint.c
index 7e2f623fb8e..f953e4cb7ab 100644
--- a/drivers/net/cpc/endpoint.c
+++ b/drivers/net/cpc/endpoint.c
@@ -260,8 +260,25 @@ void __cpc_endpoint_disconnect(struct cpc_endpoint *ep, bool send_rst)
 
 	cpc_interface_remove_rx_endpoint(ep);
 
-	if (send_rst)
+	if (send_rst) {
+		/*
+		 * It makes sense to wait on the RECEIVING bit only when send_rst is true as this
+		 * means the operation was initiated by the user and can happen concurrently with
+		 * the RX work function. If a RST is received from the remote and
+		 * __cpc_endpoint_disconnect from the RX work function, then it's safe to assume
+		 * that this frame won't trigger a call to ep->ops->rx function.
+		 */
+		int err;
+
+		err = wait_on_bit_timeout(&ep->flags,
+					  CPC_ENDPOINT_RECEIVING,
+					  TASK_INTERRUPTIBLE,
+					  msecs_to_jiffies(1000));
+		if (!err)
+			dev_warn(&ep->dev, "Timeout when disconnecting.\n");
+
 		cpc_protocol_send_rst(ep->intf, ep->id);
+	}
 }
 
 /**
diff --git a/drivers/net/cpc/interface.c b/drivers/net/cpc/interface.c
index 30e7976355c..13b52cdc357 100644
--- a/drivers/net/cpc/interface.c
+++ b/drivers/net/cpc/interface.c
@@ -36,6 +36,8 @@ static void cpc_interface_rx_work(struct work_struct *work)
 			continue;
 		}
 
+		set_bit(CPC_ENDPOINT_RECEIVING, &ep->flags);
+
 		switch (type) {
 		case CPC_FRAME_TYPE_DATA:
 			cpc_protocol_on_data(ep, skb);
@@ -50,6 +52,8 @@ static void cpc_interface_rx_work(struct work_struct *work)
 			break;
 		}
 
+		clear_and_wake_up_bit(CPC_ENDPOINT_RECEIVING, &ep->flags);
+
 		cpc_endpoint_put(ep);
 	}
 }
-- 
2.49.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ