Skip to content

Commit 8acca6a

Browse files
qsndavem330
authored andcommitted
macsec: key identifier is 128 bits, not 64
The MACsec standard mentions a key identifier for each key, but doesn't specify anything about it, so I arbitrarily chose 64 bits. IEEE 802.1X-2010 specifies MKA (MACsec Key Agreement), and defines the key identifier to be 128 bits (96 bits "member identifier" + 32 bits "key number"). Signed-off-by: Sabrina Dubroca <[email protected]> Acked-by: Hannes Frederic Sowa <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c81aa79 commit 8acca6a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

drivers/net/macsec.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct gcm_iv {
8585
* @tfm: crypto struct, key storage
8686
*/
8787
struct macsec_key {
88-
u64 id;
88+
u8 id[MACSEC_KEYID_LEN];
8989
struct crypto_aead *tfm;
9090
};
9191

@@ -1529,7 +1529,8 @@ static const struct nla_policy macsec_genl_sa_policy[NUM_MACSEC_SA_ATTR] = {
15291529
[MACSEC_SA_ATTR_AN] = { .type = NLA_U8 },
15301530
[MACSEC_SA_ATTR_ACTIVE] = { .type = NLA_U8 },
15311531
[MACSEC_SA_ATTR_PN] = { .type = NLA_U32 },
1532-
[MACSEC_SA_ATTR_KEYID] = { .type = NLA_U64 },
1532+
[MACSEC_SA_ATTR_KEYID] = { .type = NLA_BINARY,
1533+
.len = MACSEC_KEYID_LEN, },
15331534
[MACSEC_SA_ATTR_KEY] = { .type = NLA_BINARY,
15341535
.len = MACSEC_MAX_KEY_LEN, },
15351536
};
@@ -1576,6 +1577,9 @@ static bool validate_add_rxsa(struct nlattr **attrs)
15761577
return false;
15771578
}
15781579

1580+
if (nla_len(attrs[MACSEC_SA_ATTR_KEYID]) != MACSEC_KEYID_LEN)
1581+
return false;
1582+
15791583
return true;
15801584
}
15811585

@@ -1641,7 +1645,7 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
16411645
if (tb_sa[MACSEC_SA_ATTR_ACTIVE])
16421646
rx_sa->active = !!nla_get_u8(tb_sa[MACSEC_SA_ATTR_ACTIVE]);
16431647

1644-
rx_sa->key.id = nla_get_u64(tb_sa[MACSEC_SA_ATTR_KEYID]);
1648+
nla_memcpy(rx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEY], MACSEC_KEYID_LEN);
16451649
rx_sa->sc = rx_sc;
16461650
rcu_assign_pointer(rx_sc->sa[assoc_num], rx_sa);
16471651

@@ -1722,6 +1726,9 @@ static bool validate_add_txsa(struct nlattr **attrs)
17221726
return false;
17231727
}
17241728

1729+
if (nla_len(attrs[MACSEC_SA_ATTR_KEYID]) != MACSEC_KEYID_LEN)
1730+
return false;
1731+
17251732
return true;
17261733
}
17271734

@@ -1777,7 +1784,7 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info)
17771784
return -ENOMEM;
17781785
}
17791786

1780-
tx_sa->key.id = nla_get_u64(tb_sa[MACSEC_SA_ATTR_KEYID]);
1787+
nla_memcpy(tx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEY], MACSEC_KEYID_LEN);
17811788

17821789
spin_lock_bh(&tx_sa->lock);
17831790
tx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]);
@@ -2318,7 +2325,7 @@ static int dump_secy(struct macsec_secy *secy, struct net_device *dev,
23182325

23192326
if (nla_put_u8(skb, MACSEC_SA_ATTR_AN, i) ||
23202327
nla_put_u32(skb, MACSEC_SA_ATTR_PN, tx_sa->next_pn) ||
2321-
nla_put_u64(skb, MACSEC_SA_ATTR_KEYID, tx_sa->key.id) ||
2328+
nla_put(skb, MACSEC_SA_ATTR_KEYID, MACSEC_KEYID_LEN, tx_sa->key.id) ||
23222329
nla_put_u8(skb, MACSEC_SA_ATTR_ACTIVE, tx_sa->active)) {
23232330
nla_nest_cancel(skb, txsa_nest);
23242331
nla_nest_cancel(skb, txsa_list);
@@ -2419,7 +2426,7 @@ static int dump_secy(struct macsec_secy *secy, struct net_device *dev,
24192426

24202427
if (nla_put_u8(skb, MACSEC_SA_ATTR_AN, i) ||
24212428
nla_put_u32(skb, MACSEC_SA_ATTR_PN, rx_sa->next_pn) ||
2422-
nla_put_u64(skb, MACSEC_SA_ATTR_KEYID, rx_sa->key.id) ||
2429+
nla_put(skb, MACSEC_SA_ATTR_KEYID, MACSEC_KEYID_LEN, rx_sa->key.id) ||
24232430
nla_put_u8(skb, MACSEC_SA_ATTR_ACTIVE, rx_sa->active)) {
24242431
nla_nest_cancel(skb, rxsa_nest);
24252432
nla_nest_cancel(skb, rxsc_nest);

include/uapi/linux/if_macsec.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#define MACSEC_MAX_KEY_LEN 128
2121

22+
#define MACSEC_KEYID_LEN 16
23+
2224
#define MACSEC_DEFAULT_CIPHER_ID 0x0080020001000001ULL
2325
#define MACSEC_DEFAULT_CIPHER_ALT 0x0080C20001000001ULL
2426

@@ -77,7 +79,7 @@ enum macsec_sa_attrs {
7779
MACSEC_SA_ATTR_ACTIVE, /* config/dump, u8 0..1 */
7880
MACSEC_SA_ATTR_PN, /* config/dump, u32 */
7981
MACSEC_SA_ATTR_KEY, /* config, data */
80-
MACSEC_SA_ATTR_KEYID, /* config/dump, u64 */
82+
MACSEC_SA_ATTR_KEYID, /* config/dump, 128-bit */
8183
MACSEC_SA_ATTR_STATS, /* dump, nested, macsec_sa_stats_attr */
8284
__MACSEC_SA_ATTR_END,
8385
NUM_MACSEC_SA_ATTR = __MACSEC_SA_ATTR_END,

0 commit comments

Comments
 (0)