Skip to content

Commit 91a139c

Browse files
committed
netfilter: nft_limit: do not ignore unsupported flags
Bail out if userspace provides unsupported flags, otherwise future extensions to the limit expression will be silently ignored by the kernel. Fixes: c7862a5 ("netfilter: nft_limit: allow to invert matching criteria") Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 3c13725 commit 91a139c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

net/netfilter/nft_limit.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static inline bool nft_limit_eval(struct nft_limit_priv *priv, u64 cost)
5858
static int nft_limit_init(struct nft_limit_priv *priv,
5959
const struct nlattr * const tb[], bool pkts)
6060
{
61+
bool invert = false;
6162
u64 unit, tokens;
6263

6364
if (tb[NFTA_LIMIT_RATE] == NULL ||
@@ -90,19 +91,23 @@ static int nft_limit_init(struct nft_limit_priv *priv,
9091
priv->rate);
9192
}
9293

94+
if (tb[NFTA_LIMIT_FLAGS]) {
95+
u32 flags = ntohl(nla_get_be32(tb[NFTA_LIMIT_FLAGS]));
96+
97+
if (flags & ~NFT_LIMIT_F_INV)
98+
return -EOPNOTSUPP;
99+
100+
if (flags & NFT_LIMIT_F_INV)
101+
invert = true;
102+
}
103+
93104
priv->limit = kmalloc(sizeof(*priv->limit), GFP_KERNEL_ACCOUNT);
94105
if (!priv->limit)
95106
return -ENOMEM;
96107

97108
priv->limit->tokens = tokens;
98109
priv->tokens_max = priv->limit->tokens;
99-
100-
if (tb[NFTA_LIMIT_FLAGS]) {
101-
u32 flags = ntohl(nla_get_be32(tb[NFTA_LIMIT_FLAGS]));
102-
103-
if (flags & NFT_LIMIT_F_INV)
104-
priv->invert = true;
105-
}
110+
priv->invert = invert;
106111
priv->limit->last = ktime_get_ns();
107112
spin_lock_init(&priv->limit->lock);
108113

0 commit comments

Comments
 (0)