netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netfilter: nf_tables: allow NFPROTO_INET in nft_(match/target)_validate()
@ 2024-02-09 12:19 Ignat Korchagin
  2024-02-09 12:38 ` Pablo Neira Ayuso
  2024-02-14 23:40 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 5+ messages in thread
From: Ignat Korchagin @ 2024-02-09 12:19 UTC (permalink / raw)
  To: pablo, kadlec, fw, netfilter-devel, coreteam
  Cc: kernel-team, jgriege, Ignat Korchagin

Commit 67ee37360d41 ("netfilter: nf_tables: validate NFPROTO_* family") added
some validation of NFPROTO_* families in nftables, but it broke our use case for
xt_bpf module:

  * assuming we have a simple bpf program:

    #include <linux/bpf.h>
    #include <bpf/bpf_helpers.h>

    char _license[] SEC("license") = "GPL";

    SEC("socket")
    int prog(struct __sk_buff *skb) { return BPF_OK; }

  * we can compile it and pin into bpf FS:
    bpftool prog load bpf.o /sys/fs/bpf/test

  * now we want to create a following table

    table inet firewall {
        chain input {
                type filter hook prerouting priority filter; policy accept;
                bpf pinned "/sys/fs/bpf/test" drop
        }
    }

All above used to work, but now we get EOPNOTSUPP, when creating the table.

Fix this by allowing NFPROTO_INET for nft_(match/target)_validate()

Fixes: 67ee37360d41 ("netfilter: nf_tables: validate NFPROTO_* family")
Reported-by: Jordan Griege <jgriege@cloudflare.com>
Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
---
 net/netfilter/nft_compat.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
index 1f9474fefe84..beea8c447e7a 100644
--- a/net/netfilter/nft_compat.c
+++ b/net/netfilter/nft_compat.c
@@ -359,6 +359,7 @@ static int nft_target_validate(const struct nft_ctx *ctx,
 
 	if (ctx->family != NFPROTO_IPV4 &&
 	    ctx->family != NFPROTO_IPV6 &&
+	    ctx->family != NFPROTO_INET &&
 	    ctx->family != NFPROTO_BRIDGE &&
 	    ctx->family != NFPROTO_ARP)
 		return -EOPNOTSUPP;
@@ -610,6 +611,7 @@ static int nft_match_validate(const struct nft_ctx *ctx,
 
 	if (ctx->family != NFPROTO_IPV4 &&
 	    ctx->family != NFPROTO_IPV6 &&
+	    ctx->family != NFPROTO_INET &&
 	    ctx->family != NFPROTO_BRIDGE &&
 	    ctx->family != NFPROTO_ARP)
 		return -EOPNOTSUPP;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-14 23:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-09 12:19 [PATCH] netfilter: nf_tables: allow NFPROTO_INET in nft_(match/target)_validate() Ignat Korchagin
2024-02-09 12:38 ` Pablo Neira Ayuso
2024-02-09 15:03   ` Ignat Korchagin
2024-02-12 12:52     ` Jordan Griege
2024-02-14 23:40 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).