Linux Netfilter development
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: pablo@netfilter.org
Cc: Jakub Kicinski <kuba@kernel.org>,
	netfilter-devel@vger.kernel.org, davem@davemloft.net,
	netdev@vger.kernel.org, pabeni@redhat.com, edumazet@google.com,
	horms@kernel.org, fw@strlen.de, ja@ssi.bg
Subject: Re: [PATCH net 03/10] netfilter: ip6t_rpfilter: reject routes without inet6_dev
Date: Thu, 17 Sep 2026 19:04:10 -0700	[thread overview]
Message-ID: <20260918020410.3513378-1-kuba@kernel.org> (raw)
In-Reply-To: <20260916231652.127456-4-pablo@netfilter.org>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
netfilter: ip6t_rpfilter: reject routes without inet6_dev

This adds a NULL check on rt6i_idev right after the ip6_route_lookup()
call in rpfilter_lookup_reverse6(), so routes that survived in the FIB
after their nexthop device lost its inet6_dev are skipped. It protects
the later rt6i_idev->dev dereferences in the same function.

Closes: https://lore.kernel.org/all/VtWUkE8QzJt5CroTj2V2v3ZQ0gwbXZ7nq7I3@bugs.sh/

> diff --git a/net/ipv6/netfilter/ip6t_rpfilter.c b/net/ipv6/netfilter/ip6t_rpfilter.c
> index 67c87a88cde4f..b5def30c3127e 100644
> --- a/net/ipv6/netfilter/ip6t_rpfilter.c
> +++ b/net/ipv6/netfilter/ip6t_rpfilter.c
> @@ -61,7 +61,7 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb,
>  		fl6.flowi6_oif = dev->ifindex;
>  
>  	rt = (void *)ip6_route_lookup(net, &fl6, skb, lookup_flags);
> -	if (rt->dst.error)
> +	if (rt->dst.error || !rt->rt6i_idev)
>  		goto out;

[Severity: High]
This isn't a bug introduced by this patch, but if rt6i_idev can be NULL on
an error-free route, does the same dereference remain unguarded in
validate_ipv6_net_dev() in drivers/infiniband/core/cma.c?

drivers/infiniband/core/cma.c:validate_ipv6_net_dev() {
	struct rt6_info *rt = rt6_lookup(dev_net(net_dev), &dst_addr->sin6_addr,
					 &src_addr->sin6_addr, net_dev->ifindex,
					 NULL, strict);
	bool ret;

	if (!rt)
		return false;

	ret = rt->rt6i_idev->dev == net_dev;
	...
}

The !rt test there looks equivalent to the rt->dst.error test this patch
just found insufficient, since rt6_lookup() only returns NULL for the
error case:

net/ipv6/route.c:rt6_lookup() {
	dst = fib6_rule_lookup(net, &fl6, skb, flags, ip6_pol_route_lookup);
	if (dst->error == 0)
		return dst_rt6_info(dst);

	dst_release(dst);

	return NULL;
}

So the route class described in this commit message, an error-free cache
route whose rt6i_idev was left NULL by ip6_rt_copy_init():

net/ipv6/route.c:ip6_rt_copy_init() {
	...
	rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL;
	...
}

would pass the !rt check and then be dereferenced when validating an
incoming RoCE CM request via validate_net_dev() -> validate_ipv6_net_dev().

The other in-tree readers of the field already treat NULL as legal:

net/ipv6/fib6_rules.c:fib6_rule_suppress() {
	...
	if (rt->rt6i_idev)
		dev = rt->rt6i_idev->dev;
	...
}

net/ipv6/icmp.c:icmp6_send() {
	...
		if (rt6 && rt6->rt6i_idev)
			dev = rt6->rt6i_idev->dev;
	...
}

Would a follow-up patch adding the same guard to cma.c make sense? Note
that reaching the cma.c site is not unprivileged end-to-end the way the
rpfilter path is: it needs the NULL-idev route to exist in the namespace
of the RoCE netdev, which normally means CAP_NET_ADMIN in init_net plus an
RDMA-capable device. Nothing later in this series touches
drivers/infiniband/core/cma.c or net/ipv6/route.c, so the call site is
still unguarded at the end of the series.

  reply	other threads:[~2026-09-18  2:04 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 23:16 [PATCH net 00/10] Netfilter/IPVS fixes for net Pablo Neira Ayuso
2026-09-16 23:16 ` [PATCH net 01/10] netfilter: flowtable: publish HW_DEAD after worker is done Pablo Neira Ayuso
2026-09-17  0:40   ` patchwork-bot+netdevbpf
2026-09-18  2:04   ` Jakub Kicinski
2026-09-18  8:38     ` Pablo Neira Ayuso
2026-09-18  8:56       ` my summary of LLM judgement in this PR [was Re: [PATCH net 01/10] netfilter: flowtable: publish HW_DEAD after worker is done] Pablo Neira Ayuso
2026-09-21 20:56         ` Jakub Kicinski
2026-09-16 23:16 ` [PATCH net 02/10] netfilter: nfnetlink_queue: hold nfnl mutex in event notifier Pablo Neira Ayuso
2026-09-18  2:04   ` Jakub Kicinski
2026-09-18  8:39     ` Pablo Neira Ayuso
2026-09-18  9:51     ` Florian Westphal
2026-09-16 23:16 ` [PATCH net 03/10] netfilter: ip6t_rpfilter: reject routes without inet6_dev Pablo Neira Ayuso
2026-09-18  2:04   ` Jakub Kicinski [this message]
2026-09-18  8:39     ` Pablo Neira Ayuso
2026-09-16 23:16 ` [PATCH net 04/10] netfilter: ip6t_rt: fix zero-address non-strict match out-of-bounds read Pablo Neira Ayuso
2026-09-16 23:16 ` [PATCH net 05/10] netfilter: nft_synproxy: use the family-aware checksum helper Pablo Neira Ayuso
2026-09-16 23:16 ` [PATCH net 06/10] ipvs: revalidate ihl before icmp_send Pablo Neira Ayuso
2026-09-16 23:16 ` [PATCH net 07/10] ipvs: filter some flags received in the backup server Pablo Neira Ayuso
2026-09-18  2:04   ` Jakub Kicinski
2026-09-18  8:39     ` Pablo Neira Ayuso
2026-09-18 10:23     ` Julian Anastasov
2026-09-16 23:16 ` [PATCH net 08/10] netfilter: ctnetlink: fix suspicious RCU usage in expect_iter_name Pablo Neira Ayuso
2026-09-16 23:16 ` [PATCH net 09/10] net: remove WARN_ON_ONCE() from the dev_fill_forward_path() loop check Pablo Neira Ayuso
2026-09-16 23:16 ` [PATCH net 10/10] netfilter: nf_tables: skip expired catchall elements on insert and delete Pablo Neira Ayuso
2026-09-18  2:04   ` Jakub Kicinski
2026-09-18  8:41     ` Pablo Neira Ayuso

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=20260918020410.3513378-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=ja@ssi.bg \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox