]> git.baikalelectronics.ru Git - kernel.git/commitdiff
netfilter: nft_quota: copy content when cloning expression
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 28 Feb 2023 19:43:02 +0000 (20:43 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Mar 2023 07:50:23 +0000 (08:50 +0100)
[ Upstream commit 56b8c484d417dd30a635cf6fa46d3063a68dbe0a ]

If the ruleset contains consumed quota, restore them accordingly.
Otherwise, listing after restoration shows never used items.

Restore the user-defined quota and flags too.

Fixes: 5da0d94e8605 ("netfilter: nft_quota: move stateful fields out of expression data")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nft_quota.c

index e6b0df68feeaf85640969c64cf8d80d84082a4ef..410a5fcf88309448d16aee89d1a50db661f9f9ba 100644 (file)
@@ -235,12 +235,16 @@ static void nft_quota_destroy(const struct nft_ctx *ctx,
 static int nft_quota_clone(struct nft_expr *dst, const struct nft_expr *src)
 {
        struct nft_quota *priv_dst = nft_expr_priv(dst);
+       struct nft_quota *priv_src = nft_expr_priv(src);
+
+       priv_dst->quota = priv_src->quota;
+       priv_dst->flags = priv_src->flags;
 
        priv_dst->consumed = kmalloc(sizeof(*priv_dst->consumed), GFP_ATOMIC);
        if (!priv_dst->consumed)
                return -ENOMEM;
 
-       atomic64_set(priv_dst->consumed, 0);
+       *priv_dst->consumed = *priv_src->consumed;
 
        return 0;
 }