From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58DEB2522B4; Tue, 29 Apr 2025 17:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745948693; cv=none; b=TIyshCkvVe9mIybG3TPc4igwRpAYw4dK/KmbqZ7ar2O55IexRx10Ll/l4unmaNKkPrfiQVFmZdkAbX5omD94yi7M60rEbtfIOKAXC+93e5EFPbiafp/Vnmq5jSDaGUjV+afk93bq4u369MODL9MSIqNDRTSEyXgGt5sH/p6wakU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745948693; c=relaxed/simple; bh=/l2shZ+SdeLfm2NfjGal5s38AzlsZG8DIMWT40cN+Qs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OcU+f1u9fbet0ETP8NFmYognMVa+sSInIKhZnuziUq4n0NMg/2aoPt+KLFmtWB02Vg8nkY5wmVVDLm74UdEK6asOautYVKe/hlBpLxyU4uNn71UupkAAFMz17Z/NpOtBs5CFzLm6AwaJbHk7J+OO6zn1WzQ/dWyZVP/Gn07vsJo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qq72eomZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qq72eomZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7A47C4CEE3; Tue, 29 Apr 2025 17:44:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745948693; bh=/l2shZ+SdeLfm2NfjGal5s38AzlsZG8DIMWT40cN+Qs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qq72eomZyk6R/FxB6bhsod9+zRfuVz3Uy4dogkZI+trdPyz56xzRSi/k/8xoLDF36 /tPZsfRhhhmOW7fqv8tlzJUVNpRHxNEk0J/AzgxOU2R26pmYnQIE89a+cqXpA29BAc pw3+4JQuQF8/gF3Ja2bu/1frbwUzUsnwxy3FM+Cs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ilia Gavrilov , Johannes Berg Subject: [PATCH 5.15 083/373] wifi: mac80211: fix integer overflow in hwmp_route_info_get() Date: Tue, 29 Apr 2025 18:39:20 +0200 Message-ID: <20250429161126.564773859@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161123.119104857@linuxfoundation.org> References: <20250429161123.119104857@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gavrilov Ilia commit d00c0c4105e5ab8a6a13ed23d701cceb285761fa upstream. Since the new_metric and last_hop_metric variables can reach the MAX_METRIC(0xffffffff) value, an integer overflow may occur when multiplying them by 10/9. It can lead to incorrect behavior. Found by InfoTeCS on behalf of Linux Verification Center (linuxtesting.org) with SVACE. Fixes: a8d418d9ac25 ("mac80211: mesh: only switch path when new metric is at least 10% better") Cc: stable@vger.kernel.org Signed-off-by: Ilia Gavrilov Link: https://patch.msgid.link/20250212082124.4078236-1-Ilia.Gavrilov@infotecs.ru Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/mac80211/mesh_hwmp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/net/mac80211/mesh_hwmp.c +++ b/net/mac80211/mesh_hwmp.c @@ -360,6 +360,12 @@ u32 airtime_link_metric_get(struct ieee8 return (u32)result; } +/* Check that the first metric is at least 10% better than the second one */ +static bool is_metric_better(u32 x, u32 y) +{ + return (x < y) && (x < (y - x / 10)); +} + /** * hwmp_route_info_get - Update routing info to originator and transmitter * @@ -450,8 +456,8 @@ static u32 hwmp_route_info_get(struct ie (mpath->sn == orig_sn && (rcu_access_pointer(mpath->next_hop) != sta ? - mult_frac(new_metric, 10, 9) : - new_metric) >= mpath->metric)) { + !is_metric_better(new_metric, mpath->metric) : + new_metric >= mpath->metric))) { process = false; fresh_info = false; } @@ -521,8 +527,8 @@ static u32 hwmp_route_info_get(struct ie if ((mpath->flags & MESH_PATH_FIXED) || ((mpath->flags & MESH_PATH_ACTIVE) && ((rcu_access_pointer(mpath->next_hop) != sta ? - mult_frac(last_hop_metric, 10, 9) : - last_hop_metric) > mpath->metric))) + !is_metric_better(last_hop_metric, mpath->metric) : + last_hop_metric > mpath->metric)))) fresh_info = false; } else { mpath = mesh_path_add(sdata, ta);