macsec: fix SA leak if initialization fails
authorSabrina Dubroca <sd@queasysnail.net>
Fri, 22 Apr 2016 09:28:07 +0000 (11:28 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 24 Apr 2016 18:31:58 +0000 (14:31 -0400)
Fixes: c09440f7dcb3 ("macsec: introduce IEEE 802.1AE driver")
Reported-by: Lance Richardson <lrichard@redhat.com>
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/macsec.c

index 826c6c9ce7fd4585055843b7a882afe1a2c08537..b37d348b8ea0b99c3227d558e9cf846c03e6e9c2 100644 (file)
@@ -1627,6 +1627,7 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
        rx_sa = kmalloc(sizeof(*rx_sa), GFP_KERNEL);
        if (!rx_sa || init_rx_sa(rx_sa, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]),
                                 secy->key_len, secy->icv_len)) {
+               kfree(rx_sa);
                rtnl_unlock();
                return -ENOMEM;
        }
@@ -1771,6 +1772,7 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info)
        tx_sa = kmalloc(sizeof(*tx_sa), GFP_KERNEL);
        if (!tx_sa || init_tx_sa(tx_sa, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]),
                                 secy->key_len, secy->icv_len)) {
+               kfree(tx_sa);
                rtnl_unlock();
                return -ENOMEM;
        }