Skip to content

Commit 6c3020d

Browse files
Binary-Eatergregkh
authored andcommitted
macsec: Detect if Rx skb is macsec-related for offloading devices that update md_dst
commit 642c984 upstream. Can now correctly identify where the packets should be delivered by using md_dst or its absence on devices that provide it. This detection is not possible without device drivers that update md_dst. A fallback pattern should be used for supporting such device drivers. This fallback mode causes multicast messages to be cloned to both the non-macsec and macsec ports, independent of whether the multicast message received was encrypted over MACsec or not. Other non-macsec traffic may also fail to be handled correctly for devices in promiscuous mode. Link: https://lore.kernel.org/netdev/ZULRxX9eIbFiVi7v@hog/ Cc: Sabrina Dubroca <sd@queasysnail.net> Cc: stable@vger.kernel.org Fixes: 860ead8 ("net/macsec: Add MACsec skb_metadata_dst Rx Data path support") Signed-off-by: Rahul Rameshbabu <rrameshbabu@nvidia.com> Reviewed-by: Benjamin Poirier <bpoirier@nvidia.com> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Link: https://lore.kernel.org/r/20240423181319.115860-4-rrameshbabu@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ee5dde3 commit 6c3020d

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

drivers/net/macsec.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -996,10 +996,12 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
996996
struct metadata_dst *md_dst;
997997
struct macsec_rxh_data *rxd;
998998
struct macsec_dev *macsec;
999+
bool is_macsec_md_dst;
9991000

10001001
rcu_read_lock();
10011002
rxd = macsec_data_rcu(skb->dev);
10021003
md_dst = skb_metadata_dst(skb);
1004+
is_macsec_md_dst = md_dst && md_dst->type == METADATA_MACSEC;
10031005

10041006
list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
10051007
struct sk_buff *nskb;
@@ -1010,14 +1012,42 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
10101012
* the SecTAG, so we have to deduce which port to deliver to.
10111013
*/
10121014
if (macsec_is_offloaded(macsec) && netif_running(ndev)) {
1013-
struct macsec_rx_sc *rx_sc = NULL;
1015+
const struct macsec_ops *ops;
10141016

1015-
if (md_dst && md_dst->type == METADATA_MACSEC)
1016-
rx_sc = find_rx_sc(&macsec->secy, md_dst->u.macsec_info.sci);
1017+
ops = macsec_get_ops(macsec, NULL);
10171018

1018-
if (md_dst && md_dst->type == METADATA_MACSEC && !rx_sc)
1019+
if (ops->rx_uses_md_dst && !is_macsec_md_dst)
10191020
continue;
10201021

1022+
if (is_macsec_md_dst) {
1023+
struct macsec_rx_sc *rx_sc;
1024+
1025+
/* All drivers that implement MACsec offload
1026+
* support using skb metadata destinations must
1027+
* indicate that they do so.
1028+
*/
1029+
DEBUG_NET_WARN_ON_ONCE(!ops->rx_uses_md_dst);
1030+
rx_sc = find_rx_sc(&macsec->secy,
1031+
md_dst->u.macsec_info.sci);
1032+
if (!rx_sc)
1033+
continue;
1034+
/* device indicated macsec offload occurred */
1035+
skb->dev = ndev;
1036+
skb->pkt_type = PACKET_HOST;
1037+
eth_skb_pkt_type(skb, ndev);
1038+
ret = RX_HANDLER_ANOTHER;
1039+
goto out;
1040+
}
1041+
1042+
/* This datapath is insecure because it is unable to
1043+
* enforce isolation of broadcast/multicast traffic and
1044+
* unicast traffic with promiscuous mode on the macsec
1045+
* netdev. Since the core stack has no mechanism to
1046+
* check that the hardware did indeed receive MACsec
1047+
* traffic, it is possible that the response handling
1048+
* done by the MACsec port was to a plaintext packet.
1049+
* This violates the MACsec protocol standard.
1050+
*/
10211051
if (ether_addr_equal_64bits(hdr->h_dest,
10221052
ndev->dev_addr)) {
10231053
/* exact match, divert skb to this port */
@@ -1033,14 +1063,10 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
10331063
break;
10341064

10351065
nskb->dev = ndev;
1036-
if (ether_addr_equal_64bits(hdr->h_dest,
1037-
ndev->broadcast))
1038-
nskb->pkt_type = PACKET_BROADCAST;
1039-
else
1040-
nskb->pkt_type = PACKET_MULTICAST;
1066+
eth_skb_pkt_type(nskb, ndev);
10411067

10421068
__netif_rx(nskb);
1043-
} else if (rx_sc || ndev->flags & IFF_PROMISC) {
1069+
} else if (ndev->flags & IFF_PROMISC) {
10441070
skb->dev = ndev;
10451071
skb->pkt_type = PACKET_HOST;
10461072
ret = RX_HANDLER_ANOTHER;

0 commit comments

Comments
 (0)