lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251011222829.25295-1-zengyijing19900106@gmail.com>
Date: Sat, 11 Oct 2025 15:25:24 -0700
From: Yijing Zeng <zengyijing19900106@...il.com>
To: netdev@...r.kernel.org
Cc: stephen@...workplumber.org,
	me@...chata.org,
	kuba@...nel.org,
	yijingzeng@...a.com
Subject: [PATCH v2] dcb: fix tc-maxrate unit conversions

From: Yijing Zeng <yijingzeng@...a.com>

The ieee_maxrate UAPI is defined as kbps, but dcb_maxrate uses Bps.
This fix patch converts Bps to kbps for parse by dividing 125,
and convert kbps to Bps for print_rate() by multiplying 125.

Fixes: 117939d9bd89 ("dcb: Add a subtool for the DCB maxrate object")
Signed-off-by: Yijing Zeng <yijingzeng@...a.com>
---
v2:
  - Address style comments
  - Avoid potential overflow

 dcb/dcb_maxrate.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/dcb/dcb_maxrate.c b/dcb/dcb_maxrate.c
index 1538c6d7..8c5a7e55 100644
--- a/dcb/dcb_maxrate.c
+++ b/dcb/dcb_maxrate.c
@@ -42,13 +42,20 @@ static void dcb_maxrate_help(void)
 
 static int dcb_maxrate_parse_mapping_tc_maxrate(__u32 key, char *value, void *data)
 {
-	__u64 rate;
+	__u64 rate_bytes_per_sec;
+	__u64 rate_kbits_per_sec;
 
-	if (get_rate64(&rate, value))
+	if (get_rate64(&rate_bytes_per_sec, value))
 		return -EINVAL;
 
+	/* get_rate64() returns Bps.
+	 * ieee_maxrate UAPI expects kbps.
+	 * convert Bps to kbps by dividing 125.
+	 */
+	rate_kbits_per_sec = rate_bytes_per_sec / 125;
+
 	return dcb_parse_mapping("TC", key, IEEE_8021QAZ_MAX_TCS - 1,
-				 "RATE", rate, -1,
+				 "RATE", rate_kbits_per_sec, -1,
 				 dcb_set_u64, data);
 }
 
@@ -62,8 +69,14 @@ static void dcb_maxrate_print_tc_maxrate(struct dcb *dcb, const struct ieee_maxr
 	print_string(PRINT_FP, NULL, "tc-maxrate ", NULL);
 
 	for (i = 0; i < size; i++) {
+		/* ieee_maxrate UAPI returns kbps.
+		 * print_rate() expects Bps for display.
+		 * convert kbps to Bps by multiplying 125.
+		 */
+		__u64 rate_bytes_per_sec  = maxrate->tc_maxrate[i] * 125;
+
 		snprintf(b, sizeof(b), "%zd:%%s ", i);
-		print_rate(dcb->use_iec, PRINT_ANY, NULL, b, maxrate->tc_maxrate[i]);
+		print_rate(dcb->use_iec, PRINT_ANY, NULL, b, rate_bytes_per_sec);
 	}
 
 	close_json_array(PRINT_JSON, "tc_maxrate");
-- 
2.50.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ