From: Tristan Madani <tristmd@gmail.com>
To: Jon Maloy <jmaloy@redhat.com>,
Tung Quang Nguyen <tung.quang.nguyen@est.tech>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: Richard Alpe <richard.alpe@ericsson.com>,
Ying Xue <ying.xue@windriver.com>,
Erik Hugne <erik.hugne@ericsson.com>,
netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org,
Tristan Madani <tristan@talencesecurity.com>
Subject: [PATCH net] tipc: fix division by zero in perc()
Date: Tue, 3 Nov 2026 22:54:33 +0000 [thread overview]
Message-ID: <20261103225433.2663943-1-tristmd@gmail.com> (raw)
From: Tristan Madani <tristan@talencesecurity.com>
The perc() function divides count by total without checking whether
total is zero. When link statistics are queried on a freshly
established link that has not yet exchanged messages,
TIPC_NLA_STATS_MSG_PROF_TOT is zero, causing a division by zero
in tipc_nl_compat_link_stat_dump().
Add a zero check to return 0 when total is zero.
Fixes: f2b3b2d4ccbf ("tipc: convert legacy nl link stat to nl compat")
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
net/tipc/netlink_compat.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c
index d9a4f94ea2d43..75f3193a2a6cf 100644
--- a/net/tipc/netlink_compat.c
+++ b/net/tipc/netlink_compat.c
@@ -497,6 +497,9 @@ static int tipc_nl_compat_bearer_disable(struct tipc_nl_compat_cmd_doit *cmd,
static inline u32 perc(u32 count, u32 total)
{
+ if (!total)
+ return 0;
+
return (count * 100 + (total / 2)) / total;
}
--
2.47.3
next reply other threads:[~2026-11-03 22:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 22:54 Tristan Madani [this message]
2026-11-03 22:58 ` netdev-bot+sinfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261103225433.2663943-1-tristmd@gmail.com \
--to=tristmd@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=erik.hugne@ericsson.com \
--cc=horms@kernel.org \
--cc=jmaloy@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richard.alpe@ericsson.com \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=tristan@talencesecurity.com \
--cc=tung.quang.nguyen@est.tech \
--cc=ying.xue@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®