]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
netfilter: nft_fib: fix stale stack leak via the OIFNAME register
authorDavide Ornaghi <d.ornaghi97@gmail.com>
Wed, 10 Jun 2026 10:39:12 +0000 (12:39 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 10 Jun 2026 16:00:19 +0000 (18:00 +0200)
For NFT_FIB_RESULT_OIFNAME the destination register is declared with
len = IFNAMSIZ (four 32-bit registers), but on the lookup-fail,
RTN_LOCAL and oif-mismatch paths nft_fib{4,6}_eval() only writes one
register via "*dest = 0". The remaining three registers are left as
whatever was on the stack in nft_do_chain()'s struct nft_regs, and a
downstream expression that loads the register span can leak that
uninitialised kernel stack to userspace.

The NFTA_FIB_F_PRESENT existence check has the same shape: it is only
meaningful for NFT_FIB_RESULT_OIF, yet it was accepted for any result type
while the eval stores a single byte via nft_reg_store8(), leaving the rest
of the declared span stale.

Fix both:

 - replace the bare "*dest = 0" in the eval with nft_fib_store_result(),
   which strscpy_pad()s the whole IFNAMSIZ for OIFNAME (and is already
   used on the other early-return path), and

 - restrict NFTA_FIB_F_PRESENT to NFT_FIB_RESULT_OIF and declare its
   destination as a single u8, so the marked span matches the one byte
   the eval writes.

Fixes: f6d0cbcf09c5 ("netfilter: nf_tables: add fib expression")
Suggested-by: Florian Westphal <fw@strlen.de>
Cc: stable@vger.kernel.org
Signed-off-by: Davide Ornaghi <d.ornaghi97@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/ipv4/netfilter/nft_fib_ipv4.c
net/ipv6/netfilter/nft_fib_ipv6.c
net/netfilter/nft_fib.c

index 9d0c6d75109b365ade97de18b9dfd7cbf06b92ba..177d738825b4ced772f186aee47846859b023d94 100644 (file)
@@ -128,7 +128,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
                fl4.saddr = get_saddr(iph->daddr);
        }
 
-       *dest = 0;
+       nft_fib_store_result(dest, priv, NULL);
 
        if (fib_lookup(nft_net(pkt), &fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE))
                return;
index 2dbe44715df30093928e120c419e96ee7e032104..b9ad7cac1417633a029794fd1ae1e2231348d6ed 100644 (file)
@@ -239,7 +239,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
 
        lookup_flags = nft_fib6_flowi_init(&fl6, priv, pkt, oif, iph);
 
-       *dest = 0;
+       nft_fib_store_result(dest, priv, NULL);
        ret = nft_fib6_lookup(nft_net(pkt), &fl6, &res, lookup_flags);
        if (ret || res.fib6_flags & (RTF_REJECT | RTF_ANYCAST | RTF_LOCAL))
                return;
index 327a5f33659cd79da08a430ed5676c25df72e58b..a1632e308f1828eebf68b816b0cd1d14d8418060 100644 (file)
@@ -107,6 +107,12 @@ int nft_fib_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
                return -EINVAL;
        }
 
+       if (priv->flags & NFTA_FIB_F_PRESENT) {
+               if (priv->result != NFT_FIB_RESULT_OIF)
+                       return -EINVAL;
+               len = sizeof(u8);
+       }
+
        err = nft_parse_register_store(ctx, tb[NFTA_FIB_DREG], &priv->dreg,
                                       NULL, NFT_DATA_VALUE, len);
        if (err < 0)