netfilter: nft_limit: reject configs whose per-packet cost can overflow
Subsystems (2)
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.
--- net/netfilter/nft_limit.c | 4 ++++ 1 file changed, 4 insertions(+)
net/netfilter/nft_limit.c +4 -0
@@ -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
Quoted 10 lines · SaifAllah benMassaoud
Byte-rate limits using long time units (e.g. bytes/week) can overflow
priv->nsecs*skb->lenin 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")Signed-off-by SaifAllah benMassaoud <[email protected]>
Thanks!
Quoted 28 lines
--- net/netfilter/nft_limit.c | 4 ++++ 1 file changed, 4 insertions(+)net/netfilter/nft_limit.c +4
-0@@ -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