All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2 v2] ip: Fix size_columns() invocation that passes a 32-bit quantity
@ 2022-06-28 10:17 Petr Machata
  2022-07-05 16:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Machata @ 2022-06-28 10:17 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Stephen Hemminger, Petr Machata

In print_stats64(), the last size_columns() invocation passes number of
carrier changes as one of the arguments. The value is decoded as a 32-bit
quantity, but size_columns() expects a 64-bit one. This is undefined
behavior.

The reason valgrind does not cite this is that the previous size_columns()
invocations prime the ABI area used for the value transfer. When these
other invocations are commented away, valgrind does complain that
"conditional jump or move depends on uninitialised value", as would be
expected.

Fixes: 49437375b6c1 ("ip: dynamically size columns when printing stats")
Signed-off-by: Petr Machata <petrm@nvidia.com>
---

Notes:
    v2:
    - Use a temporary to hold the number of carrier changes.

 ip/ipaddress.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 5a3b1cae..a288341c 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -783,13 +783,15 @@ void print_stats64(FILE *fp, struct rtnl_link_stats64 *s,
 			     s->tx_bytes, s->tx_packets, s->tx_errors,
 			     s->tx_dropped, s->tx_carrier_errors,
 			     s->collisions, s->tx_compressed);
-		if (show_stats > 1)
+		if (show_stats > 1) {
+			uint64_t cc = carrier_changes ?
+				      rta_getattr_u32(carrier_changes) : 0;
+
 			size_columns(cols, ARRAY_SIZE(cols), 0, 0,
 				     s->tx_aborted_errors, s->tx_fifo_errors,
 				     s->tx_window_errors,
-				     s->tx_heartbeat_errors,
-				     carrier_changes ?
-				     rta_getattr_u32(carrier_changes) : 0);
+				     s->tx_heartbeat_errors, cc);
+		}
 
 		/* RX stats */
 		fprintf(fp, "    RX: %*s %*s %*s %*s %*s %*s %*s%s",
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2 v2] ip: Fix size_columns() invocation that passes a 32-bit quantity
  2022-06-28 10:17 [PATCH iproute2 v2] ip: Fix size_columns() invocation that passes a 32-bit quantity Petr Machata
@ 2022-07-05 16:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-05 16:20 UTC (permalink / raw)
  To: Petr Machata; +Cc: netdev, dsahern, stephen

Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Tue, 28 Jun 2022 12:17:31 +0200 you wrote:
> In print_stats64(), the last size_columns() invocation passes number of
> carrier changes as one of the arguments. The value is decoded as a 32-bit
> quantity, but size_columns() expects a 64-bit one. This is undefined
> behavior.
> 
> The reason valgrind does not cite this is that the previous size_columns()
> invocations prime the ABI area used for the value transfer. When these
> other invocations are commented away, valgrind does complain that
> "conditional jump or move depends on uninitialised value", as would be
> expected.
> 
> [...]

Here is the summary with links:
  - [iproute2,v2] ip: Fix size_columns() invocation that passes a 32-bit quantity
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=329fda186156

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-05 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28 10:17 [PATCH iproute2 v2] ip: Fix size_columns() invocation that passes a 32-bit quantity Petr Machata
2022-07-05 16:20 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.