From: Haseeb Malik via B4 Relay <devnull+haseebulhaq55.gmail.com@kernel.org>
To: Sabrina Dubroca <sd@queasysnail.net>, netdev@vger.kernel.org
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next] macsec: check for duplicate SCIs before registering the device
Date: Sun, 11 Oct 2026 21:57:11 +0000 [thread overview]
Message-ID: <20261011-macsec-early-sci-check-2b1f06af193f@gmail.com> (raw)
From: Haseeb Malik <haseebulhaq55@gmail.com>
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.
Suggested-by: Sabrina Dubroca <sd@queasysnail.net>
Link: https://lore.kernel.org/netdev/ar2KmwhtCMbOKLsG@krikkit/
Assisted-by: LLM
Signed-off-by: Haseeb Malik <haseebulhaq55@gmail.com>
---
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(-)
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 409fd855235ba29125e39bfd80e1c5656aea784f..4e3020586b1e53c5a17f7e31c1f15b87f6443e17 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -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
next reply other threads:[~2026-10-11 22:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 21:57 Haseeb Malik via B4 Relay [this message]
2026-10-12 9:00 ` Sabrina Dubroca
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261011-macsec-early-sci-check-2b1f06af193f@gmail.com \
--to=devnull+haseebulhaq55.gmail.com@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=haseebulhaq55@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sd@queasysnail.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®