aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2016-10-24 09:44:26 -0400
committerDavid S. Miller <davem@davemloft.net>2016-10-27 16:21:00 -0400
commite0f841f5cbf2a195c63f3441f3d8ef1cd2bdeeed (patch)
treedee1989eb0d3ce80167b44b12ee6c6000e26279a
parentf62265b53ef34a372b657c99e23d32e95b464316 (diff)
macsec: Fix header length if SCI is added if explicitly disabled
Even if sending SCIs is explicitly disabled, the code that creates the Security Tag might still decide to add it (e.g. if multiple RX SCs are defined on the MACsec interface). But because the header length so far only depended on the configuration option the SCI overwrote the original frame's contents (EtherType and e.g. the beginning of the IP header) and if encrypted did not visibly end up in the packet, while the SC flag in the TCI field of the Security Tag was still set, resulting in invalid MACsec frames. Fixes: c09440f7dcb3 ("macsec: introduce IEEE 802.1AE driver") Signed-off-by: Tobias Brunner <tobias@strongswan.org> Acked-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/macsec.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 3ea47f28e143..d2e61e002926 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -397,6 +397,14 @@ static struct macsec_cb *macsec_skb_cb(struct sk_buff *skb)
397#define DEFAULT_ENCRYPT false 397#define DEFAULT_ENCRYPT false
398#define DEFAULT_ENCODING_SA 0 398#define DEFAULT_ENCODING_SA 0
399 399
400static bool send_sci(const struct macsec_secy *secy)
401{
402 const struct macsec_tx_sc *tx_sc = &secy->tx_sc;
403
404 return tx_sc->send_sci ||
405 (secy->n_rx_sc > 1 && !tx_sc->end_station && !tx_sc->scb);
406}
407
400static sci_t make_sci(u8 *addr, __be16 port) 408static sci_t make_sci(u8 *addr, __be16 port)
401{ 409{
402 sci_t sci; 410 sci_t sci;
@@ -437,15 +445,15 @@ static unsigned int macsec_extra_len(bool sci_present)
437 445
438/* Fill SecTAG according to IEEE 802.1AE-2006 10.5.3 */ 446/* Fill SecTAG according to IEEE 802.1AE-2006 10.5.3 */
439static void macsec_fill_sectag(struct macsec_eth_header *h, 447static void macsec_fill_sectag(struct macsec_eth_header *h,
440 const struct macsec_secy *secy, u32 pn) 448 const struct macsec_secy *secy, u32 pn,
449 bool sci_present)
441{ 450{
442 const struct macsec_tx_sc *tx_sc = &secy->tx_sc; 451 const struct macsec_tx_sc *tx_sc = &secy->tx_sc;
443 452
444 memset(&h->tci_an, 0, macsec_sectag_len(tx_sc->send_sci)); 453 memset(&h->tci_an, 0, macsec_sectag_len(sci_present));
445 h->eth.h_proto = htons(ETH_P_MACSEC); 454 h->eth.h_proto = htons(ETH_P_MACSEC);
446 455
447 if (tx_sc->send_sci || 456 if (sci_present) {
448 (secy->n_rx_sc > 1 && !tx_sc->end_station && !tx_sc->scb)) {
449 h->tci_an |= MACSEC_TCI_SC; 457 h->tci_an |= MACSEC_TCI_SC;
450 memcpy(&h->secure_channel_id, &secy->sci, 458 memcpy(&h->secure_channel_id, &secy->sci,
451 sizeof(h->secure_channel_id)); 459 sizeof(h->secure_channel_id));
@@ -650,6 +658,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
650 struct macsec_tx_sc *tx_sc; 658 struct macsec_tx_sc *tx_sc;
651 struct macsec_tx_sa *tx_sa; 659 struct macsec_tx_sa *tx_sa;
652 struct macsec_dev *macsec = macsec_priv(dev); 660 struct macsec_dev *macsec = macsec_priv(dev);
661 bool sci_present;
653 u32 pn; 662 u32 pn;
654 663
655 secy = &macsec->secy; 664 secy = &macsec->secy;
@@ -687,7 +696,8 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
687 696
688 unprotected_len = skb->len; 697 unprotected_len = skb->len;
689 eth = eth_hdr(skb); 698 eth = eth_hdr(skb);
690 hh = (struct macsec_eth_header *)skb_push(skb, macsec_extra_len(tx_sc->send_sci)); 699 sci_present = send_sci(secy);
700 hh = (struct macsec_eth_header *)skb_push(skb, macsec_extra_len(sci_present));
691 memmove(hh, eth, 2 * ETH_ALEN); 701 memmove(hh, eth, 2 * ETH_ALEN);
692 702
693 pn = tx_sa_update_pn(tx_sa, secy); 703 pn = tx_sa_update_pn(tx_sa, secy);
@@ -696,7 +706,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
696 kfree_skb(skb); 706 kfree_skb(skb);
697 return ERR_PTR(-ENOLINK); 707 return ERR_PTR(-ENOLINK);
698 } 708 }
699 macsec_fill_sectag(hh, secy, pn); 709 macsec_fill_sectag(hh, secy, pn, sci_present);
700 macsec_set_shortlen(hh, unprotected_len - 2 * ETH_ALEN); 710 macsec_set_shortlen(hh, unprotected_len - 2 * ETH_ALEN);
701 711
702 skb_put(skb, secy->icv_len); 712 skb_put(skb, secy->icv_len);
@@ -726,10 +736,10 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
726 skb_to_sgvec(skb, sg, 0, skb->len); 736 skb_to_sgvec(skb, sg, 0, skb->len);
727 737
728 if (tx_sc->encrypt) { 738 if (tx_sc->encrypt) {
729 int len = skb->len - macsec_hdr_len(tx_sc->send_sci) - 739 int len = skb->len - macsec_hdr_len(sci_present) -
730 secy->icv_len; 740 secy->icv_len;
731 aead_request_set_crypt(req, sg, sg, len, iv); 741 aead_request_set_crypt(req, sg, sg, len, iv);
732 aead_request_set_ad(req, macsec_hdr_len(tx_sc->send_sci)); 742 aead_request_set_ad(req, macsec_hdr_len(sci_present));
733 } else { 743 } else {
734 aead_request_set_crypt(req, sg, sg, 0, iv); 744 aead_request_set_crypt(req, sg, sg, 0, iv);
735 aead_request_set_ad(req, skb->len - secy->icv_len); 745 aead_request_set_ad(req, skb->len - secy->icv_len);