diff options
author | Davide Caratti <dcaratti@redhat.com> | 2016-07-22 09:07:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-07-25 13:55:39 -0400 |
commit | 34aedfee22967236adc3d9147c8b47b7f5bad26c (patch) | |
tree | 803b910b1bc2476176754ed51a5b1ff48be7576e /drivers/net/macsec.c | |
parent | 2ccbe2cb79f2f74ab739252299b6f9ff27586f2c (diff) |
macsec: fix error codes when a SA is created
preserve the return value of AEAD functions that are called when a SA is
created, to avoid inappropriate display of "RTNETLINK answers: Cannot
allocate memory" message.
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/macsec.c')
-rw-r--r-- | drivers/net/macsec.c | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 18cfb46c5911..0045108d7159 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c | |||
@@ -1270,22 +1270,22 @@ static struct crypto_aead *macsec_alloc_tfm(char *key, int key_len, int icv_len) | |||
1270 | int ret; | 1270 | int ret; |
1271 | 1271 | ||
1272 | tfm = crypto_alloc_aead("gcm(aes)", 0, 0); | 1272 | tfm = crypto_alloc_aead("gcm(aes)", 0, 0); |
1273 | if (!tfm || IS_ERR(tfm)) | 1273 | |
1274 | return NULL; | 1274 | if (IS_ERR(tfm)) |
1275 | return tfm; | ||
1275 | 1276 | ||
1276 | ret = crypto_aead_setkey(tfm, key, key_len); | 1277 | ret = crypto_aead_setkey(tfm, key, key_len); |
1277 | if (ret < 0) { | 1278 | if (ret < 0) |
1278 | crypto_free_aead(tfm); | 1279 | goto fail; |
1279 | return NULL; | ||
1280 | } | ||
1281 | 1280 | ||
1282 | ret = crypto_aead_setauthsize(tfm, icv_len); | 1281 | ret = crypto_aead_setauthsize(tfm, icv_len); |
1283 | if (ret < 0) { | 1282 | if (ret < 0) |
1284 | crypto_free_aead(tfm); | 1283 | goto fail; |
1285 | return NULL; | ||
1286 | } | ||
1287 | 1284 | ||
1288 | return tfm; | 1285 | return tfm; |
1286 | fail: | ||
1287 | crypto_free_aead(tfm); | ||
1288 | return ERR_PTR(ret); | ||
1289 | } | 1289 | } |
1290 | 1290 | ||
1291 | static int init_rx_sa(struct macsec_rx_sa *rx_sa, char *sak, int key_len, | 1291 | static int init_rx_sa(struct macsec_rx_sa *rx_sa, char *sak, int key_len, |
@@ -1293,12 +1293,12 @@ static int init_rx_sa(struct macsec_rx_sa *rx_sa, char *sak, int key_len, | |||
1293 | { | 1293 | { |
1294 | rx_sa->stats = alloc_percpu(struct macsec_rx_sa_stats); | 1294 | rx_sa->stats = alloc_percpu(struct macsec_rx_sa_stats); |
1295 | if (!rx_sa->stats) | 1295 | if (!rx_sa->stats) |
1296 | return -1; | 1296 | return -ENOMEM; |
1297 | 1297 | ||
1298 | rx_sa->key.tfm = macsec_alloc_tfm(sak, key_len, icv_len); | 1298 | rx_sa->key.tfm = macsec_alloc_tfm(sak, key_len, icv_len); |
1299 | if (!rx_sa->key.tfm) { | 1299 | if (IS_ERR(rx_sa->key.tfm)) { |
1300 | free_percpu(rx_sa->stats); | 1300 | free_percpu(rx_sa->stats); |
1301 | return -1; | 1301 | return PTR_ERR(rx_sa->key.tfm); |
1302 | } | 1302 | } |
1303 | 1303 | ||
1304 | rx_sa->active = false; | 1304 | rx_sa->active = false; |
@@ -1391,12 +1391,12 @@ static int init_tx_sa(struct macsec_tx_sa *tx_sa, char *sak, int key_len, | |||
1391 | { | 1391 | { |
1392 | tx_sa->stats = alloc_percpu(struct macsec_tx_sa_stats); | 1392 | tx_sa->stats = alloc_percpu(struct macsec_tx_sa_stats); |
1393 | if (!tx_sa->stats) | 1393 | if (!tx_sa->stats) |
1394 | return -1; | 1394 | return -ENOMEM; |
1395 | 1395 | ||
1396 | tx_sa->key.tfm = macsec_alloc_tfm(sak, key_len, icv_len); | 1396 | tx_sa->key.tfm = macsec_alloc_tfm(sak, key_len, icv_len); |
1397 | if (!tx_sa->key.tfm) { | 1397 | if (IS_ERR(tx_sa->key.tfm)) { |
1398 | free_percpu(tx_sa->stats); | 1398 | free_percpu(tx_sa->stats); |
1399 | return -1; | 1399 | return PTR_ERR(tx_sa->key.tfm); |
1400 | } | 1400 | } |
1401 | 1401 | ||
1402 | tx_sa->active = false; | 1402 | tx_sa->active = false; |
@@ -1629,6 +1629,7 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info) | |||
1629 | unsigned char assoc_num; | 1629 | unsigned char assoc_num; |
1630 | struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1]; | 1630 | struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1]; |
1631 | struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1]; | 1631 | struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1]; |
1632 | int err; | ||
1632 | 1633 | ||
1633 | if (!attrs[MACSEC_ATTR_IFINDEX]) | 1634 | if (!attrs[MACSEC_ATTR_IFINDEX]) |
1634 | return -EINVAL; | 1635 | return -EINVAL; |
@@ -1665,13 +1666,19 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info) | |||
1665 | } | 1666 | } |
1666 | 1667 | ||
1667 | rx_sa = kmalloc(sizeof(*rx_sa), GFP_KERNEL); | 1668 | rx_sa = kmalloc(sizeof(*rx_sa), GFP_KERNEL); |
1668 | if (!rx_sa || init_rx_sa(rx_sa, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]), | 1669 | if (!rx_sa) { |
1669 | secy->key_len, secy->icv_len)) { | ||
1670 | kfree(rx_sa); | ||
1671 | rtnl_unlock(); | 1670 | rtnl_unlock(); |
1672 | return -ENOMEM; | 1671 | return -ENOMEM; |
1673 | } | 1672 | } |
1674 | 1673 | ||
1674 | err = init_rx_sa(rx_sa, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]), | ||
1675 | secy->key_len, secy->icv_len); | ||
1676 | if (err < 0) { | ||
1677 | kfree(rx_sa); | ||
1678 | rtnl_unlock(); | ||
1679 | return err; | ||
1680 | } | ||
1681 | |||
1675 | if (tb_sa[MACSEC_SA_ATTR_PN]) { | 1682 | if (tb_sa[MACSEC_SA_ATTR_PN]) { |
1676 | spin_lock_bh(&rx_sa->lock); | 1683 | spin_lock_bh(&rx_sa->lock); |
1677 | rx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]); | 1684 | rx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]); |
@@ -1777,6 +1784,7 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info) | |||
1777 | struct macsec_tx_sa *tx_sa; | 1784 | struct macsec_tx_sa *tx_sa; |
1778 | unsigned char assoc_num; | 1785 | unsigned char assoc_num; |
1779 | struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1]; | 1786 | struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1]; |
1787 | int err; | ||
1780 | 1788 | ||
1781 | if (!attrs[MACSEC_ATTR_IFINDEX]) | 1789 | if (!attrs[MACSEC_ATTR_IFINDEX]) |
1782 | return -EINVAL; | 1790 | return -EINVAL; |
@@ -1813,13 +1821,19 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info) | |||
1813 | } | 1821 | } |
1814 | 1822 | ||
1815 | tx_sa = kmalloc(sizeof(*tx_sa), GFP_KERNEL); | 1823 | tx_sa = kmalloc(sizeof(*tx_sa), GFP_KERNEL); |
1816 | if (!tx_sa || init_tx_sa(tx_sa, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]), | 1824 | if (!tx_sa) { |
1817 | secy->key_len, secy->icv_len)) { | ||
1818 | kfree(tx_sa); | ||
1819 | rtnl_unlock(); | 1825 | rtnl_unlock(); |
1820 | return -ENOMEM; | 1826 | return -ENOMEM; |
1821 | } | 1827 | } |
1822 | 1828 | ||
1829 | err = init_tx_sa(tx_sa, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]), | ||
1830 | secy->key_len, secy->icv_len); | ||
1831 | if (err < 0) { | ||
1832 | kfree(tx_sa); | ||
1833 | rtnl_unlock(); | ||
1834 | return err; | ||
1835 | } | ||
1836 | |||
1823 | nla_memcpy(tx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN); | 1837 | nla_memcpy(tx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN); |
1824 | 1838 | ||
1825 | spin_lock_bh(&tx_sa->lock); | 1839 | spin_lock_bh(&tx_sa->lock); |