From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.247 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792746922; b=5lsVVNspvXmDdtABC09A7WAtK6zVOwAUvrKoKidZ2aYNLC1okNltc4OHxBmherVqOXFU uAG+rQ0Ws9laXo5IExvLqkZxepf5Wkz2U8GyC276bbsflHr5TlWQCdlOsmCWsL4BTPUpN +GaJZjWdb2pyIakJr1pCvgtF7M0FkOFw1irHF3+6389BUb9/SYcPemDSaW0LtyyYf25nx NNh/xM6b52JI1Y8wzOaT11AmTAGRiUTfTuvYQ9S8/JSzOW2I6hcnDVfyhJ6CNOqyeFeL5 dpVdA4dANwtmgZMazx4vSqZYfsQCo/LzNB1uDxLDjqjyXVu5dWqPQQ/FDDqFZN6FyRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792746922; 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=oxLJBo5kiejXWGJthd7cBd7kiiHHZ3kDKL/3z8bFmws=; b=hM3S3dR9XGqgq4zj+eZm+34Kufz2OgXzTgouESp38t9q4VlP2bXFX7IRgr4W5+K6D87r uOU/NWBo8xDDcinmK3ukuWEiggxRFvEtl+D5b9bexRAIzkO67opUOmiYXui9ozw/7Q6JV 6zy6BEHkr9yM8gO3qurzEgXgqW9DmqDCW7JhhPQtFbgGMLSLCr/1MLsL9onM940tydFBD rmeLq1uFi1bnMTwVkAuGS4vqG7jHIbRkBuTj1avD7cH+YEk7spnh7fRyDwqXX+w+ePBdd OV20QJY7V7lmjM8qbVJhdMuq5MeMEtS6iFNgDkuGJS4yJTOeEP3kFwTIvJ9E45h1CLw== 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=CPJaLoLs; arc=none smtp.remote-ip=91.218.175.247 Received: from mta0.migadu.com (out-247.mta0.migadu.com [91.218.175.247]) (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 11039606A31B for ; Fri, 23 Oct 2026 09:15:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 11039606A31B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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=CPJaLoLs X-Envelope-To: netdev@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=rGi6OLiAd6zKc4y/mbTm5VOHf7DVCMJfKD3folF6xio=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1792746920; v=1; x=1793351720; b=CPJaLoLsvy0qxnDLYfyHz9iWfSQSVu0Rpmg9StkqxK0JfN8Jgj5febrYfRxsRvh0h5/KNYDP i/64HDS2n2f+Oiv5jrffc9H0THIOjwuWDCHd2itXZHt5QtNarZf6JWXwWnCOEmUG3Dfgc4+/reM MVbkA670VlUPHReBTfCwDpOU= X-Envelope-To: netdev@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 117f44c2f1bf2234; Fri, 23 Oct 2026 09:15:19 +0000 X-Mizu-Trace-ID: 117f44c2f1bf2234 X-Migadu-Flow: FLOW_OUT From: Jiayuan Chen To: netdev@vger.kernel.org Cc: Jiayuan Chen , stable@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , David Ahern , Ido Schimmel , Kuniyuki Iwashima , Joel Granados , Chia-Yu Chang , Fernando Fernandez Mancera , Wyatt Feng , Yung Chih Su , Hannes Frederic Sowa , Flavio Leitner , "Paul E. McKenney" , Petr Mladek , linux-kernel@vger.kernel.org Subject: [PATCH net 2/5] ipv4: fix shift-out-of-bounds in ip_rt_send_redirect() Date: Fri, 23 Oct 2026 17:13:28 +0800 Message-ID: <20261023091419.167088-3-jiayuan.chen@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261023091419.167088-1-jiayuan.chen@linux.dev> References: <20261023091419.167088-1-jiayuan.chen@linux.dev> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 only stops growing when 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: 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 Fixing this from the sysctl side would mean bounding both knobs, e.g. redirect_load to [0, 65535] and redirect_number to [0, 16], which gets in the way of users who legitimately do not want to cap ICMP redirects. Instead compute the backoff in u64 with the shift count capped at 31, which cannot overflow since ip_rt_redirect_load is an int, and clamp the result to MAX_JIFFY_OFFSET. The clamp also fixes 32-bit kernels, where the same expression goes wrong long before the shift count reaches 32. With the default ip_rt_redirect_load of 20, from n_redirects == 27 on the result is either truncated or too large for time_after(), which then treats the deadline as already passed, and from 30 on it is 0, so every forwarded packet gets a redirect again until ip_rt_redirect_number is reached. This needs a raised redirect_silence to be reachable, otherwise n_redirects is reset long before. On 64-bit, ip_rt_redirect_load << 31 stays below MAX_JIFFY_OFFSET, so nothing changes there. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Jiayuan Chen --- net/ipv4/route.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 595a3b7f1783..76807b757046 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); -- 2.43.0