All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nf] netfilter: nft_queue: only allow supported families
Date: Tue, 26 Jul 2022 12:43:48 +0200	[thread overview]
Message-ID: <20220726104348.2125-1-fw@strlen.de> (raw)

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, so all
"reinject" attempts result in packet drop.

Ingress/egress do not support async resume at the moment anyway,
so disallow loading such rulesets with a more appropriate error
message.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/netfilter/nft_queue.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/net/netfilter/nft_queue.c b/net/netfilter/nft_queue.c
index 15e4b7640dc0..cb54a0a4b424 100644
--- a/net/netfilter/nft_queue.c
+++ b/net/netfilter/nft_queue.c
@@ -75,6 +75,24 @@ static const struct nla_policy nft_queue_policy[NFTA_QUEUE_MAX + 1] = {
 	[NFTA_QUEUE_SREG_QNUM]	= { .type = NLA_U32 },
 };
 
+static bool nft_queue_family_supported(const struct nft_ctx *ctx)
+{
+	switch (ctx->family) {
+	case NFPROTO_IPV4:
+	case NFPROTO_IPV6:
+	case NFPROTO_INET:
+	case NFPROTO_BRIDGE:
+		return true;
+	case NFPROTO_ARP:
+	case NFPROTO_DECNET:
+	case NFPROTO_NETDEV:
+	default:
+		break;
+	}
+
+	return false;
+}
+
 static int nft_queue_init(const struct nft_ctx *ctx,
 			  const struct nft_expr *expr,
 			  const struct nlattr * const tb[])
@@ -82,6 +100,9 @@ static int nft_queue_init(const struct nft_ctx *ctx,
 	struct nft_queue *priv = nft_expr_priv(expr);
 	u32 maxid;
 
+	if (!nft_queue_family_supported(ctx))
+		return -EOPNOTSUPP;
+
 	priv->queuenum = ntohs(nla_get_be16(tb[NFTA_QUEUE_NUM]));
 
 	if (tb[NFTA_QUEUE_TOTAL])
@@ -111,6 +132,9 @@ static int nft_queue_sreg_init(const struct nft_ctx *ctx,
 	struct nft_queue *priv = nft_expr_priv(expr);
 	int err;
 
+	if (!nft_queue_family_supported(ctx))
+		return -EOPNOTSUPP;
+
 	err = nft_parse_register_load(tb[NFTA_QUEUE_SREG_QNUM],
 				      &priv->sreg_qnum, sizeof(u32));
 	if (err < 0)
-- 
2.35.1


             reply	other threads:[~2022-07-26 10:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 10:43 Florian Westphal [this message]
2022-07-26 13:29 ` [PATCH nf] netfilter: nft_queue: only allow supported families Pablo Neira Ayuso
2022-07-26 17:50   ` Florian Westphal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220726104348.2125-1-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.