From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Theodor Arsenij Larionov-Trichkine <theodorlarionov@gmail.com>
Cc: Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org
Subject: Re: [PATCH nf] netfilter: nft_fib: reject fib expression on the netdev egress hook
Date: Thu, 25 Jun 2026 22:11:01 +0200 [thread overview]
Message-ID: <aj2LVX4rz4C_Z9DJ@chamomile> (raw)
In-Reply-To: <20260625122834.204088-1-theodorlarionov@gmail.com>
Hi,
Comments below.
On Thu, Jun 25, 2026 at 03:28:34PM +0300, Theodor Arsenij Larionov-Trichkine wrote:
> A fib expression in a netdev egress base chain dereferences the input
> device nft_in(pkt), which is NULL on the transmit path, causing a
> NULL-ptr-deref at eval. nft_fib_validate() gates the chain hook with
> NF_INET_* masks, but a netdev chain's hook numbers come from a separate
> enum that aliases them (NF_NETDEV_EGRESS == NF_INET_LOCAL_IN == 1), so a
> netdev egress chain passes validation and then faults. Add a dedicated
> nft_fib_netdev_validate() restricting the netdev fib expression to
> NF_NETDEV_INGRESS, the only netdev hook with an input device, and
> restrict nft_fib_validate() to NFPROTO_IPV4/IPV6/INET so its NF_INET_*
> hook masks are never applied to another family's hook numbering.
>
> Fixes: 42df6e1d221d ("netfilter: Introduce egress hook")
> Link: https://lore.kernel.org/netfilter-devel/ajxsjcDOnwllMfoR@strlen.de/
> Signed-off-by: Theodor Arsenij Larionov-Trichkine <theodorlarionov@gmail.com>
> ---
> net/netfilter/nft_fib.c | 9 +++++++++
> net/netfilter/nft_fib_netdev.c | 8 +++++++-
> 2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/net/netfilter/nft_fib.c b/net/netfilter/nft_fib.c
> index e048f05694cd..89555380f1c5 100644
> --- a/net/netfilter/nft_fib.c
> +++ b/net/netfilter/nft_fib.c
> @@ -31,6 +31,15 @@ int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr)
> const struct nft_fib *priv = nft_expr_priv(expr);
> unsigned int hooks;
>
> + switch (ctx->family) {
> + case NFPROTO_IPV4:
> + case NFPROTO_IPV6:
> + case NFPROTO_INET:
> + break;
> + default:
> + return -EOPNOTSUPP;
> + }
> +
> switch (priv->result) {
> case NFT_FIB_RESULT_OIF:
> case NFT_FIB_RESULT_OIFNAME:
> diff --git a/net/netfilter/nft_fib_netdev.c b/net/netfilter/nft_fib_netdev.c
> index 3f3478abd845..c855c5dccd41 100644
> --- a/net/netfilter/nft_fib_netdev.c
> +++ b/net/netfilter/nft_fib_netdev.c
> @@ -50,6 +50,12 @@ static void nft_fib_netdev_eval(const struct nft_expr *expr,
> regs->verdict.code = NFT_BREAK;
> }
>
> +static int nft_fib_netdev_validate(const struct nft_ctx *ctx,
> + const struct nft_expr *expr)
> +{
Maybe this is missing:
switch (priv->result) {
case NFT_FIB_RESULT_OIF:
case NFT_FIB_RESULT_OIFNAME:
hooks = (1 << NF_NETDEV_INGRESS);
break;
case NFT_FIB_RESULT_ADDRTYPE:
if (priv->flags & NFTA_FIB_F_IIF)
hooks = (1 << NF_NETDEV_INGRESS);
else if (priv->flags & NFTA_FIB_F_OIF)
hooks = (1 << NF_NETDEV_EGRESS);
else
hooks = (1 << NF_NETDEV_INGRESS) |
(1 << NF_NETDEV_EGRESS);
break;
default:
return -EINVAL;
}
> + return nft_chain_validate_hooks(ctx->chain, 1 << NF_NETDEV_INGRESS);
> +}
> +
> static struct nft_expr_type nft_fib_netdev_type;
> static const struct nft_expr_ops nft_fib_netdev_ops = {
> .type = &nft_fib_netdev_type,
> @@ -57,7 +63,7 @@ static const struct nft_expr_ops nft_fib_netdev_ops = {
> .eval = nft_fib_netdev_eval,
> .init = nft_fib_init,
> .dump = nft_fib_dump,
> - .validate = nft_fib_validate,
> + .validate = nft_fib_netdev_validate,
> };
>
> static struct nft_expr_type nft_fib_netdev_type __read_mostly = {
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-06-25 20:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 19:04 [BUG] netfilter: nft_fib: NULL-ptr-deref (GPF) in nft_fib6_eval on netdev egress hook Theodor Arsenij Larionov-Trichkine
2026-06-24 20:19 ` Florian Westphal
2026-06-24 22:23 ` Pablo Neira Ayuso
2026-06-24 23:47 ` Florian Westphal
2026-06-25 12:28 ` [PATCH nf] netfilter: nft_fib: reject fib expression on the " Theodor Arsenij Larionov-Trichkine
2026-06-25 20:11 ` Pablo Neira Ayuso [this message]
2026-06-29 10:53 ` [PATCH nf v2] " Theodor Arsenij Larionov-Trichkine
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=aj2LVX4rz4C_Z9DJ@chamomile \
--to=pablo@netfilter.org \
--cc=coreteam@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=phil@nwl.cc \
--cc=theodorlarionov@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox