mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: jiayuan.chen@linux.dev
Cc: netdev@vger.kernel.org, stable@vger.kernel.org,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, dsahern@kernel.org,
	idosch@nvidia.com, kuniyu@google.com, joel.granados@kernel.org,
	chia-yu.chang@nokia-bell-labs.com, bronzed_45_vested@icloud.com,
	yuuchihsu@gmail.com, fmancera@suse.de,
	hannes@stressinduktion.org, fbl@redhat.com, pmladek@suse.com,
	paulmck@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 2/5] ipv4: fix shift-out-of-bounds in ip_rt_send_redirect()
Date: Mon, 26 Oct 2026 12:15:39 +0000	[thread overview]
Message-ID: <179301693984.3134.10311722588849367187@kernel.org> (raw)
In-Reply-To: <20261023091419.167088-3-jiayuan.chen@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The new backoff code in ip_rt_send_redirect() casts the signed
  sysctl `ip_rt_redirect_load` straight to u64.

--

ipv4: fix shift-out-of-bounds in ip_rt_send_redirect()

This commit fixes a UBSAN shift-out-of-bounds in ip_rt_send_redirect().
The shift happens when ip_rt_redirect_number is set above 32. The backoff
is now computed in u64 with the shift count capped at 31, and the result
is clamped to MAX_JIFFY_OFFSET before it is passed to time_after().

> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
> index 595a3b7f17830..76807b7570467 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c

[ ... ]

> @@ -945,10 +946,10 @@ void ip_rt_send_redirect(struct sk_buff *skb)
>  	/* Check for load limit; set rate_last to the latest sent
>  	 * redirect.
>  	 */
> +	backoff = (u64)ip_rt_redirect_load << min(peer->n_redirects, 31U);
> +	backoff = min_t(u64, backoff, MAX_JIFFY_OFFSET);

[Severity: Medium]
What happens here when ip_rt_redirect_load is negative?

The redirect_load sysctl is a plain proc_dointvec with no extra1/extra2
bounds, so root can write a negative value:

net/ipv4/route.c:ipv4_route_table[] {
    ...
	.procname	= "redirect_load",
	.data		= &ip_rt_redirect_load,
	.maxlen		= sizeof(int),
	.mode		= 0644,
	.proc_handler	= proc_dointvec,
    ...
}

When the load is a negative x, (u64)ip_rt_redirect_load sign-extends to
2^64 + x. For any shift n <= 31, the shifted value mod 2^64 is
2^64 + x * 2^n, which is still at or above 2^63.

The min_t() would then always return MAX_JIFFY_OFFSET, and this check
would effectively never be true:

    time_after(jiffies, peer->rate_last + MAX_JIFFY_OFFSET)

So after the first redirect (n_redirects == 0 skips the check), does a
peer get no more redirects until the ip_rt_redirect_silence reset clears
n_redirects?

Before this patch, a negative load produced a negative offset from
rate_last. time_after() was then always true, so a redirect went out on
every packet until ip_rt_redirect_number was reached. With this patch a
negative redirect_load seems to change from no backoff to maximum backoff.

The commit message says the u64 computation "cannot overflow since
ip_rt_redirect_load is an int". That only seems to hold for non-negative
values.

A later patch in this series restricts message_cost and message_burst to
non-negative values. It doesn't touch redirect_load, and route.c is
unchanged through the end of the series.

Would it make sense to treat a negative load as 0 before the cast? The
other option is a lower bound on the sysctl, for example
proc_dointvec_minmax with extra1 = SYSCTL_ZERO.

>  	if (peer->n_redirects == 0 ||
> -	    time_after(jiffies,
> -		       (peer->rate_last +
> -			(ip_rt_redirect_load << peer->n_redirects)))) {
> +	    time_after(jiffies, peer->rate_last + (unsigned long)backoff)) {
>  		__be32 gw = rt_nexthop(rt, ip_hdr(skb)->daddr);
>  
>  		icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, gw);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261023091419.167088-1-jiayuan.chen%40linux.dev

  parent reply	other threads:[~2026-10-26 12:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23  9:13 [PATCH net 0/5] net: fix misc signed overflows caused by bad sysctl values Jiayuan Chen
2026-10-23  9:13 ` [PATCH net 1/5] ipv6: restrict gc_elasticity to 31 Jiayuan Chen
2026-10-23 13:31   ` Fernando Fernandez Mancera
2026-10-26 12:15   ` netdev-bot+sashiko
2026-10-27  5:18   ` Kuniyuki Iwashima
2026-10-23  9:13 ` [PATCH net 2/5] ipv4: fix shift-out-of-bounds in ip_rt_send_redirect() Jiayuan Chen
2026-10-23 14:11   ` Fernando Fernandez Mancera
2026-10-23 14:38     ` Jiayuan Chen
2026-10-26 12:15   ` netdev-bot+sashiko [this message]
2026-10-23  9:13 ` [PATCH net 3/5] ipv6: restrict mld_qrv to 255 Jiayuan Chen
2026-10-23 14:13   ` Fernando Fernandez Mancera
2026-10-26 12:15   ` netdev-bot+sashiko
2026-10-27  5:24   ` Kuniyuki Iwashima
2026-10-23  9:13 ` [PATCH net 4/5] ipv4: restrict igmp_qrv " Jiayuan Chen
2026-10-23 14:14   ` Fernando Fernandez Mancera
2026-10-26 12:15   ` netdev-bot+sashiko
2026-10-27  5:25   ` Kuniyuki Iwashima
2026-10-23  9:13 ` [PATCH net 5/5] net: restrict message_cost and message_burst to non-negative values Jiayuan Chen
2026-10-23 12:19   ` Joel Granados
2026-10-23 12:55     ` Fernando Fernandez Mancera
2026-10-23 14:30       ` Jiayuan Chen

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=179301693984.3134.10311722588849367187@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=bronzed_45_vested@icloud.com \
    --cc=chia-yu.chang@nokia-bell-labs.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=fbl@redhat.com \
    --cc=fmancera@suse.de \
    --cc=hannes@stressinduktion.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=joel.granados@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=pmladek@suse.com \
    --cc=stable@vger.kernel.org \
    --cc=yuuchihsu@gmail.com \
    /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

all inboxes | Powered by JetHome®