Skip to content

Commit 7e0f122

Browse files
ignatkummakynes
authored andcommitted
netfilter: nf_tables: allow NFPROTO_INET in nft_(match/target)_validate()
Commit d0009ef ("netfilter: nf_tables: validate NFPROTO_* family") added some validation of NFPROTO_* families in the nft_compat module, but it broke the ability to use legacy iptables modules in dual-stack nftables. While with legacy iptables one had to independently manage IPv4 and IPv6 tables, with nftables it is possible to have dual-stack tables sharing the rules. Moreover, it was possible to use rules based on legacy iptables match/target modules in dual-stack nftables. As an example, the program from [2] creates an INET dual-stack family table using an xt_bpf based rule, which looks like the following (the actual output was generated with a patched nft tool as the current nft tool does not parse dual stack tables with legacy match rules, so consider it for illustrative purposes only): table inet testfw { chain input { type filter hook prerouting priority filter; policy accept; bytecode counter packets 0 bytes 0 accept } } After d0009ef ("netfilter: nf_tables: validate NFPROTO_* family") we get EOPNOTSUPP for the above program. Fix this by allowing NFPROTO_INET for nft_(match/target)_validate(), but also restrict the functions to classic iptables hooks. Changes in v3: * clarify that upstream nft will not display such configuration properly and that the output was generated with a patched nft tool * remove example program from commit description and link to it instead * no code changes otherwise Changes in v2: * restrict nft_(match/target)_validate() to classic iptables hooks * rewrite example program to use unmodified libnftnl Fixes: d0009ef ("netfilter: nf_tables: validate NFPROTO_* family") Link: https://lore.kernel.org/all/Zc1PfoWN38UuFJRI@calendula/T/#mc947262582c90fec044c7a3398cc92fac7afea72 [1] Link: https://lore.kernel.org/all/20240220145509.53357-1-ignat@cloudflare.com/ [2] Reported-by: Jordan Griege <jgriege@cloudflare.com> Signed-off-by: Ignat Korchagin <ignat@cloudflare.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 359e54a commit 7e0f122

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

net/netfilter/nft_compat.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,20 @@ static int nft_target_validate(const struct nft_ctx *ctx,
359359

360360
if (ctx->family != NFPROTO_IPV4 &&
361361
ctx->family != NFPROTO_IPV6 &&
362+
ctx->family != NFPROTO_INET &&
362363
ctx->family != NFPROTO_BRIDGE &&
363364
ctx->family != NFPROTO_ARP)
364365
return -EOPNOTSUPP;
365366

367+
ret = nft_chain_validate_hooks(ctx->chain,
368+
(1 << NF_INET_PRE_ROUTING) |
369+
(1 << NF_INET_LOCAL_IN) |
370+
(1 << NF_INET_FORWARD) |
371+
(1 << NF_INET_LOCAL_OUT) |
372+
(1 << NF_INET_POST_ROUTING));
373+
if (ret)
374+
return ret;
375+
366376
if (nft_is_base_chain(ctx->chain)) {
367377
const struct nft_base_chain *basechain =
368378
nft_base_chain(ctx->chain);
@@ -610,10 +620,20 @@ static int nft_match_validate(const struct nft_ctx *ctx,
610620

611621
if (ctx->family != NFPROTO_IPV4 &&
612622
ctx->family != NFPROTO_IPV6 &&
623+
ctx->family != NFPROTO_INET &&
613624
ctx->family != NFPROTO_BRIDGE &&
614625
ctx->family != NFPROTO_ARP)
615626
return -EOPNOTSUPP;
616627

628+
ret = nft_chain_validate_hooks(ctx->chain,
629+
(1 << NF_INET_PRE_ROUTING) |
630+
(1 << NF_INET_LOCAL_IN) |
631+
(1 << NF_INET_FORWARD) |
632+
(1 << NF_INET_LOCAL_OUT) |
633+
(1 << NF_INET_POST_ROUTING));
634+
if (ret)
635+
return ret;
636+
617637
if (nft_is_base_chain(ctx->chain)) {
618638
const struct nft_base_chain *basechain =
619639
nft_base_chain(ctx->chain);

0 commit comments

Comments
 (0)