From: sashiko-bot@kernel.org
To: "Mahe Tardy" <mahe.tardy@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v8 3/7] bpf: add bpf_icmp_send kfunc
Date: Mon, 22 Jun 2026 12:32:22 +0000 [thread overview]
Message-ID: <20260622123222.5AE7F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260622120515.137082-4-mahe.tardy@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf_icmp_send() causes __icmp_send() to bypass broadcast checks and spoof the source address for TC ingress packets.
--
commit 2acddb10f02b54c09816af3432bc928c87824069
Author: Mahe Tardy <mahe.tardy@gmail.com>
bpf: add bpf_icmp_send kfunc
This commit adds the bpf_icmp_send kfunc to allow cgroup_skb and tc programs
to send ICMP error messages in response to packets. It clones the original
packet, optionally assigns a route using ip_route_reply_fill_dst for
unrouted ingress packets, and invokes the standard icmp_send or icmpv6_send
functions.
> diff --git a/net/core/filter.c b/net/core/filter.c
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
[ ... ]
> @@ -12546,6 +12548,101 @@ __bpf_kfunc int bpf_xdp_pull_data(struct xdp_md *x, u32 len)
> +__bpf_kfunc int bpf_icmp_send(struct __sk_buff *skb_ctx, int type, int code)
> +{
> + struct sk_buff *skb = (struct sk_buff *)skb_ctx;
> + struct sk_buff *nskb;
> + struct sock *sk;
[ ... ]
> + switch (skb->protocol) {
> +#if IS_ENABLED(CONFIG_INET)
> + case htons(ETH_P_IP):
> + if (type != ICMP_DEST_UNREACH)
> + return -EOPNOTSUPP;
> + if (code < 0 || code > NR_ICMP_UNREACH)
> + return -EINVAL;
> +
> + nskb = skb_clone(skb, GFP_ATOMIC);
> + if (!nskb)
> + return -ENOMEM;
> +
> + if (!pskb_network_may_pull(nskb, sizeof(struct iphdr))) {
> + kfree_skb(nskb);
> + return -EBADMSG;
> + }
> +
> + if (!skb_dst(nskb) && ip_route_reply_fill_dst(nskb) < 0) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
Does using ip_route_reply_fill_dst() here cause regressions with how
__icmp_send() evaluates routing flags?
For TC ingress packets where skb_dst(nskb) is NULL, this attaches an output
route. However, __icmp_send() expects the SKB to have an input route when
evaluating rt_flags:
net/ipv4/icmp.c:__icmp_send() {
...
if (rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))
goto out;
...
saddr = iph->daddr;
if (!(rt->rt_flags & RTCF_LOCAL)) {
...
saddr = 0;
}
...
}
Because the attached route is an output route, it lacks RTCF_BROADCAST,
which might incorrectly allow ICMP replies to broadcast traffic.
Additionally, because RTCF_LOCAL is missing on the output route,
__icmp_send() clears saddr. This causes icmp_route_lookup() to select the
primary IP of the outgoing interface rather than the specific IP the packet
was originally addressed to, violating RFC 1122 requirements for ICMP error
source addresses.
> + kfree_skb(nskb);
> + return -EHOSTUNREACH;
> + }
> +
> + memset(IPCB(nskb), 0, sizeof(struct inet_skb_parm));
> +
> + icmp_send(nskb, type, code, 0);
> + consume_skb(nskb);
> + break;
> +#endif
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260622120515.137082-1-mahe.tardy@gmail.com?part=3
next prev parent reply other threads:[~2026-06-22 12:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 12:05 [PATCH bpf-next v8 0/7] bpf: add icmp_send kfunc Mahe Tardy
2026-06-22 12:05 ` [PATCH bpf-next v8 1/7] net: move netfilter nf_reject_fill_skb_dst to core ipv4 Mahe Tardy
2026-06-22 12:05 ` [PATCH bpf-next v8 2/7] net: move netfilter nf_reject6_fill_skb_dst to core ipv6 Mahe Tardy
2026-06-22 12:05 ` [PATCH bpf-next v8 3/7] bpf: add bpf_icmp_send kfunc Mahe Tardy
2026-06-22 12:32 ` sashiko-bot [this message]
2026-06-22 18:55 ` Mahe Tardy
2026-06-22 12:05 ` [PATCH bpf-next v8 4/7] selftests/bpf: add bpf_icmp_send kfunc cgroup_skb tests Mahe Tardy
2026-06-22 12:41 ` bot+bpf-ci
2026-06-22 12:05 ` [PATCH bpf-next v8 5/7] selftests/bpf: add bpf_icmp_send kfunc cgroup_skb IPv6 tests Mahe Tardy
2026-06-22 12:15 ` sashiko-bot
2026-06-22 12:05 ` [PATCH bpf-next v8 6/7] selftests/bpf: add bpf_icmp_send kfunc tc tests Mahe Tardy
2026-06-22 12:41 ` bot+bpf-ci
2026-06-22 12:05 ` [PATCH bpf-next v8 7/7] selftests/bpf: add bpf_icmp_send recursion test Mahe Tardy
2026-06-22 12:13 ` sashiko-bot
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=20260622123222.5AE7F1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=mahe.tardy@gmail.com \
--cc=sashiko-reviews@lists.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