netfilter: nf_tables: fix memory leak during stateful obj update
authorFlorian Westphal <fw@strlen.de>
Mon, 21 Feb 2022 12:31:49 +0000 (13:31 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Mar 2022 10:47:59 +0000 (11:47 +0100)
commite96e204ee6fa46702f6c94c3c69a09e69e0eac52
tree6b7391ad97d05ca3227ea5389912ec311d7fbafc
parent7d258451d3454b168ba6df3c9e4cb26a8ce6b752
netfilter: nf_tables: fix memory leak during stateful obj update

commit dad3bdeef45f81a6e90204bcc85360bb76eccec7 upstream.

stateful objects can be updated from the control plane.
The transaction logic allocates a temporary object for this purpose.

The ->init function was called for this object, so plain kfree() leaks
resources. We must call ->destroy function of the object.

nft_obj_destroy does this, but it also decrements the module refcount,
but the update path doesn't increment it.

To avoid special-casing the update object release, do module_get for
the update case too and release it via nft_obj_destroy().

Fixes: d62d0ba97b58 ("netfilter: nf_tables: Introduce stateful object update operation")
Cc: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/netfilter/nf_tables_api.c