* [PATCH nf-next v2] netfilter: nft_quota: match correctly when the quota just depleted
@ 2025-04-17 15:49 Zhongqiu Duan
2025-05-05 11:16 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: Zhongqiu Duan @ 2025-04-17 15:49 UTC (permalink / raw)
To: coreteam, netfilter-devel
Cc: Zhongqiu Duan, Pablo Neira Ayuso, Jozsef Kadlecsik,
Florian Westphal, Simon Horman
The xt_quota compares skb length with remaining quota, but the nft_quota
compares it with consumed bytes.
The xt_quota can match consumed bytes up to quota at maximum. But the
nft_quota break match when consumed bytes equal to quota.
i.e., nft_quota match consumed bytes in [0, quota - 1], not [0, quota].
Fixes: 795595f68d6c ("netfilter: nft_quota: dump consumed quota")
Signed-off-by: Zhongqiu Duan <dzq.aishenghu0@gmail.com>
---
v2:
- Keeps the behavior of notified on the quota just exhausted.
- Convert to a more descriptive title.
v1: https://lore.kernel.org/netfilter-devel/20250410071748.248027-1-dzq.aishenghu0@gmail.com/
net/netfilter/nft_quota.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/net/netfilter/nft_quota.c b/net/netfilter/nft_quota.c
index 9b2d7463d3d3..df0798da2329 100644
--- a/net/netfilter/nft_quota.c
+++ b/net/netfilter/nft_quota.c
@@ -19,10 +19,16 @@ struct nft_quota {
};
static inline bool nft_overquota(struct nft_quota *priv,
- const struct sk_buff *skb)
+ const struct sk_buff *skb,
+ bool *report)
{
- return atomic64_add_return(skb->len, priv->consumed) >=
- atomic64_read(&priv->quota);
+ u64 consumed = atomic64_add_return(skb->len, priv->consumed);
+ u64 quota = atomic64_read(&priv->quota);
+
+ if (report)
+ *report = consumed >= quota;
+
+ return consumed > quota;
}
static inline bool nft_quota_invert(struct nft_quota *priv)
@@ -34,7 +40,7 @@ static inline void nft_quota_do_eval(struct nft_quota *priv,
struct nft_regs *regs,
const struct nft_pktinfo *pkt)
{
- if (nft_overquota(priv, pkt->skb) ^ nft_quota_invert(priv))
+ if (nft_overquota(priv, pkt->skb, NULL) ^ nft_quota_invert(priv))
regs->verdict.code = NFT_BREAK;
}
@@ -51,13 +57,13 @@ static void nft_quota_obj_eval(struct nft_object *obj,
const struct nft_pktinfo *pkt)
{
struct nft_quota *priv = nft_obj_data(obj);
- bool overquota;
+ bool overquota, report;
- overquota = nft_overquota(priv, pkt->skb);
+ overquota = nft_overquota(priv, pkt->skb, &report);
if (overquota ^ nft_quota_invert(priv))
regs->verdict.code = NFT_BREAK;
- if (overquota &&
+ if (report &&
!test_and_set_bit(NFT_QUOTA_DEPLETED_BIT, &priv->flags))
nft_obj_notify(nft_net(pkt), obj->key.table, obj, 0, 0,
NFT_MSG_NEWOBJ, 0, nft_pf(pkt), 0, GFP_ATOMIC);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH nf-next v2] netfilter: nft_quota: match correctly when the quota just depleted
2025-04-17 15:49 [PATCH nf-next v2] netfilter: nft_quota: match correctly when the quota just depleted Zhongqiu Duan
@ 2025-05-05 11:16 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2025-05-05 11:16 UTC (permalink / raw)
To: Zhongqiu Duan
Cc: coreteam, netfilter-devel, Jozsef Kadlecsik, Florian Westphal,
Simon Horman
On Thu, Apr 17, 2025 at 03:49:30PM +0000, Zhongqiu Duan wrote:
> The xt_quota compares skb length with remaining quota, but the nft_quota
> compares it with consumed bytes.
>
> The xt_quota can match consumed bytes up to quota at maximum. But the
> nft_quota break match when consumed bytes equal to quota.
>
> i.e., nft_quota match consumed bytes in [0, quota - 1], not [0, quota].
Yes, quota is off by one.
Applied to nf-next, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-05-05 11:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17 15:49 [PATCH nf-next v2] netfilter: nft_quota: match correctly when the quota just depleted Zhongqiu Duan
2025-05-05 11:16 ` Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.