From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C915FC05027 for ; Mon, 20 Feb 2023 13:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232474AbjBTNwq (ORCPT ); Mon, 20 Feb 2023 08:52:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232480AbjBTNwp (ORCPT ); Mon, 20 Feb 2023 08:52:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 229711E9C7 for ; Mon, 20 Feb 2023 05:52:44 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AC32D60B74 for ; Mon, 20 Feb 2023 13:52:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD5CBC433D2; Mon, 20 Feb 2023 13:52:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1676901163; bh=tS3Dpnw4Tx4Yhk3jexrVbEFIOFLxLrRmSiNjFaY7tjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=scM92rXfey5A7FCkxi1YYJLYCyacsLk8uvrQCu0dmYkiUfvCaMkfv6/9iJ3G07coH hL4hK3Npn4hozA5EWiOrhH14UGyEZexs3mkRHHhMnA5vN+IPbEh0fdfYiV/dzE8y6W pU92bnqjvNlCeR8LoWcOHqJn4qsmQ9wwjzWCHwqc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Felix Riemann , Eric Dumazet , "David S. Miller" Subject: [PATCH 5.15 53/83] net: Fix unwanted sign extension in netdev_stats_to_stats64() Date: Mon, 20 Feb 2023 14:36:26 +0100 Message-Id: <20230220133555.523277845@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230220133553.669025851@linuxfoundation.org> References: <20230220133553.669025851@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Felix Riemann commit 9b55d3f0a69af649c62cbc2633e6d695bb3cc583 upstream. When converting net_device_stats to rtnl_link_stats64 sign extension is triggered on ILP32 machines as 6c1c509778 changed the previous "ulong -> u64" conversion to "long -> u64" by accessing the net_device_stats fields through a (signed) atomic_long_t. This causes for example the received bytes counter to jump to 16EiB after having received 2^31 bytes. Casting the atomic value to "unsigned long" beforehand converting it into u64 avoids this. Fixes: 6c1c5097781f ("net: add atomic_long_t to net_device_stats fields") Signed-off-by: Felix Riemann Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10646,7 +10646,7 @@ void netdev_stats_to_stats64(struct rtnl BUILD_BUG_ON(n > sizeof(*stats64) / sizeof(u64)); for (i = 0; i < n; i++) - dst[i] = atomic_long_read(&src[i]); + dst[i] = (unsigned long)atomic_long_read(&src[i]); /* zero out counters that only exist in rtnl_link_stats64 */ memset((char *)stats64 + n * sizeof(u64), 0, sizeof(*stats64) - n * sizeof(u64));