Skip to content

Commit 47f4f51

Browse files
author
Florian Westphal
committed
netfilter: nft_queue: only allow supported familes and hooks
Trying to use 'queue' statement in ingress (for example) triggers a splat on reinject: WARNING: CPU: 3 PID: 1345 at net/netfilter/nf_queue.c:291 ... because nf_reinject cannot find the ruleset head. The netdev family doesn't support async resume at the moment anyway, so disallow loading such rulesets with a more appropriate error message. v2: add 'validate' callback and also check hook points, v1 did allow ingress use in 'table inet', but that doesn't work either. (Pablo) Signed-off-by: Florian Westphal <fw@strlen.de> Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 81ea010 commit 47f4f51

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

net/netfilter/nft_queue.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,31 @@ static void nft_queue_sreg_eval(const struct nft_expr *expr,
6868
regs->verdict.code = ret;
6969
}
7070

71+
static int nft_queue_validate(const struct nft_ctx *ctx,
72+
const struct nft_expr *expr,
73+
const struct nft_data **data)
74+
{
75+
static const unsigned int supported_hooks = ((1 << NF_INET_PRE_ROUTING) |
76+
(1 << NF_INET_LOCAL_IN) |
77+
(1 << NF_INET_FORWARD) |
78+
(1 << NF_INET_LOCAL_OUT) |
79+
(1 << NF_INET_POST_ROUTING));
80+
81+
switch (ctx->family) {
82+
case NFPROTO_IPV4:
83+
case NFPROTO_IPV6:
84+
case NFPROTO_INET:
85+
case NFPROTO_BRIDGE:
86+
break;
87+
case NFPROTO_NETDEV: /* lacks okfn */
88+
fallthrough;
89+
default:
90+
return -EOPNOTSUPP;
91+
}
92+
93+
return nft_chain_validate_hooks(ctx->chain, supported_hooks);
94+
}
95+
7196
static const struct nla_policy nft_queue_policy[NFTA_QUEUE_MAX + 1] = {
7297
[NFTA_QUEUE_NUM] = { .type = NLA_U16 },
7398
[NFTA_QUEUE_TOTAL] = { .type = NLA_U16 },
@@ -164,6 +189,7 @@ static const struct nft_expr_ops nft_queue_ops = {
164189
.eval = nft_queue_eval,
165190
.init = nft_queue_init,
166191
.dump = nft_queue_dump,
192+
.validate = nft_queue_validate,
167193
.reduce = NFT_REDUCE_READONLY,
168194
};
169195

@@ -173,6 +199,7 @@ static const struct nft_expr_ops nft_queue_sreg_ops = {
173199
.eval = nft_queue_sreg_eval,
174200
.init = nft_queue_sreg_init,
175201
.dump = nft_queue_sreg_dump,
202+
.validate = nft_queue_validate,
176203
.reduce = NFT_REDUCE_READONLY,
177204
};
178205

0 commit comments

Comments
 (0)