Skip to contentSkip to conversation

macsec: check for duplicate SCIs before registering the device

PATCH Applied Haseeb Malik 3 participants 3 messages Oct 11 – Oct 16

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 macsec: check for duplicate SCIs before registering the device

macsec_newlink() registers and links the device before rejecting a duplicate SCI. Registration can emit link notifications for a device whose creation ultimately fails with -EBUSY.

The SCI is already resolved before SecY initialization, so check for a duplicate there and return -EBUSY directly. Remove the now-unused unlink label while preserving cleanup for failures after registration.

---
Tested on arm64 in virtme with KASAN and lockdep: all 15 MACsec selftests and 80 offload/cleanup cycles pass. Rejected-device link notifications observed by the diagnostic drop from two to zero.

 drivers/net/macsec.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/net/macsec.c +3 -6
index 409fd855235ba29125e39bfd80e1c5656aea784f..4e3020586b1e53c5a17f7e31c1f15b87f6443e17 100644
@@ -4264,6 +4264,9 @@ static int macsec_newlink(struct net_device *dev,
 	if (sci == MACSEC_UNDEF_SCI)
 		sci = dev_to_sci(dev, MACSEC_PORT_ES);
 
+	if (rx_handler && sci_exists(real_dev, sci))
+		return -EBUSY;
+
 	/* Registration can notify listeners before returning. */
 	macsec_init_secy(dev, sci, icv_len);
 	if (data) {
@@ -4284,11 +4287,6 @@ static int macsec_newlink(struct net_device *dev,
 	if (err < 0)
 		goto unregister;
 
-	if (rx_handler && sci_exists(real_dev, sci)) {
-		err = -EBUSY;
-		goto unlink;
-	}
-
 	/* If h/w offloading is available, propagate to the device */
 	if (macsec_is_offloaded(macsec)) {
 		const struct macsec_ops *ops;
@@ -4320,7 +4318,6 @@ static int macsec_newlink(struct net_device *dev,
 
 del_dev:
 	macsec_del_dev(macsec);
-unlink:
 	netdev_upper_dev_unlink(real_dev, dev);
 unregister:
 	unregister_netdevice(dev);

base-commit: 8df0638138d3e0344fd1fb36cf2d1ca1cf5028f0

maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · 2026-10-11, 21:57:11 +0000, Haseeb Malik via B4 Relay wrote:

From: Haseeb Malik <[email protected]>

macsec_newlink() registers and links the device before rejecting a duplicate SCI. Registration can emit link notifications for a device whose creation ultimately fails with -EBUSY.

The SCI is already resolved before SecY initialization, so check for a duplicate there and return -EBUSY directly. Remove the now-unused unlink label while preserving cleanup for failures after registration.

Quoted 8 lines

---
Tested on arm64 in virtme with KASAN and lockdep: all 15 MACsec selftests and 80 offload/cleanup cycles pass. Rejected-device link notifications observed by the diagnostic drop from two to zero.

Thanks.

Sashiko is probably going to complain again about the mdo_add_secy cleanup problem it caught in
https://lore.kernel.org/all/[email protected]/

If you have the time and interest to look at this, it would be nice. If not, no worries, I'll take care of it later.

Signature · 1 line
Sabrina
#2 lore raw
In reply to Haseeb Malik
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Sun, 11 Oct 2026 21:57:11 +0000 you wrote:

From: Haseeb Malik <[email protected]>

macsec_newlink() registers and links the device before rejecting a duplicate SCI. Registration can emit link notifications for a device whose creation ultimately fails with -EBUSY.

The SCI is already resolved before SecY initialization, so check for a duplicate there and return -EBUSY directly. Remove the now-unused unlink label while preserving cleanup for failures after registration.

[...]

Here is the summary with links:
- [net-next] macsec: check for duplicate SCIs before registering the device

    https://git.kernel.org/netdev/net-next/c/de3ef6921c00

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html