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.

Suggested-by: Sabrina Dubroca <sd@queasysnail.net>
Link: https://lore.kernel.org/netdev/ar2KmwhtCMbOKLsG@krikkit/
Signed-off-by: Haseeb Malik <haseebulhaq55@gmail.com>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Link: https://patch.msgid.link/20261011-macsec-early-sci-check-2b1f06af193f@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Haseeb Malik 2026-10-11 21:57:11 +00:00 committed by Jakub Kicinski
parent 9c7e89fc1b
commit de3ef6921c

View File

@ -4269,6 +4269,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) {
@ -4289,11 +4292,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;
@ -4325,7 +4323,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);