Netdev List
 help / color / mirror / Atom feed
* [PATCH net v3] ipv4: icmp: reject RTN_UNREACHABLE input routes in icmp_route_lookup
@ 2026-08-25  9:45 Dong Chenchen
  2026-08-25 12:09 ` Jiayuan Chen
  2026-08-26 15:40 ` Ido Schimmel
  0 siblings, 2 replies; 4+ messages in thread
From: Dong Chenchen @ 2026-08-25  9:45 UTC (permalink / raw)
  To: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, herbert
  Cc: netdev, zhangchangzhong, Dong Chenchen

When the forward output route cannot be used in icmp_route_lookup(),
it enters the "reverse path" and calls ip_route_input() on fl4_dec.daddr,
the original packet's source address.

ip_route_input() only returns an error for truly invalid packets. For
unreachable addresses it will succeed and return an input route whose
dst.output is set to ip_rt_bug(). The existing check only rejects
RTN_LOCAL routes, so the RTN_UNREACHABLE route types can still be returned
and later used for output, syzkaller triggering a WARN_ON_ONCE()
in ip_rt_bug() as bellow:

 ------------[ cut here ]------------
 WARNING: net/ipv4/route.c:1273 at ip_rt_bug+0x14/0x20
 RIP: 0010:ip_rt_bug+0x14/0x20
 Call Trace:
  ip_push_pending_frames+0xfa/0x100
  __icmp_send+0x905/0xf10
  ip_options_compile+0xc0/0xd0
  ip_rcv_finish_core+0x321/0xae0
  ip_rcv+0x1de/0x260
  __netif_receive_skb_one_core+0x11a/0x130
  netif_receive_skb+0x7b/0x260
  tun_get_user+0x11bf/0x1c10
 ------------[ cut here ]------------

Reject input route that is RTN_UNREACHABLE to fix it.

Fixes: 8b7817f3a959 ("[IPSEC]: Add ICMP host relookup support")
Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>
---
v2:
- RTN_UNICAST judgement will reject bforward packet. Only reject RTN_UNREACHABLE
v3:
- Modify the comments to make them more accurate.
- RTN_UNREACHABLE dont need warn log. 
---
 net/ipv4/icmp.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 0caedfc7ca92..7350f0380be1 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -581,16 +581,15 @@ static struct rtable *icmp_route_lookup(struct net *net, struct flowi4 *fl4,
 		skb_dstref_restore(skb_in, orefdst);
 
 		/*
-		 * At this point, fl4_dec.daddr should NOT be local (we
-		 * checked fl4_dec.saddr above). However, a race condition
-		 * may occur if the address is added to the interface
-		 * concurrently. In that case, ip_route_input() returns a
-		 * LOCAL route with dst.output=ip_rt_bug, which must not
-		 * be used for output.
+		 * At this point, fl4_dec.daddr should NOT be local (the
+		 * address can be added to the interface concurrently) or unroutable.
+		 * In that case, ip_route_input() returns a LOCAL or UNREACHABLE
+		 * route with dst.output=ip_rt_bug, which must not be used for output.
 		 */
-		if (!err && rt2 && rt2->rt_type == RTN_LOCAL) {
-			net_warn_ratelimited("detected local route for %pI4 during ICMP sending, src %pI4\n",
-					     &fl4_dec.daddr, &fl4_dec.saddr);
+		if (!err && rt2 && (rt2->rt_type == RTN_LOCAL || rt2->rt_type == RTN_UNREACHABLE)) {
+			if (rt2->rt_type == RTN_LOCAL)
+				net_warn_ratelimited("detected local route for %pI4 during ICMP sending, src %pI4\n",
+						     &fl4_dec.daddr, &fl4_dec.saddr);
 			dst_release(&rt2->dst);
 			err = -EINVAL;
 		}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net v3] ipv4: icmp: reject RTN_UNREACHABLE input routes in icmp_route_lookup
  2026-08-25  9:45 [PATCH net v3] ipv4: icmp: reject RTN_UNREACHABLE input routes in icmp_route_lookup Dong Chenchen
@ 2026-08-25 12:09 ` Jiayuan Chen
  2026-08-26 15:40 ` Ido Schimmel
  1 sibling, 0 replies; 4+ messages in thread
From: Jiayuan Chen @ 2026-08-25 12:09 UTC (permalink / raw)
  To: Dong Chenchen, dsahern, idosch, davem, edumazet, kuba, pabeni,
	horms, herbert
  Cc: netdev, zhangchangzhong


On 8/25/26 5:45 PM, Dong Chenchen wrote:
> When the forward output route cannot be used in icmp_route_lookup(),
> it enters the "reverse path" and calls ip_route_input() on fl4_dec.daddr,
> the original packet's source address.
>
> ip_route_input() only returns an error for truly invalid packets. For
> unreachable addresses it will succeed and return an input route whose
> dst.output is set to ip_rt_bug(). The existing check only rejects
> RTN_LOCAL routes, so the RTN_UNREACHABLE route types can still be returned
> and later used for output, syzkaller triggering a WARN_ON_ONCE()
> in ip_rt_bug() as bellow:
>
>   ------------[ cut here ]------------
>   WARNING: net/ipv4/route.c:1273 at ip_rt_bug+0x14/0x20
>   RIP: 0010:ip_rt_bug+0x14/0x20
>   Call Trace:
>    ip_push_pending_frames+0xfa/0x100
>    __icmp_send+0x905/0xf10
>    ip_options_compile+0xc0/0xd0
>    ip_rcv_finish_core+0x321/0xae0
>    ip_rcv+0x1de/0x260
>    __netif_receive_skb_one_core+0x11a/0x130
>    netif_receive_skb+0x7b/0x260
>    tun_get_user+0x11bf/0x1c10
>   ------------[ cut here ]------------
>
> Reject input route that is RTN_UNREACHABLE to fix it.
>
> Fixes: 8b7817f3a959 ("[IPSEC]: Add ICMP host relookup support")
> Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>


Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net v3] ipv4: icmp: reject RTN_UNREACHABLE input routes in icmp_route_lookup
  2026-08-25  9:45 [PATCH net v3] ipv4: icmp: reject RTN_UNREACHABLE input routes in icmp_route_lookup Dong Chenchen
  2026-08-25 12:09 ` Jiayuan Chen
@ 2026-08-26 15:40 ` Ido Schimmel
  2026-08-27 11:49   ` dongchenchen (A)
  1 sibling, 1 reply; 4+ messages in thread
From: Ido Schimmel @ 2026-08-26 15:40 UTC (permalink / raw)
  To: Dong Chenchen
  Cc: dsahern, davem, edumazet, kuba, pabeni, horms, herbert, netdev,
	zhangchangzhong

On Tue, Aug 25, 2026 at 05:45:23PM +0800, Dong Chenchen wrote:
> When the forward output route cannot be used in icmp_route_lookup(),
> it enters the "reverse path" and calls ip_route_input() on fl4_dec.daddr,
> the original packet's source address.
> 
> ip_route_input() only returns an error for truly invalid packets. For
> unreachable addresses it will succeed and return an input route whose
> dst.output is set to ip_rt_bug(). The existing check only rejects
> RTN_LOCAL routes, so the RTN_UNREACHABLE route types can still be returned
> and later used for output, syzkaller triggering a WARN_ON_ONCE()
> in ip_rt_bug() as bellow:
> 
>  ------------[ cut here ]------------
>  WARNING: net/ipv4/route.c:1273 at ip_rt_bug+0x14/0x20
>  RIP: 0010:ip_rt_bug+0x14/0x20
>  Call Trace:
>   ip_push_pending_frames+0xfa/0x100
>   __icmp_send+0x905/0xf10
>   ip_options_compile+0xc0/0xd0
>   ip_rcv_finish_core+0x321/0xae0
>   ip_rcv+0x1de/0x260
>   __netif_receive_skb_one_core+0x11a/0x130
>   netif_receive_skb+0x7b/0x260
>   tun_get_user+0x11bf/0x1c10
>  ------------[ cut here ]------------
> 
> Reject input route that is RTN_UNREACHABLE to fix it.

Nit: Also mention that the warning is only printed for RTN_LOCAL, as
RTN_UNREACHABLE is not the result of a race condition.

> 
> Fixes: 8b7817f3a959 ("[IPSEC]: Add ICMP host relookup support")
> Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>
> ---
> v2:
> - RTN_UNICAST judgement will reject bforward packet. Only reject RTN_UNREACHABLE
> v3:
> - Modify the comments to make them more accurate.
> - RTN_UNREACHABLE dont need warn log. 
> ---
>  net/ipv4/icmp.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
> index 0caedfc7ca92..7350f0380be1 100644
> --- a/net/ipv4/icmp.c
> +++ b/net/ipv4/icmp.c
> @@ -581,16 +581,15 @@ static struct rtable *icmp_route_lookup(struct net *net, struct flowi4 *fl4,
>  		skb_dstref_restore(skb_in, orefdst);
>  
>  		/*
> -		 * At this point, fl4_dec.daddr should NOT be local (we
> -		 * checked fl4_dec.saddr above). However, a race condition
> -		 * may occur if the address is added to the interface
> -		 * concurrently. In that case, ip_route_input() returns a
> -		 * LOCAL route with dst.output=ip_rt_bug, which must not
> -		 * be used for output.
> +		 * At this point, fl4_dec.daddr should NOT be local (the
> +		 * address can be added to the interface concurrently) or unroutable.
> +		 * In that case, ip_route_input() returns a LOCAL or UNREACHABLE
> +		 * route with dst.output=ip_rt_bug, which must not be used for output.
>  		 */

The code is fine, but the comment is a bit misleading (the "should NOT"
part is only correct for "local"). I find this clearer:

"
fl4_dec.daddr is not expected to be local here, but it can be added to
an interface concurrently, in which case ip_route_input() returns a
LOCAL route. It can also fail to build a forwarding route towards
fl4_dec.daddr, for example, when forwarding is disabled, and return an
UNREACHABLE route. Both cases will result in a route with
dst.output=ip_rt_bug, which must not be used for output.
"

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net v3] ipv4: icmp: reject RTN_UNREACHABLE input routes in icmp_route_lookup
  2026-08-26 15:40 ` Ido Schimmel
@ 2026-08-27 11:49   ` dongchenchen (A)
  0 siblings, 0 replies; 4+ messages in thread
From: dongchenchen (A) @ 2026-08-27 11:49 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: dsahern, davem, edumazet, kuba, pabeni, horms, herbert, netdev,
	zhangchangzhong


> On Tue, Aug 25, 2026 at 05:45:23PM +0800, Dong Chenchen wrote:
>> When the forward output route cannot be used in icmp_route_lookup(),
>> it enters the "reverse path" and calls ip_route_input() on fl4_dec.daddr,
>> the original packet's source address.
>>
>> ip_route_input() only returns an error for truly invalid packets. For
>> unreachable addresses it will succeed and return an input route whose
>> dst.output is set to ip_rt_bug(). The existing check only rejects
>> RTN_LOCAL routes, so the RTN_UNREACHABLE route types can still be returned
>> and later used for output, syzkaller triggering a WARN_ON_ONCE()
>> in ip_rt_bug() as bellow:
>>
>>   ------------[ cut here ]------------
>>   WARNING: net/ipv4/route.c:1273 at ip_rt_bug+0x14/0x20
>>   RIP: 0010:ip_rt_bug+0x14/0x20
>>   Call Trace:
>>    ip_push_pending_frames+0xfa/0x100
>>    __icmp_send+0x905/0xf10
>>    ip_options_compile+0xc0/0xd0
>>    ip_rcv_finish_core+0x321/0xae0
>>    ip_rcv+0x1de/0x260
>>    __netif_receive_skb_one_core+0x11a/0x130
>>    netif_receive_skb+0x7b/0x260
>>    tun_get_user+0x11bf/0x1c10
>>   ------------[ cut here ]------------
>>
>> Reject input route that is RTN_UNREACHABLE to fix it.
> 
> Nit: Also mention that the warning is only printed for RTN_LOCAL, as
> RTN_UNREACHABLE is not the result of a race condition.
> 
>>
>> Fixes: 8b7817f3a959 ("[IPSEC]: Add ICMP host relookup support")
>> Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>
>> ---
>> v2:
>> - RTN_UNICAST judgement will reject bforward packet. Only reject RTN_UNREACHABLE
>> v3:
>> - Modify the comments to make them more accurate.
>> - RTN_UNREACHABLE dont need warn log.
>> ---
>>   net/ipv4/icmp.c | 17 ++++++++---------
>>   1 file changed, 8 insertions(+), 9 deletions(-)
>>
>> diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
>> index 0caedfc7ca92..7350f0380be1 100644
>> --- a/net/ipv4/icmp.c
>> +++ b/net/ipv4/icmp.c
>> @@ -581,16 +581,15 @@ static struct rtable *icmp_route_lookup(struct net *net, struct flowi4 *fl4,
>>   		skb_dstref_restore(skb_in, orefdst);
>>   
>>   		/*
>> -		 * At this point, fl4_dec.daddr should NOT be local (we
>> -		 * checked fl4_dec.saddr above). However, a race condition
>> -		 * may occur if the address is added to the interface
>> -		 * concurrently. In that case, ip_route_input() returns a
>> -		 * LOCAL route with dst.output=ip_rt_bug, which must not
>> -		 * be used for output.
>> +		 * At this point, fl4_dec.daddr should NOT be local (the
>> +		 * address can be added to the interface concurrently) or unroutable.
>> +		 * In that case, ip_route_input() returns a LOCAL or UNREACHABLE
>> +		 * route with dst.output=ip_rt_bug, which must not be used for output.
>>   		 */
> 
> The code is fine, but the comment is a bit misleading (the "should NOT"
> part is only correct for "local"). I find this clearer:
> 
> "
> fl4_dec.daddr is not expected to be local here, but it can be added to
> an interface concurrently, in which case ip_route_input() returns a
> LOCAL route. It can also fail to build a forwarding route towards
> fl4_dec.daddr, for example, when forwarding is disabled, and return an
> UNREACHABLE route. Both cases will result in a route with
> dst.output=ip_rt_bug, which must not be used for output.
> "
> 
> Thanks!

Thanks for review!
v4 will be sent

> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-27 11:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-25  9:45 [PATCH net v3] ipv4: icmp: reject RTN_UNREACHABLE input routes in icmp_route_lookup Dong Chenchen
2026-08-25 12:09 ` Jiayuan Chen
2026-08-26 15:40 ` Ido Schimmel
2026-08-27 11:49   ` dongchenchen (A)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox