Skip to content

Commit d0009ef

Browse files
committed
netfilter: nf_tables: validate NFPROTO_* family
Several expressions explicitly refer to NF_INET_* hook definitions from expr->ops->validate, however, family is not validated. Bail out with EOPNOTSUPP in case they are used from unsupported families. Fixes: 0ca743a ("netfilter: nf_tables: add compatibility layer for x_tables") Fixes: a3c90f7 ("netfilter: nf_tables: flow offload expression") Fixes: 2fa8419 ("netfilter: nf_tables: introduce routing expression") Fixes: 554ced0 ("netfilter: nf_tables: add support for native socket matching") Fixes: ad49d86 ("netfilter: nf_tables: Add synproxy support") Fixes: 4ed8eb6 ("netfilter: nf_tables: Add native tproxy support") Fixes: 6c47260 ("netfilter: nf_tables: add xfrm expression") Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent f342de4 commit d0009ef

File tree

8 files changed

+47
-2
lines changed

8 files changed

+47
-2
lines changed

net/netfilter/nft_compat.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ static int nft_target_validate(const struct nft_ctx *ctx,
350350
unsigned int hook_mask = 0;
351351
int ret;
352352

353+
if (ctx->family != NFPROTO_IPV4 &&
354+
ctx->family != NFPROTO_IPV6 &&
355+
ctx->family != NFPROTO_BRIDGE &&
356+
ctx->family != NFPROTO_ARP)
357+
return -EOPNOTSUPP;
358+
353359
if (nft_is_base_chain(ctx->chain)) {
354360
const struct nft_base_chain *basechain =
355361
nft_base_chain(ctx->chain);
@@ -595,6 +601,12 @@ static int nft_match_validate(const struct nft_ctx *ctx,
595601
unsigned int hook_mask = 0;
596602
int ret;
597603

604+
if (ctx->family != NFPROTO_IPV4 &&
605+
ctx->family != NFPROTO_IPV6 &&
606+
ctx->family != NFPROTO_BRIDGE &&
607+
ctx->family != NFPROTO_ARP)
608+
return -EOPNOTSUPP;
609+
598610
if (nft_is_base_chain(ctx->chain)) {
599611
const struct nft_base_chain *basechain =
600612
nft_base_chain(ctx->chain);

net/netfilter/nft_flow_offload.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ static int nft_flow_offload_validate(const struct nft_ctx *ctx,
384384
{
385385
unsigned int hook_mask = (1 << NF_INET_FORWARD);
386386

387+
if (ctx->family != NFPROTO_IPV4 &&
388+
ctx->family != NFPROTO_IPV6 &&
389+
ctx->family != NFPROTO_INET)
390+
return -EOPNOTSUPP;
391+
387392
return nft_chain_validate_hooks(ctx->chain, hook_mask);
388393
}
389394

net/netfilter/nft_nat.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ static int nft_nat_validate(const struct nft_ctx *ctx,
143143
struct nft_nat *priv = nft_expr_priv(expr);
144144
int err;
145145

146+
if (ctx->family != NFPROTO_IPV4 &&
147+
ctx->family != NFPROTO_IPV6 &&
148+
ctx->family != NFPROTO_INET)
149+
return -EOPNOTSUPP;
150+
146151
err = nft_chain_validate_dependency(ctx->chain, NFT_CHAIN_T_NAT);
147152
if (err < 0)
148153
return err;

net/netfilter/nft_rt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ static int nft_rt_validate(const struct nft_ctx *ctx, const struct nft_expr *exp
166166
const struct nft_rt *priv = nft_expr_priv(expr);
167167
unsigned int hooks;
168168

169+
if (ctx->family != NFPROTO_IPV4 &&
170+
ctx->family != NFPROTO_IPV6 &&
171+
ctx->family != NFPROTO_INET)
172+
return -EOPNOTSUPP;
173+
169174
switch (priv->key) {
170175
case NFT_RT_NEXTHOP4:
171176
case NFT_RT_NEXTHOP6:

net/netfilter/nft_socket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ static int nft_socket_validate(const struct nft_ctx *ctx,
242242
const struct nft_expr *expr,
243243
const struct nft_data **data)
244244
{
245+
if (ctx->family != NFPROTO_IPV4 &&
246+
ctx->family != NFPROTO_IPV6 &&
247+
ctx->family != NFPROTO_INET)
248+
return -EOPNOTSUPP;
249+
245250
return nft_chain_validate_hooks(ctx->chain,
246251
(1 << NF_INET_PRE_ROUTING) |
247252
(1 << NF_INET_LOCAL_IN) |

net/netfilter/nft_synproxy.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ static int nft_synproxy_do_init(const struct nft_ctx *ctx,
186186
break;
187187
#endif
188188
case NFPROTO_INET:
189-
case NFPROTO_BRIDGE:
190189
err = nf_synproxy_ipv4_init(snet, ctx->net);
191190
if (err)
192191
goto nf_ct_failure;
@@ -219,7 +218,6 @@ static void nft_synproxy_do_destroy(const struct nft_ctx *ctx)
219218
break;
220219
#endif
221220
case NFPROTO_INET:
222-
case NFPROTO_BRIDGE:
223221
nf_synproxy_ipv4_fini(snet, ctx->net);
224222
nf_synproxy_ipv6_fini(snet, ctx->net);
225223
break;
@@ -253,6 +251,11 @@ static int nft_synproxy_validate(const struct nft_ctx *ctx,
253251
const struct nft_expr *expr,
254252
const struct nft_data **data)
255253
{
254+
if (ctx->family != NFPROTO_IPV4 &&
255+
ctx->family != NFPROTO_IPV6 &&
256+
ctx->family != NFPROTO_INET)
257+
return -EOPNOTSUPP;
258+
256259
return nft_chain_validate_hooks(ctx->chain, (1 << NF_INET_LOCAL_IN) |
257260
(1 << NF_INET_FORWARD));
258261
}

net/netfilter/nft_tproxy.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ static int nft_tproxy_validate(const struct nft_ctx *ctx,
316316
const struct nft_expr *expr,
317317
const struct nft_data **data)
318318
{
319+
if (ctx->family != NFPROTO_IPV4 &&
320+
ctx->family != NFPROTO_IPV6 &&
321+
ctx->family != NFPROTO_INET)
322+
return -EOPNOTSUPP;
323+
319324
return nft_chain_validate_hooks(ctx->chain, 1 << NF_INET_PRE_ROUTING);
320325
}
321326

net/netfilter/nft_xfrm.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ static int nft_xfrm_validate(const struct nft_ctx *ctx, const struct nft_expr *e
235235
const struct nft_xfrm *priv = nft_expr_priv(expr);
236236
unsigned int hooks;
237237

238+
if (ctx->family != NFPROTO_IPV4 &&
239+
ctx->family != NFPROTO_IPV6 &&
240+
ctx->family != NFPROTO_INET)
241+
return -EOPNOTSUPP;
242+
238243
switch (priv->dir) {
239244
case XFRM_POLICY_IN:
240245
hooks = (1 << NF_INET_FORWARD) |

0 commit comments

Comments
 (0)