Skip to content

Commit 20a8546

Browse files
committed
Merge branch 'macsec-config-issues'
Sabrina Dubroca says: ==================== macsec: fix config issues The patch adding netlink support for XPN (commit 48ef50f ("macsec: Netlink support of XPN cipher suites (IEEE 802.1AEbw)")) introduced several issues, including a kernel panic reported at [1]. Reproducing those bugs with upstream iproute is limited, since iproute doesn't currently support XPN. I'm also working on this. [1] https://bugzilla.kernel.org/show_bug.cgi?id=208315 ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 1aaa62c + c630d1f commit 20a8546

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

drivers/net/macsec.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ static struct macsec_cb *macsec_skb_cb(struct sk_buff *skb)
243243
#define DEFAULT_SEND_SCI true
244244
#define DEFAULT_ENCRYPT false
245245
#define DEFAULT_ENCODING_SA 0
246+
#define MACSEC_XPN_MAX_REPLAY_WINDOW (((1 << 30) - 1))
246247

247248
static bool send_sci(const struct macsec_secy *secy)
248249
{
@@ -1697,7 +1698,7 @@ static bool validate_add_rxsa(struct nlattr **attrs)
16971698
return false;
16981699

16991700
if (attrs[MACSEC_SA_ATTR_PN] &&
1700-
*(u64 *)nla_data(attrs[MACSEC_SA_ATTR_PN]) == 0)
1701+
nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
17011702
return false;
17021703

17031704
if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
@@ -1753,7 +1754,8 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
17531754
}
17541755

17551756
pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
1756-
if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
1757+
if (tb_sa[MACSEC_SA_ATTR_PN] &&
1758+
nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
17571759
pr_notice("macsec: nl: add_rxsa: bad pn length: %d != %d\n",
17581760
nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
17591761
rtnl_unlock();
@@ -1769,7 +1771,7 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
17691771
if (nla_len(tb_sa[MACSEC_SA_ATTR_SALT]) != MACSEC_SALT_LEN) {
17701772
pr_notice("macsec: nl: add_rxsa: bad salt length: %d != %d\n",
17711773
nla_len(tb_sa[MACSEC_SA_ATTR_SALT]),
1772-
MACSEC_SA_ATTR_SALT);
1774+
MACSEC_SALT_LEN);
17731775
rtnl_unlock();
17741776
return -EINVAL;
17751777
}
@@ -1939,7 +1941,7 @@ static bool validate_add_txsa(struct nlattr **attrs)
19391941
if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
19401942
return false;
19411943

1942-
if (nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
1944+
if (nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
19431945
return false;
19441946

19451947
if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
@@ -2011,7 +2013,7 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info)
20112013
if (nla_len(tb_sa[MACSEC_SA_ATTR_SALT]) != MACSEC_SALT_LEN) {
20122014
pr_notice("macsec: nl: add_txsa: bad salt length: %d != %d\n",
20132015
nla_len(tb_sa[MACSEC_SA_ATTR_SALT]),
2014-
MACSEC_SA_ATTR_SALT);
2016+
MACSEC_SALT_LEN);
20152017
rtnl_unlock();
20162018
return -EINVAL;
20172019
}
@@ -2293,7 +2295,7 @@ static bool validate_upd_sa(struct nlattr **attrs)
22932295
if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
22942296
return false;
22952297

2296-
if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
2298+
if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
22972299
return false;
22982300

22992301
if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
@@ -3745,9 +3747,6 @@ static int macsec_changelink_common(struct net_device *dev,
37453747
secy->operational = tx_sa && tx_sa->active;
37463748
}
37473749

3748-
if (data[IFLA_MACSEC_WINDOW])
3749-
secy->replay_window = nla_get_u32(data[IFLA_MACSEC_WINDOW]);
3750-
37513750
if (data[IFLA_MACSEC_ENCRYPT])
37523751
tx_sc->encrypt = !!nla_get_u8(data[IFLA_MACSEC_ENCRYPT]);
37533752

@@ -3793,6 +3792,16 @@ static int macsec_changelink_common(struct net_device *dev,
37933792
}
37943793
}
37953794

3795+
if (data[IFLA_MACSEC_WINDOW]) {
3796+
secy->replay_window = nla_get_u32(data[IFLA_MACSEC_WINDOW]);
3797+
3798+
/* IEEE 802.1AEbw-2013 10.7.8 - maximum replay window
3799+
* for XPN cipher suites */
3800+
if (secy->xpn &&
3801+
secy->replay_window > MACSEC_XPN_MAX_REPLAY_WINDOW)
3802+
return -EINVAL;
3803+
}
3804+
37963805
return 0;
37973806
}
37983807

@@ -3822,7 +3831,7 @@ static int macsec_changelink(struct net_device *dev, struct nlattr *tb[],
38223831

38233832
ret = macsec_changelink_common(dev, data);
38243833
if (ret)
3825-
return ret;
3834+
goto cleanup;
38263835

38273836
/* If h/w offloading is available, propagate to the device */
38283837
if (macsec_is_offloaded(macsec)) {

0 commit comments

Comments
 (0)