BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xuanqiang Luo" <xuanqiang.luo@linux.dev>
Cc: bpf@vger.kernel.org, mptcp@lists.linux.dev
Subject: Re: [PATCH net-next v1 2/6] ipv4: avoid a stack canary in ip_finish_output2()
Date: Wed, 25 Nov 2026 13:09:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-233459@kernel.org> (raw)
In-Reply-To: <20261124130631.1886963-3-xuanqiang.luo@linux.dev>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] bpf: device mismatch in bpf_out_neigh_v4() on RTN_LOCAL routes
  [1]
--

commit ca3d30f8ff839a5ead3ac3b6137813b8e1486837
Author: Xuanqiang Luo <luoxuanqiang@kylinos.cn>

ipv4: avoid a stack canary in ip_finish_output2()

This commit changes ip_neigh_gw4() to take a pointer to the IPv4 address
instead of passing it by value, avoiding a stack canary in callers such as
ip_finish_output2() and deduplicating inlined calls in ip_neigh_for_gw()
and ipv4_dst_neigh_lookup().

[ ... ]

> diff --git a/include/net/route.h b/include/net/route.h
> index 3fccd31eb74df..1571e1c6082cc 100644
> --- a/include/net/route.h
> +++ b/include/net/route.h

[ ... ]

> @@ -425,17 +425,17 @@ static inline struct neighbour *ip_neigh_for_gw(struct rtable *rt,
>  						bool *is_v6gw)
>  {
>  	struct net_device *dev = rt->dst.dev;
> -	struct neighbour *neigh;
> +	const __be32 *daddr;
>  
>  	if (likely(rt->rt_gw_family == AF_INET)) {
> -		neigh = ip_neigh_gw4(dev, rt->rt_gw4);
> +		daddr = &rt->rt_gw4;
>  	} else if (rt->rt_gw_family == AF_INET6) {
> -		neigh = ip_neigh_gw6(dev, &rt->rt_gw6);
>  		*is_v6gw = true;
> +		return ip_neigh_gw6(dev, &rt->rt_gw6);
>  	} else {
> -		neigh = ip_neigh_gw4(dev, ip_hdr(skb)->daddr);
> +		daddr = &ip_hdr(skb)->daddr;
>  	}
> -	return neigh;
> +	return ip_neigh_gw4(dev, daddr);
>  }
>  
>  #endif	/* _ROUTE_H */
> diff --git a/net/core/filter.c b/net/core/filter.c
> index f42ecfb5841f9..8ee023c87c243 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2376,7 +2376,7 @@ static int bpf_out_neigh_v4(struct net *net, struct sk_buff *skb,
>  		neigh = ip_neigh_gw6(dev, &nh->ipv6_nh);
>  		is_v6gw = true;
>  	} else if (nh->nh_family == AF_INET) {
> -		neigh = ip_neigh_gw4(dev, nh->ipv4_nh);
> +		neigh = ip_neigh_gw4(dev, &nh->ipv4_nh);
>  	} else {
>  		rcu_read_unlock();
>  		goto out_drop;

[Severity: High]
This problem wasn't introduced by this patch, but can bpf_out_neigh_v4()
resolve the neighbour on the wrong device when nh is NULL [1]?

When __bpf_redirect_neigh_v4() resolves an RTN_LOCAL route via
ip_route_output_flow(), rt->dst.dev is set to net->loopback_dev (or the VRF
device) rather than the target redirect device dev:

net/core/filter.c:bpf_out_neigh_v4() {
	...
	skb->dev = dev;
	skb_clear_tstamp(skb);

	if (unlikely(skb_headroom(skb) < hh_len && dev->header_ops)) {
		skb = skb_expand_head(skb, hh_len);
		if (!skb)
			return -ENOMEM;
	}

	rcu_read_lock();
	if (!nh) {
		struct rtable *rt = skb_rtable(skb);

		neigh = ip_neigh_for_gw(rt, skb, &is_v6gw);
	...
}

Because ip_neigh_for_gw() uses rt->dst.dev instead of dev, neigh_output()
is invoked with a loopback_dev neighbour (which uses eth_header_ops) while
skb->dev points to dev.  If dev is an L3 device where dev->header_ops is
NULL (such as a tun interface), bpf_out_neigh_v4() skips skb_expand_head(),
and neigh_output() pushes an Ethernet header without sufficient headroom,
triggering skb_under_panic().

[1] https://sashiko.dev/#/bug/linux-26626829-3abf-4baa-b906-b783eeb1b107

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124130631.1886963-1-xuanqiang.luo@linux.dev?part=2

  reply	other threads:[~2026-11-25 13:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 13:06 [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4 fast paths Xuanqiang Luo
2026-11-24 13:06 ` [PATCH net-next v1 1/6] tcp: avoid a stack canary in __tcp_select_window() Xuanqiang Luo
2026-11-24 13:06 ` [PATCH net-next v1 2/6] ipv4: avoid a stack canary in ip_finish_output2() Xuanqiang Luo
2026-11-25 13:09   ` sashiko-bot [this message]
2026-11-24 13:06 ` [PATCH net-next v1 3/6] ipv4: raw: do not use skb_header_pointer() in icmp_filter() Xuanqiang Luo
2026-11-24 13:06 ` [PATCH net-next v1 4/6] net: avoid stack canaries in skb_try_coalesce() callers Xuanqiang Luo
2026-11-24 13:06 ` [PATCH net-next v1 5/6] tcp: avoid a stack canary in tcp_rcv_established() Xuanqiang Luo
2026-11-25 13:09   ` sashiko-bot
2026-11-24 13:06 ` [PATCH net-next v1 6/6] tcp: do not call bpf_skops_write_hdr_opt() unless needed Xuanqiang Luo

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=sashiko-outbox-233459@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xuanqiang.luo@linux.dev \
    /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