Skip to contentSkip to conversation

netfilter: nft_limit: reject configs whose per-packet cost can overflow

PATCH In review SaifAllah benMassaoud 2 participants 2 messages Oct 24 – Oct 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 netfilter: nft_limit: reject configs whose per-packet cost can overflow

Byte-rate limits using long time units (e.g. bytes/week) can overflow priv->nsecs * skb->len in the packet-path cost calculation, silently defeating the configured rate limit.

Reject such configurations at rule-add time instead, using the GRO maximum packet size as a conservative bound on skb length for the multiplication check.

Fixes d2168e849ebf ("netfilter: nft_limit: add per-byte limiting")
---
 net/netfilter/nft_limit.c | 4 ++++
 1 file changed, 4 insertions(+)
net/netfilter/nft_limit.c +4 -0
index 167d99b1447f..07dc5c55b0a0 100644
@@ -13,6 +13,7 @@
 #include <linux/netfilter.h>
 #include <linux/netfilter/nf_tables.h>
 #include <net/netfilter/nf_tables.h>
+#include <linux/netdevice.h>
 
 struct nft_limit {
 	spinlock_t	lock;
@@ -73,6 +74,9 @@ static int nft_limit_init(struct nft_limit_priv *priv,
 	if (check_mul_overflow(unit, NSEC_PER_SEC, &priv->nsecs))
 		return -EOVERFLOW;
 
+	if (!pkts && priv->nsecs > U64_MAX / GRO_MAX_SIZE)
+		return -EOVERFLOW;
+
 	if (tb[NFTA_LIMIT_BURST])
 		priv->burst = ntohl(nla_get_be32(tb[NFTA_LIMIT_BURST]));
 

base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b

Signature · 1 line
2.53.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 10 lines · SaifAllah benMassaoud

Byte-rate limits using long time units (e.g. bytes/week) can overflow priv->nsecs * skb->len in the packet-path cost calculation, silently defeating the configured rate limit.

Reject such configurations at rule-add time instead, using the GRO maximum packet size as a conservative bound on skb length for the multiplication check.

Fixes d2168e849ebf ("netfilter: nft_limit: add per-byte limiting")

Thanks!

Quoted 28 lines
---
  net/netfilter/nft_limit.c | 4 ++++
  1 file changed, 4 insertions(+)
net/netfilter/nft_limit.c +4 -0
index 167d99b1447f..07dc5c55b0a0 100644
@@ -13,6 +13,7 @@
  #include <linux/netfilter.h>
  #include <linux/netfilter/nf_tables.h>
  #include <net/netfilter/nf_tables.h>
+#include <linux/netdevice.h>
 
  struct nft_limit {
  	spinlock_t	lock;
@@ -73,6 +74,9 @@ static int nft_limit_init(struct nft_limit_priv *priv,
  	if (check_mul_overflow(unit, NSEC_PER_SEC, &priv->nsecs))
  		return -EOVERFLOW;
 
+	if (!pkts && priv->nsecs > U64_MAX / GRO_MAX_SIZE)
+		return -EOVERFLOW;
+
  	if (tb[NFTA_LIMIT_BURST])
  		priv->burst = ntohl(nla_get_be32(tb[NFTA_LIMIT_BURST]));
 

base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b