]> www.infradead.org Git - users/hch/misc.git/commitdiff
ipv4: icmp: Fix source IP derivation in presence of VRFs
authorIdo Schimmel <idosch@nvidia.com>
Mon, 8 Sep 2025 07:32:33 +0000 (10:32 +0300)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 11 Sep 2025 10:22:38 +0000 (12:22 +0200)
When the "icmp_errors_use_inbound_ifaddr" sysctl is enabled, the source
IP of ICMP error messages should be the "primary address of the
interface that received the packet that caused the icmp error".

The IPv4 ICMP code determines this interface using inet_iif() which in
the input path translates to skb->skb_iif. If the interface that
received the packet is a VRF port, skb->skb_iif will contain the ifindex
of the VRF device and not that of the receiving interface. This is
because in the input path the VRF driver overrides skb->skb_iif with the
ifindex of the VRF device itself (see vrf_ip_rcv()).

As such, the source IP that will be chosen for the ICMP error message is
either an address assigned to the VRF device itself (if present) or an
address assigned to some VRF port, not necessarily the input or output
interface.

This behavior is especially problematic when the error messages are
"Time Exceeded" messages as it means that utilities like traceroute will
show an incorrect packet path.

Solve this by determining the input interface based on the iif field in
the control block, if present. This field is set in the input path to
skb->skb_iif and is not later overridden by the VRF driver, unlike
skb->skb_iif.

This behavior is consistent with the IPv6 counterpart that already uses
the iif from the control block.

Reported-by: Andy Roulin <aroulin@nvidia.com>
Reported-by: Rajkumar Srinivasan <rajsrinivasa@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Link: https://patch.msgid.link/20250908073238.119240-4-idosch@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/ipv4/icmp.c

index 59fd0e1993a6fc5c2c1f2a502e151c6f2547bce3..1b7fb5d935edfd95df7881ef55e9fbea7e88aaf0 100644 (file)
@@ -710,7 +710,8 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info,
                rcu_read_lock();
                if (rt_is_input_route(rt) &&
                    READ_ONCE(net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr))
-                       dev = dev_get_by_index_rcu(net, inet_iif(skb_in));
+                       dev = dev_get_by_index_rcu(net, parm->iif ? parm->iif :
+                                                  inet_iif(skb_in));
 
                if (dev)
                        saddr = inet_select_addr(dev, iph->saddr,