Skip to contentSkip to conversation

macsec: check the resolved SCI for duplicates

PATCH Superseded Haseeb Malik 2 participants 2 messages Oct 1

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 macsec: check the resolved SCI for duplicates

An all-ones IFLA_MACSEC_SCI selects the default SCI derived from the MACsec device's MAC address and port 1. macsec_init_secy() resolves this value and stores the result in secy.sci, but macsec_newlink() checks for duplicates using the unchanged local sci argument.

Consequently, an all-ones request can create a second MACsec device with the same transmit SCI on the same lower device, while requesting that SCI explicitly returns -EBUSY.

Resolve an undefined SCI in macsec_newlink() before initializing the SecY, so initialization and duplicate detection use the same value. Preserve the all-ones fallback when the resulting SCI is available.

Add regression tests for duplicate rejection using default, explicit and all-ones SCI requests, and for valid fallback and reuse after deletion. Skip these local tests when iproute2 lacks MACsec support.

Fixes c09440f7dcb3 ("macsec: introduce IEEE 802.1AE driver")
Assisted-by LLM

---
Changes in v2:
- Resolve undefined SCI in macsec_newlink(), as suggested by Sabrina.
- Check local iproute2 MACsec support in the new tests, as Sashiko noted.

Link to v1: https://lore.kernel.org/netdev/[email protected]/

Tested on arm64/virtme with KASAN and lockdep: the new regression tests go from 5 pass/2 fail to 7 pass/0 fail. The full MACsec selftest passes all 15 cases without skips.

---
 drivers/net/macsec.c                          |  8 ++--
 tools/testing/selftests/drivers/net/macsec.py | 57 +++++++++++++++++++++++++--
 2 files changed, 57 insertions(+), 8 deletions(-)
drivers/net/macsec.c +3 -5
index 78a19b134632..69686f22eda8 100644
@@ -4143,9 +4143,6 @@ static void macsec_init_secy(struct net_device *dev, sci_t sci, u8 icv_len)
 	struct macsec_dev *macsec = macsec_priv(dev);
 	struct macsec_secy *secy = &macsec->secy;
 
-	if (sci == MACSEC_UNDEF_SCI)
-		sci = dev_to_sci(dev, MACSEC_PORT_ES);
-
 	secy->netdev = dev;
 	secy->operational = true;
 	secy->key_len = DEFAULT_SAK_LEN;
@@ -4178,7 +4175,7 @@ static int macsec_newlink(struct net_device *dev,
 	u8 icv_len = MACSEC_DEFAULT_ICV_LEN;
 	struct net_device *real_dev;
 	int err, mtu;
-	sci_t sci;
+	sci_t sci = MACSEC_UNDEF_SCI;
 
 	if (!tb[IFLA_LINK])
 		return -EINVAL;
@@ -4231,7 +4228,8 @@ static int macsec_newlink(struct net_device *dev,
 		sci = nla_get_sci(data[IFLA_MACSEC_SCI]);
 	else if (data && data[IFLA_MACSEC_PORT])
 		sci = dev_to_sci(dev, nla_get_be16(data[IFLA_MACSEC_PORT]));
-	else
+
+	if (sci == MACSEC_UNDEF_SCI)
 		sci = dev_to_sci(dev, MACSEC_PORT_ES);
 
 	/* Registration can notify listeners before returning. */
tools/testing/selftests/drivers/net/macsec.py +54 -3

75 lines not on this page · raw message

---
base-commit: 11536ee3d3e0b1bd35b6f3f8df55a6053eb0c71d
change-id: 20260926-fix-macsec-duplicate-sci-ed7635ac1c35

Best regards,

Signature · 1 line
Haseeb Malik <[email protected]>
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.