Skip to content

Commit

Permalink
net: macsec: fix potential resource leak in macsec_add_rxsa() and mac…
Browse files Browse the repository at this point in the history
…sec_add_txsa()

[ Upstream commit c7b205f ]

init_rx_sa() allocates relevant resource for rx_sa->stats and rx_sa->
key.tfm with alloc_percpu() and macsec_alloc_tfm(). When some error
occurs after init_rx_sa() is called in macsec_add_rxsa(), the function
released rx_sa with kfree() without releasing rx_sa->stats and rx_sa->
key.tfm, which will lead to a resource leak.

We should call macsec_rxsa_put() instead of kfree() to decrease the ref
count of rx_sa and release the relevant resource if the refcount is 0.
The same bug exists in macsec_add_txsa() for tx_sa as well. This patch
fixes the above two bugs.

Fixes: 3cf3227 ("net: macsec: hardware offloading infrastructure")
Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Jianglei Nie authored and gregkh committed Aug 3, 2022
1 parent 96fd73f commit 03a344d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/net/macsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
return 0;

cleanup:
kfree(rx_sa);
macsec_rxsa_put(rx_sa);
rtnl_unlock();
return err;
}
Expand Down Expand Up @@ -2087,7 +2087,7 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info)

cleanup:
secy->operational = was_operational;
kfree(tx_sa);
macsec_txsa_put(tx_sa);
rtnl_unlock();
return err;
}
Expand Down

0 comments on commit 03a344d

Please sign in to comment.