Skip to content

Commit c630d1f

Browse files
qsndavem330
authored andcommitted
macsec: always read MACSEC_SA_ATTR_PN as a u64
Currently, MACSEC_SA_ATTR_PN is handled inconsistently, sometimes as a u32, sometimes forced into a u64 without checking the actual length of the attribute. Instead, we can use nla_get_u64 everywhere, which will read up to 64 bits into a u64, capped by the actual length of the attribute coming from userspace. This fixes several issues: - the check in validate_add_rxsa doesn't work with 32-bit attributes - the checks in validate_add_txsa and validate_upd_sa incorrectly reject X << 32 (with X != 0) Fixes: 48ef50f ("macsec: Netlink support of XPN cipher suites (IEEE 802.1AEbw)") Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b07a0e2 commit c630d1f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/net/macsec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ static bool validate_add_rxsa(struct nlattr **attrs)
16981698
return false;
16991699

17001700
if (attrs[MACSEC_SA_ATTR_PN] &&
1701-
*(u64 *)nla_data(attrs[MACSEC_SA_ATTR_PN]) == 0)
1701+
nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
17021702
return false;
17031703

17041704
if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
@@ -1941,7 +1941,7 @@ static bool validate_add_txsa(struct nlattr **attrs)
19411941
if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
19421942
return false;
19431943

1944-
if (nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
1944+
if (nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
19451945
return false;
19461946

19471947
if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
@@ -2295,7 +2295,7 @@ static bool validate_upd_sa(struct nlattr **attrs)
22952295
if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
22962296
return false;
22972297

2298-
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)
22992299
return false;
23002300

23012301
if (attrs[MACSEC_SA_ATTR_ACTIVE]) {

0 commit comments

Comments
 (0)