Article View: linux.kernel.netdev
Article #7863[PATCH net v2 2/5] ipv4: fix shift-out-of-bounds in ip_rt_send_redirect()
From: Jiayuan Chen
Date: Tue, 27 Oct 2026 10:45
Date: Tue, 27 Oct 2026 10:45
91 lines
12620 bytes
12620 bytes
ip_rt_redirect_number is the max number of ICMP Redirects we send to one
endpoint; once we hit it we stop. Before that, ip_rt_redirect_load gives
the redirects an exponential backoff:
if (peer->n_redirects == 0 ||
time_after(jiffies,
(peer->rate_last +
(ip_rt_redirect_load << peer->n_redirects)))) {
n_redirects grows until it reaches ip_rt_redirect_number, and both
redirect_number and redirect_load are plain proc_dointvec sysctls with
no upper bound. Set redirect_number past 32 and n_redirects climbs past
31, so "ip_rt_redirect_load << peer->n_redirects" shifts a 32-bit int by
>= 32 bits, which is UB:
UBSAN: shift-out-of-bounds in net/ipv4/route.c:949:6
shift exponent 32 is too large for 32-bit type 'int'
CPU: 1 UID: 0 PID: 1845 Comm: ping Not tainted 7.3.0-rc7+ #364 PREEMPT
Call Trace:
<IRQ>
dump_stack_lvl+0xc1/0xf0
dump_stack+0x10/0x20
__ubsan_handle_shift_out_of_bounds+0x1d1/0x390
ip_rt_send_redirect.cold+0x2c/0x146
ip_forward+0x1ddc/0x2430
ip_rcv+0x2b1/0x320
__netif_receive_skb_one_core+0x16b/0x1c0
__netif_receive_skb+0x21/0x150
process_backlog+0x37e/0x1200
__napi_poll.constprop.0+0xa5/0x5e0
net_rx_action+0x4c0/0xf70
Bounding redirect_number instead is not an option: 0 disables redirects
and -1 removes the cap. Compute the backoff in u64 with the shift count
capped at 31, which cannot overflow once ip_rt_redirect_load is
non-negative, and clamp the result to MAX_JIFFY_OFFSET: on 32-bit a
backoff of 2^31 or more is read by time_after() as already expired. This
keeps redirect_number as the limit on how many ICMP redirects are sent,
and the shift can no longer go out of bounds.
redirect_load on the other hand gets a lower bound of 0. A negative
backoff never meant anything, the old code only happened to treat it as
no backoff, and once converted to u64 it would turn into the maximum
backoff instead.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
net/ipv4/route.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 595a3b7f17830..f2c899f4cf8ca 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -907,6 +907,7 @@ void ip_rt_send_redirect(struct sk_buff *skb)
struct inet_peer *peer;
int log_martians;
struct net *net;
+ u64 backoff;
int vif;
rcu_read_lock();
@@ -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);
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);
@@ -3573,7 +3574,8 @@ static struct ctl_table ipv4_route_table[] = {
.data = &ip_rt_redirect_load,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec,
+ .proc_handler = proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
},
{
.procname = "redirect_number",
--
2.43.0
Technical Details
Message-ID:
<20261027104701.296240-3-jiayuan.chen@linux.dev>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352371-linux-kernel-netdev=dewy.ruReferences:
<20261027104701.296240-1-jiayuan.chen@linux.dev>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352371-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: [PATCH net v2 2/5] ipv4: fix shift-out-of-bounds in ip_rt_send_redirect() Date: Tue, 27 Oct 2026 18:45:30 +0800 Organization: Usenet Network Message-ID: <20261027104701.296240-3-jiayuan.chen@linux.dev> References: <20261027104701.296240-1-jiayuan.chen@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1516728"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:N9gonxZup85XgBVWKMywsig81X8= sha256:oxeyEQA/2UA76mB+zytY64g+ZhVbFJvrmb6GxbEpuwM= sha1:xuxlrIleU/3JxDCem3dQwD7EJSg= sha256:Ry7BsD2AkfCx+gVQ5Gk9B/fbG4JsxRMxUHOWBSr/oQQ= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 9D625125BEB; Tue, 27 Oct 2026 13:55:54 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.051 X-Spam-Status: No, score=-2.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HK_RANDOM_FROM=0.999, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1aOrC55MH_rF; Tue, 27 Oct 2026 13:55:53 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-352371-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id CDC8C125BEA; Tue, 27 Oct 2026 13:55:44 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id CA68220796; Tue, 27 Oct 2026 10:48:41 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793098119; b=MYeIimk8NEyj4xm5f7KyO/VLpuwG11RnIrb9OOGgVm4og39/AEez8HuDdDt8C28QxkIf C7MZiRaIDB4ls5zd7xioT4x8MpnoEo5HWcwkP82Jf40q9/L3ekjwJMmgvYoivkMuGp4q7 D+81iv90Ec9L5QdsHOKuFjy62MrN0FxwhRxkktaczJARMY6+ATLoBKwP3T0fX14KlInBz 1ZFdo8/UH44UTw5Hrhg/iK8jHaugqnv5BeeRLrD8AD9Oq5ezzLCmm3C1Lul53SNCgOtYL eCsiHZm0jiufD9VGQSZpEEvSWffJF6jBAxdtKGgTgc9XX0LXmqSwCTSHJXxxwJExkYA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793098119; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=Mt3Mq9SNW050+eWeZNF7XPUNXgUiqiP1/haRS99oyLQ=; b=Tf66PZqGQHfDx6a0nkkLAPARqXkWbLnqJqJ0q0toTAXf4JMgsRq+7jmjPCV+fdjIW6P7 JBGWezUGAFDYpFuSEgamHd8TXoAC/nJvAbrQaF/8s2HV/OKERuyNvnpALvCxWPbTM0SIN TDAMjwEh6us+5OmQtEvuAuloBKBowpt/PFUDzMYNwKpkwL31fEgfVXquO83W/jP0R4IV8 pjNIrAF7F5sTRmSEZEvGapaI5G1TQPP5pT4yVyzCamN/uvkyUQLMGLYsADBViuDKa5f6I ktkAz/JvzlGOPkw9JsiBYxRSkpYID3uqUUeq2fWTycrzXNi6ZQa3serNisKZDYuxtAA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fiQvg4Oo; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 20EBA606A32E; Tue, 27 Oct 2026 10:48:39 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fiQvg4Oo X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.246 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793098118; b=gBBePp+Uv5VZUURRbQpUDTc6mYH00iY4yU+i9S6UBVHUPFEjrjywmrbf8Qqs2cAp7kT8 P742S1zTWv0p+3aStKrhBr8G1DzTqRGhoczYT2ORJinqLfSnw45m8w74usIyHl4oUBcs5 ehRn9W6z29aXdSf+D+28RdHwsBKitgxx+lolvXnuPckxTRRL3sBIZAiwn7spRZCzclHSa acg+EGBMl7pw4MWD05Zm6U/UWMXbU8TrUr/U3FiXfgzlNTSq3ZE/0BHtDns5/PmKZf5uo mREcA0IR0cx5zTmoEgBTk6ub4izgKlHMhYCYHUhTJluVJh7s4FnPVLwamjVcWNeiyeg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793098118; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=Mt3Mq9SNW050+eWeZNF7XPUNXgUiqiP1/haRS99oyLQ=; b=t5NXzdCBIw3/rNNoSBMYQli5ck6hbFFw0mTsZQE/3zUtKqk+cs4yRyzuXYZ+WN4WF6vZ Qt22AkBlZIRenccEY8R+ACdGeEekRIsr8hdNUg64wN8JTeuX61BnI2X830TBSZrCqxCz/ vDKwOj2y0Y0zCNqm7nSTBYtg4sydu4UFJEN2KH+tdiXrmWvnVE3V363+Mra+R36pvvHrG jkhcF0f3JJPWr7o03kXrpLqjtVuqc3kiYK5RO5w8zDG7RH/aXz2QB5kbmcGYRQKTxks85 9j60ODf9yRpvPX9FgLSjVLgV8Go8WDGTkO+p2e1n/E1cfXFcRznpDbxUdq991SwJIRg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fiQvg4Oo; arc=none smtp.remote-ip=91.218.175.246 X-Received: from mta0.migadu.com (out-246.mta0.migadu.com [91.218.175.246]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37CCF606A31A for <netdev@vger.kernel.org>; Tue, 27 Oct 2026 10:48:36 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 37CCF606A31A X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=BlCR7qyhz1RBwYmpMqZM4257yNl/7pbJi2t5We+ivQE=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793098115; v=1; x=1793702915; b=fiQvg4Ooic/RPRsTW3Tfh0uKJmnZuZqp69gN3cvhQ3DDi1b8gcXIkFyW+By7MLk9ADAKwvBi 9J40xxh7KAGn1EfjVXZehjZVlMyfzx/9c39I5avVGDRbhdFmitjNmgOi0mq9oybZ4jrYjU+s73Q wqRVuHALuN4f9FmjysKrtmcA= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 65688ab5fc1ffcf3; Tue, 27 Oct 2026 10:48:35 +0000 X-Mizu-Trace-ID: 65688ab5fc1ffcf3 X-Migadu-Flow: FLOW_OUT X-Cc: Jiayuan Chen <jiayuan.chen@linux.dev>, stable@vger.kernel.org, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, Jonathan Corbet <corbet@lwn.net>, Shuah Khan <skhan@linuxfoundation.org>, Randy Dunlap <rdunlap@infradead.org>, David Ahern <dsahern@kernel.org>, Ido Schimmel <idosch@nvidia.com>, Thomas Gleixner <tglx@kernel.org>, Joel Granados <joel.granados@kernel.org>, Petr Pavlu <petr.pavlu@suse.com>, Kuniyuki Iwashima <kuniyu@google.com>, Fernando Fernandez Mancera <fmancera@suse.de>, Willem de Bruijn <willemb@google.com>, Maoyi Xie <maoyi.xie@ntu.edu.sg>, Daniel J Blueman <daniel@quora.org>, Jiri Wiesner <jwiesner@suse.de>, Gerd Rausch <gerd.rausch@oracle.com>, Oleg Nesterov <oleg@redhat.com>, Chia-Yu Chang <chia-yu.chang@nokia-bell-labs.com>, Wyatt Feng <bronzed_45_vested@icloud.com>, Yung Chih Su <yuuchihsu@gmail.com>, Hannes Frederic Sowa <hannes@stressinduktion.org>, Flavio Leitner <fbl@redhat.com>, Petr Mladek <pmladek@suse.com>, "Paul E. McKenney" <paulmck@kernel.org>, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: git-send-email 2.43.0 X-In-Reply-To: <20261027104701.296240-1-jiayuan.chen@linux.dev> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list