* [PATCH net] macsec: MACsec SCI assignment for ES = 0
@ 2025-05-29 12:44 carlos.fernandez
2025-06-03 7:04 ` Subbaraya Sundeep
2025-06-03 8:06 ` Carlos Fernandez
0 siblings, 2 replies; 5+ messages in thread
From: carlos.fernandez @ 2025-05-29 12:44 UTC (permalink / raw)
To: linux-kernel
Cc: carlos.fernandez, Sabrina Dubroca, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev
From: Carlos Fernandez <carlos.fernandez@technica-engineering.de>
According to 802.1AE standard, when ES and SC flags in TCI are zero, used
SCI should be the current active SC_RX but current code uses the header
MAC address.
Without this patch, when ES flag is 0 (using a bridge or switch), header
MAC will not be equal to the SCI and MACSec frames will be discarted.
Signed-off-by: Carlos Fernandez <carlos.fernandez@technica-engineering.de>
---
drivers/net/macsec.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 3d315e30ee47..9a743aee2cea 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -247,15 +247,29 @@ static sci_t make_sci(const u8 *addr, __be16 port)
return sci;
}
-static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present)
+static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present,
+ struct macsec_rxh_data *rxd)
{
- sci_t sci;
+ struct macsec_dev *macsec_device;
+ sci_t sci = 0;
- if (sci_present)
+ if (sci_present) {
memcpy(&sci, hdr->secure_channel_id,
sizeof(hdr->secure_channel_id));
- else
+ } else if (!(hdr->tci_an & (MACSEC_TCI_ES | MACSEC_TCI_SC))) {
+ list_for_each_entry_rcu(macsec_device, &rxd->secys, secys) {
+ struct macsec_secy *secy = &macsec_device->secy;
+ struct macsec_rx_sc *rx_sc;
+
+ for_each_rxsc(secy, rx_sc) {
+ rx_sc = rx_sc ? macsec_rxsc_get(rx_sc) : NULL;
+ if (rx_sc && rx_sc->active)
+ sci = rx_sc->sci;
+ }
+ }
+ } else {
sci = make_sci(hdr->eth.h_source, MACSEC_PORT_ES);
+ }
return sci;
}
@@ -1156,11 +1170,12 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
macsec_skb_cb(skb)->has_sci = !!(hdr->tci_an & MACSEC_TCI_SC);
macsec_skb_cb(skb)->assoc_num = hdr->tci_an & MACSEC_AN_MASK;
- sci = macsec_frame_sci(hdr, macsec_skb_cb(skb)->has_sci);
rcu_read_lock();
rxd = macsec_data_rcu(skb->dev);
+ sci = macsec_frame_sci(hdr, macsec_skb_cb(skb)->has_sci, rxd);
+
list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
struct macsec_rx_sc *sc = find_rx_sc(&macsec->secy, sci);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH net] macsec: MACsec SCI assignment for ES = 0
2025-05-29 12:44 [PATCH net] macsec: MACsec SCI assignment for ES = 0 carlos.fernandez
@ 2025-06-03 7:04 ` Subbaraya Sundeep
2025-06-03 8:06 ` Carlos Fernandez
1 sibling, 0 replies; 5+ messages in thread
From: Subbaraya Sundeep @ 2025-06-03 7:04 UTC (permalink / raw)
To: carlos.fernandez
Cc: linux-kernel, Sabrina Dubroca, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev
Hi,
On 2025-05-29 at 12:44:42, carlos.fernandez@technica-engineering.de (carlos.fernandez@technica-engineering.de) wrote:
> From: Carlos Fernandez <carlos.fernandez@technica-engineering.de>
>
> According to 802.1AE standard, when ES and SC flags in TCI are zero, used
> SCI should be the current active SC_RX but current code uses the header
> MAC address.
>
> Without this patch, when ES flag is 0 (using a bridge or switch), header
> MAC will not be equal to the SCI and MACSec frames will be discarted.
>
> Signed-off-by: Carlos Fernandez <carlos.fernandez@technica-engineering.de>
> ---
> drivers/net/macsec.c | 25 ++++++++++++++++++++-----
> 1 file changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
> index 3d315e30ee47..9a743aee2cea 100644
> --- a/drivers/net/macsec.c
> +++ b/drivers/net/macsec.c
> @@ -247,15 +247,29 @@ static sci_t make_sci(const u8 *addr, __be16 port)
> return sci;
> }
>
> -static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present)
> +static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present,
> + struct macsec_rxh_data *rxd)
> {
> - sci_t sci;
> + struct macsec_dev *macsec_device;
> + sci_t sci = 0;
>
> - if (sci_present)
> + if (sci_present) {
> memcpy(&sci, hdr->secure_channel_id,
> sizeof(hdr->secure_channel_id));
> - else
> + } else if (!(hdr->tci_an & (MACSEC_TCI_ES | MACSEC_TCI_SC))) {
> + list_for_each_entry_rcu(macsec_device, &rxd->secys, secys) {
> + struct macsec_secy *secy = &macsec_device->secy;
> + struct macsec_rx_sc *rx_sc;
> +
> + for_each_rxsc(secy, rx_sc) {
> + rx_sc = rx_sc ? macsec_rxsc_get(rx_sc) : NULL;
> + if (rx_sc && rx_sc->active)
> + sci = rx_sc->sci;
The intention of this logic is not clear to reader since you want
last sci in list or you forgot to return/break. Digging previous mail
chain you said loop iteration count will only be 1 but we are not
really sure about it. Please change as Sabrina suggested to check whether
RXSC is exactly one for lower device and if not drop the packet.
Write a comment on top of 'else if' so that we dont need to dig
into history of why this logic is like that.
Also this looks like net-next material, if you feel strongly this as
a fix which was missed from beginning then add Fixes tag.
Thanks,
Sundeep
> + }
> + }
> + } else {
> sci = make_sci(hdr->eth.h_source, MACSEC_PORT_ES);
> + }
>
> return sci;
> }
> @@ -1156,11 +1170,12 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
>
> macsec_skb_cb(skb)->has_sci = !!(hdr->tci_an & MACSEC_TCI_SC);
> macsec_skb_cb(skb)->assoc_num = hdr->tci_an & MACSEC_AN_MASK;
> - sci = macsec_frame_sci(hdr, macsec_skb_cb(skb)->has_sci);
>
> rcu_read_lock();
> rxd = macsec_data_rcu(skb->dev);
>
> + sci = macsec_frame_sci(hdr, macsec_skb_cb(skb)->has_sci, rxd);
> +
> list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
> struct macsec_rx_sc *sc = find_rx_sc(&macsec->secy, sci);
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH net] macsec: MACsec SCI assignment for ES = 0
2025-05-29 12:44 [PATCH net] macsec: MACsec SCI assignment for ES = 0 carlos.fernandez
2025-06-03 7:04 ` Subbaraya Sundeep
@ 2025-06-03 8:06 ` Carlos Fernandez
2025-06-03 8:18 ` Paolo Abeni
1 sibling, 1 reply; 5+ messages in thread
From: Carlos Fernandez @ 2025-06-03 8:06 UTC (permalink / raw)
Cc: carlos.fernandez, Sabrina Dubroca, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
Hi,
I'll ammend the patch and send it to net-next instead.
Thanks,
Carlos
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] macsec: MACsec SCI assignment for ES = 0
2025-06-03 8:06 ` Carlos Fernandez
@ 2025-06-03 8:18 ` Paolo Abeni
0 siblings, 0 replies; 5+ messages in thread
From: Paolo Abeni @ 2025-06-03 8:18 UTC (permalink / raw)
To: Carlos Fernandez
Cc: Sabrina Dubroca, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, netdev, linux-kernel
On 6/3/25 10:06 AM, Carlos Fernandez wrote:
> I'll ammend the patch and send it to net-next instead.
While at it:
- please include the changelog comprising a reference (URL) to the prior
discussion after the tag area and a '---' separator
- please include the patch revision in the subj prefix (v5 AFAICS)
- consider extracting the active sci lookup logic in a separate helper,
will probably simplify the code and will reduce the indentation.
Thanks,
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v3] macsec: MACsec SCI assignment for ES = 0
@ 2025-06-04 12:33 carlos.fernandez
2025-06-05 13:17 ` [PATCH net] " Carlos Fernandez
0 siblings, 1 reply; 5+ messages in thread
From: carlos.fernandez @ 2025-06-04 12:33 UTC (permalink / raw)
To: andreu.montiel
Cc: carlos.fernandez, Andreu Montiel, Sabrina Dubroca, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Hannes Frederic Sowa, netdev, linux-kernel
From: Carlos Fernandez <carlos.fernandez@technica-engineering.de>
According to 802.1AE standard, when ES and SC flags in TCI are zero,
used SCI should be the current active SC_RX. Current code uses the
header MAC address. Without this patch, when ES flag is 0 (using a
bridge or switch), header MAC will not fit the SCI and MACSec frames
will be discarted.
Fixes: c09440f7dcb3 ("macsec: introduce IEEE 802.1AE driver")
Co-developed-by: Andreu Montiel <Andreu.Montiel@technica-engineering.de>
Signed-off-by: Andreu Montiel <Andreu.Montiel@technica-engineering.de>
Signed-off-by: Carlos Fernandez <carlos.fernandez@technica-engineering.de>
---
v3:
* Wrong drop frame afer macsec_frame_sci
* Wrong Fixes tag in message
v2: https://patchwork.kernel.org/project/netdevbpf/patch/20250604113213.2595524-1-carlos.fernandez@technica-engineering.de/
* Active sci lookup logic in a separate helper.
* Unnecessary loops avoided.
* Check RXSC is exactly one for lower device.
* Drops frame in case of error.
v1: https://patchwork.kernel.org/project/netdevbpf/patch/20250529124455.2761783-1-carlos.fernandez@technica-engineering.de/
drivers/net/macsec.c | 40 ++++++++++++++++++++++++++++++++++------
1 file changed, 34 insertions(+), 6 deletions(-)
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 3d315e30ee47..7edbe76b5455 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -247,15 +247,39 @@ static sci_t make_sci(const u8 *addr, __be16 port)
return sci;
}
-static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present)
+static sci_t macsec_active_sci(struct macsec_secy *secy)
{
- sci_t sci;
+ struct macsec_rx_sc *rx_sc = rcu_dereference_bh(secy->rx_sc);
+
+ /* Case single RX SC */
+ if (rx_sc && !rcu_dereference_bh(rx_sc->next))
+ return (rx_sc->active) ? rx_sc->sci : 0;
+ /* Case no RX SC or multiple */
+ else
+ return 0;
+}
+
+static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present,
+ struct macsec_rxh_data *rxd)
+{
+ struct macsec_dev *macsec;
+ sci_t sci = 0;
- if (sci_present)
+ /* SC = 1 */
+ if (sci_present) {
memcpy(&sci, hdr->secure_channel_id,
sizeof(hdr->secure_channel_id));
- else
+ /* SC = 0; ES = 0 */
+ } else if ((!(hdr->tci_an & (MACSEC_TCI_ES | MACSEC_TCI_SC))) &&
+ (list_is_singular(&rxd->secys))) {
+ /* Only one SECY should exist on this scenario */
+ macsec = list_first_or_null_rcu(&rxd->secys, struct macsec_dev,
+ secys);
+ if (macsec)
+ return macsec_active_sci(&macsec->secy);
+ } else {
sci = make_sci(hdr->eth.h_source, MACSEC_PORT_ES);
+ }
return sci;
}
@@ -1109,7 +1133,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
struct macsec_rxh_data *rxd;
struct macsec_dev *macsec;
unsigned int len;
- sci_t sci;
+ sci_t sci = 0;
u32 hdr_pn;
bool cbit;
struct pcpu_rx_sc_stats *rxsc_stats;
@@ -1156,11 +1180,14 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
macsec_skb_cb(skb)->has_sci = !!(hdr->tci_an & MACSEC_TCI_SC);
macsec_skb_cb(skb)->assoc_num = hdr->tci_an & MACSEC_AN_MASK;
- sci = macsec_frame_sci(hdr, macsec_skb_cb(skb)->has_sci);
rcu_read_lock();
rxd = macsec_data_rcu(skb->dev);
+ sci = macsec_frame_sci(hdr, macsec_skb_cb(skb)->has_sci, rxd);
+ if (!sci)
+ goto drop_nosc;
+
list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
struct macsec_rx_sc *sc = find_rx_sc(&macsec->secy, sci);
@@ -1283,6 +1310,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
macsec_rxsa_put(rx_sa);
drop_nosa:
macsec_rxsc_put(rx_sc);
+drop_nosc:
rcu_read_unlock();
drop_direct:
kfree_skb(skb);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH net] macsec: MACsec SCI assignment for ES = 0
2025-06-04 12:33 [PATCH net v3] " carlos.fernandez
@ 2025-06-05 13:17 ` Carlos Fernandez
0 siblings, 0 replies; 5+ messages in thread
From: Carlos Fernandez @ 2025-06-05 13:17 UTC (permalink / raw)
Cc: carlos.fernandez, sbhatta, Sabrina Dubroca, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Hannes Frederic Sowa, netdev, linux-kernel
Hi Sundeep,
In order to test this scenario, ES and SC flags must be 0 and
port identifier should be different than 1.
In order to test it, I runned the following commands that configure
two network interfaces on qemu over different namespaces.
After applying this configuration, MACsec ping works in the patched version
but fails with the original code.
I'll paste the script commands here. Hope it helps your testing.
PORT=11
SEND_SCI="off"
ETH1_MAC="52:54:00:12:34:57"
ETH0_MAC="52:54:00:12:34:56"
ENCRYPT="on"
ip netns add macsec1
ip netns add macsec0
ip link set eth0 netns macsec0
ip link set eth1 netns macsec1
ip netns exec macsec0 ip link add link eth0 macsec0 type macsec port $PORT send_sci $SEND_SCI end_station off encrypt $ENCRYPT
ip netns exec macsec0 ip macsec add macsec0 tx sa 0 pn 2 on key 01 12345678901234567890123456789012
ip netns exec macsec0 ip macsec add macsec0 rx port $PORT address $ETH1_MAC
ip netns exec macsec0 ip macsec add macsec0 rx port $PORT address $ETH1_MAC sa 0 pn 2 on key 02 09876543210987654321098765432109
ip netns exec macsec0 ip link set dev macsec0 up
ip netns exec macsec0 ip addr add 10.10.12.1/24 dev macsec0
ip netns exec macsec1 ip link add link eth1 macsec1 type macsec port $PORT send_sci $SEND_SCI end_station off encrypt $ENCRYPT
ip netns exec macsec1 ip macsec add macsec1 tx sa 0 pn 2 on key 02 09876543210987654321098765432109
ip netns exec macsec1 ip macsec add macsec1 rx port $PORT address $ETH0_MAC
ip netns exec macsec1 ip macsec add macsec1 rx port $PORT address $ETH0_MAC sa 0 pn 2 on key 01 12345678901234567890123456789012
ip netns exec macsec1 ip link set dev macsec1 up
ip netns exec macsec1 ip addr add 10.10.12.2/24 dev macsec1
ip netns exec macsec1 ping 10.10.12.1 #Ping works on patched version.
Thanks,
Carlos
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-06-05 13:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-29 12:44 [PATCH net] macsec: MACsec SCI assignment for ES = 0 carlos.fernandez
2025-06-03 7:04 ` Subbaraya Sundeep
2025-06-03 8:06 ` Carlos Fernandez
2025-06-03 8:18 ` Paolo Abeni
-- strict thread matches above, loose matches on Subject: below --
2025-06-04 12:33 [PATCH net v3] " carlos.fernandez
2025-06-05 13:17 ` [PATCH net] " Carlos Fernandez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox