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 88D0B63BB for ; Mon, 20 Feb 2023 13:59:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E733BC433EF; Mon, 20 Feb 2023 13:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1676901590; bh=x6hnhaPR7ioJYdKBVfvihnjZzekB0F8wDYU6GtzGhuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qlh5T87f5CZItzkqOto227qixwqhv/4dZidz4MfLpD4LsbOHVtXVkEH5YavaTwU1y ew8G3Bao0nlO/PbMBT8tS4FuDvBCoW4IJmaiPxaXN07IjZGafUvtUemTil3ZR9Pdu5 PAGNURoHO4XydQv1te9Fi3dMLzqpfxNFhYGEKtVA= 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 6.1 076/118] net: Fix unwanted sign extension in netdev_stats_to_stats64() Date: Mon, 20 Feb 2023 14:36:32 +0100 Message-Id: <20230220133603.459545457@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230220133600.368809650@linuxfoundation.org> References: <20230220133600.368809650@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 @@ -10385,7 +10385,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));