]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
net: macsec: fix potential resource leak in macsec_add_rxsa() and macsec_add_txsa()
authorJianglei Nie <niejianglei2021@163.com>
Fri, 22 Jul 2022 09:29:02 +0000 (17:29 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 16 Sep 2022 08:53:44 +0000 (10:53 +0200)
commitee90aab29dccac00ed491e5091cd3a62b133830e
tree98af2da35e0fae74f8ab61d19ccc5d511f8c626a
parent76208d8a36a8967d07b925cf4678128650cd1d15
net: macsec: fix potential resource leak in macsec_add_rxsa() and macsec_add_txsa()

BugLink: https://bugs.launchpad.net/bugs/1989218
[ Upstream commit c7b205fbbf3cffa374721bb7623f7aa8c46074f1 ]

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: 3cf3227a21d1 ("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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/net/macsec.c