From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f42.google.com (mail-yx1-f42.google.com [74.125.224.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2312A1C5D5E for ; Mon, 17 Aug 2026 01:32:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786930362; cv=none; b=rorof/M8Fwl+OEN8ObHMEphNw4V7Kgkke9ZM0w1x419zyEUMYPaT3Weku8jL6J6C3ftfJPUFdrqQE7hw/Ci7G8bX7+n7Cu6KeXaQWqqHxuE6YB4fuUV2CqC2cRQdHDNjP6vLODShfLyozFhmA+SqFL+1oObczuLf3UTemuWmJ0o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786930362; c=relaxed/simple; bh=5zxpqjA/kx3Wtv66dk33OanKoqsL0EUGG3wmTXXwJk8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FjrJvNKQ9eQH7dGaANAqLINzbNSPscJYY50TPLN5HCpqG+rR7oCLdfWIxcqOErQmC/4+wXyliiyv1QzOAiFZQMjyR4y8n62UvuEkp1skR6dj208q05ltiOIoQdmylHSUcM37QzA/BJvlSQAgGYDA9uZQ3rawtSeVkSQxGyMFQk8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ui8SLDCP; arc=none smtp.client-ip=74.125.224.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ui8SLDCP" Received: by mail-yx1-f42.google.com with SMTP id 956f58d0204a3-66b35d2c4edso4109446d50.2 for ; Sun, 16 Aug 2026 18:32:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786930360; x=1787535160; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=3WhukOejwBNTxs5CHVlgLm9bRECOcG8xzg7md60tu1g=; b=Ui8SLDCPHMKVm/8I3kkwBFlwS2dRnZ1tXtxuehpTwVhVl3MjqOiHZuLQeqFT2FHA29 SamRCJJt3HSId8U2cRdABPW+8FURtUJwNUue9/d3PBqD8IgbJ9SKYhNuuAnD8UBcuq+k CbsBLKf3WLwLmqXkXdNOG+Qo/9uRHrCtYrhYN75DhJvzrt9dXiFYEFpuKjPb3bC3MVWz rqj2G7mz5r/5/KXRBlEEr+lLgVuzHkUrOqRxXYDfUNXcEqQU+rcWe+OhAbIH50r6knxT vw48hnSp8eM38DaToGgySEwMrMM3Mp8R5NeD02jcFs30sxm6CVyySh4ZhxSbf1ctLUoK 34QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786930360; x=1787535160; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3WhukOejwBNTxs5CHVlgLm9bRECOcG8xzg7md60tu1g=; b=bPjtJCUDhrRBhEmj9A8wgrz0opAm8C7A79loKAWZgsYL3Aq+quvG+noZNIN0mKVS+f Y5M/O43IwNOsPlQZqVPyvHOOeDgv+OsYrvFZ/kq+zPz2taEGZ2Ep74VxsaO38rnim2lp UTRAWKHlaNgrj7yAdUFoosaPdqyClnyHHUVoCPeKFmYHZqtd1HxDWKT5NtPbn+L6xAaD IYxU3yDIVxQtLiFuxNEVrJT0qAwz27HBx9DsM/nHrMJ0F7ozXawVSzt8y1YtqdzmKjcD jcZInw0CHJe6CaH5LAQYnn/Wg5SaPuqbBCCXWec7kNW4jnz94tja03ZTx057tsRgP/Qe 9Eiw== X-Forwarded-Encrypted: i=1; AHgh+Ro2sFbZtTOP613OMQBE+GVlcvCYCsQfnogogfPlop50LrM2XhMYag0Fv2zXcQrTvmeBK97iWYwdAW5tsPQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwL7yFasqA/J27DgdKVUsmIkMtoRbI+Psg1iMgITO32KpE4SGCG uRKBMLkolhxOTaBOEDpip+srrQGwrljTWol2G6++N76/dYRyuy8iHhdS X-Gm-Gg: AR+sD10j/s23K11oPia5g67aoEnpRwWrBvrDlaI3tyuk3QV5zSAu8rKJjw54PMUF2QA /u+GMUvQB2FhDHTP5C2bEZZDwWLqvJj6wh50pW6YNsP2mti9/bixhLiAB9O2R9yiR09gQBnF/YE pKyAbSRmYqYY13I9JhaEnLU5MTWEpbK+3fh4NX5dZNF2RgG8ikdTLPE62D0dhjwlPzPSn6Rghqx cPsQ/hYedmq2fgbKUjmjOS8OOykCp5QINyzb6xgusj3gAb+iGzCApepFXvSswnK4JbvoGrOTuAo Inl+k1hewobaQYThvVXxyl76DGfxFwlIs/CLQyYOUjwWH36vjznSWwhFceKeBIsDPWdw33O1leS cpTT4eiGbJ8wibcYg4i6nMvCFubihp5gmRc7q5gce5oBrcCHrIK/Eg/iiPYPRs/peohVaZfcG7x Kx23w32JC631FWwcE3D6W02wUZNYKiSRzuD/XAlSpt5FxKMT0K8iWWfbN/BytmkeBtAMc= X-Received: by 2002:a05:690e:58a:b0:66c:4ce5:834 with SMTP id 956f58d0204a3-66c7259d0a8mr5823711d50.0.1786930360064; Sun, 16 Aug 2026 18:32:40 -0700 (PDT) Received: from mac.lan ([136.55.173.105]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-66cb41e4389sm28728d50.6.2026.08.16.18.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 18:32:39 -0700 (PDT) From: "Cen Zhang (Microsoft)" To: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: horms@kernel.org, kuniyu@google.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, AutonomousCodeSecurity@microsoft.com, xmei5@asu.edu, tgopinath@linux.microsoft.com, kys@microsoft.com, blbllhy@gmail.com Subject: [PATCH net] ipv6: avoid divide by zero in rt6_multipath_rebalance Date: Sun, 16 Aug 2026 21:32:37 -0400 Message-ID: <20260817013237.2797-1-blbllhy@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit rt6_multipath_rebalance() calculates the total eligible nexthop weight in one pass and programs upper bounds in a second pass. Since RTM_NEWROUTE is RTNL-free, a concurrent ignore_routes_with_linkdown update can make the first pass return zero while the second sees an eligible nexthop, causing rt6_upper_bound_set() to divide by zero. UBSAN: division-overflow in net/ipv6/route.c:4845:17 Oops: divide error: 0000 [#1] SMP KASAN NOPTI rt6_upper_bound_set() net/ipv6/route.c:4845 rt6_multipath_rebalance() fib6_add_rt2node() ip6_route_multipath_add() inet6_rtm_newroute() Skip upper-bound calculation when the first pass reports a zero total. This respects the lock-free performance considerations here and solves insecure scenarios. Fixes: bd11ff421d36 ("ipv6: Get rid of RTNL for SIOCDELRT and RTM_DELROUTE.") Reported-by: AutonomousCodeSecurity@microsoft.com Reported-by: Xiang Mei (Microsoft) Reported-by: Cen Zhang (Microsoft) Signed-off-by: Cen Zhang (Microsoft) --- net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 5968ce5ad150..68924cff9205 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4840,7 +4840,7 @@ static void rt6_upper_bound_set(struct fib6_info *rt, int *weight, int total) { int upper_bound = -1; - if (!rt6_is_dead(rt)) { + if (total && !rt6_is_dead(rt)) { *weight += rt->fib6_nh->fib_nh_weight; upper_bound = DIV_ROUND_CLOSEST_ULL((u64) (*weight) << 31, total) - 1; -- 2.52.0