Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793215475; b=IbCMtsgQCxqOrnGSoCCnCjjl38aOVCTegq4ivEqGdtT92Joc5Mz5jLmL3FlN04zRzono ZFjPndNAT1/Fwi2st7c5FdQMK03SU5penavhIi0G1mg+pdfRU1AXW+f+NWvq6ZR0bG8CS Cu+2BNabTOa/qors2UqGWsxc5aZoO8rWVB0ZJabIEWrZRurrdcmwepY7c3EIChqjaqeOw DKy7BfSDoWHOhZkRcUumrVYhZ1dMhBuSkmrYEfP/YpIzzPLLpDB8J5u21S8FskdeIyqya AZiZNBalT2at8lUDRRdCVIZi2SCSHw2ZeCBaUHL6TGKlTmA1qbAuze5xvifKUQUFeKw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793215475; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Rl72VV5Ubg7wfJTJ4j7dVkiRQRmTafn/nb1jTkypI/k=; b=yoGHPYvShx5zVJxpSwwN9InrMDhOpNfK865gy1hafwGbzK/CBjw22ad5VgeHDG+nqGnn m+tWHEtSiK8FPEeXQhqcAXpLSU7wLrpbAb6IdYzUePAXEYp4b9YyiPG4JSvMUXe07Fj9W XzjjleUJiojEUm3wGQVB0OWPWL08EYWR9LOBI3RBYhOiV7ZO2b0eDf/6IVO3TJy3lYzop SJ4sqXPtjBxam2ohTKcCa7HGGlRLuSQlxvsDmWdmFMvA/erTbkm7E8c/smn8Tq9i2JXj+ v2BTNr8o3mnMCTeD/mkxUAN4InIj50oq6lwZ834X82mXvGWLc224egbZu5ypYAmmo9g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=FjtH2Zdm; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 694F8606A31A; Wed, 28 Oct 2026 19:24:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=FjtH2Zdm Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9A511F01825; Wed, 28 Oct 2026 19:24:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793215474; bh=Rl72VV5Ubg7wfJTJ4j7dVkiRQRmTafn/nb1jTkypI/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FjtH2Zdm84i7pmMOol5Wb+G8Fkw1kA28jYehJIjwjgn7mf24VkMQQ9L7OzBOinN+Q 9FNHgBHUkkj8trr4T5DoQKXDq1MVeVHHvH2Me4Rj9dr7MLiqNw3XGtSTl1zOT9H2Me Xbb6Klm7w5/uiD5bHE6wYNKtkT+Df6HlgEaWWThE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Theodor Arsenij Larionov-Trichkine , Florian Westphal , Sasha Levin Subject: [PATCH 6.1 1221/1887] netfilter: nft_fib: reject fib expression on the netdev egress hook Date: Wed, 28 Oct 2026 17:55:17 +0100 Message-ID: <20261028170527.211768432@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodor Arsenij Larionov-Trichkine [ Upstream commit d07955dd34ecae17d35d8c7d0a273a3fba653a8c ] A fib expression in a netdev egress base chain dereferences nft_in(pkt), NULL on the transmit path, causing a NULL pointer dereference at eval. nft_fib_validate() masks the hook with NF_INET_* values, but netdev hook numbers are a separate enum that aliases them (NF_NETDEV_EGRESS == NF_INET_LOCAL_IN), so an egress chain passes validation and then faults. Add nft_fib_netdev_validate() that limits each result/flag to the netdev hook where the device it reads exists: the input-device cases (OIF, OIFNAME, ADDRTYPE with F_IIF) to ingress, the output-device case (ADDRTYPE with F_OIF) to egress, ADDRTYPE with no device flag to both. Also restrict nft_fib_validate() to NFPROTO_IPV4/IPV6/INET so its NF_INET_* masks are not applied to another family's hooks. Fixes: 42df6e1d221d ("netfilter: Introduce egress hook") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/netfilter-devel/ajxsjcDOnwllMfoR@strlen.de/ Signed-off-by: Theodor Arsenij Larionov-Trichkine Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/netfilter/nft_fib.c | 9 +++++++++ net/netfilter/nft_fib_netdev.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nft_fib.c b/net/netfilter/nft_fib.c index 358abe2d86a7f..3acecd7b59bc8 100644 --- a/net/netfilter/nft_fib.c +++ b/net/netfilter/nft_fib.c @@ -30,6 +30,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 9121ec64e918f..ad62a06040ab8 100644 --- a/net/netfilter/nft_fib_netdev.c +++ b/net/netfilter/nft_fib_netdev.c @@ -50,6 +50,33 @@ 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) +{ + const struct nft_fib *priv = nft_expr_priv(expr); + unsigned int hooks; + + 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, hooks); +} + 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 +84,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, .reduce = nft_fib_reduce, }; -- 2.53.0