From: Dave Seddon <dave.seddon.ca@gmail.com>
To: netdev@vger.kernel.org
Cc: Dave Seddon <dave.seddon.ca@gmail.com>,
Stephen Hemminger <stephen@networkplumber.org>,
David Ahern <dsahern@kernel.org>,
Jamal Hadi Salim <jhs@mojatatu.com>
Subject: [PATCH iproute2 4/5] lib: reject a time that does not fit the result type
Date: Wed, 2 Dec 2026 22:40:13 -0800 [thread overview]
Message-ID: <20261203064014.2272012-5-dave.seddon.ca@gmail.com> (raw)
In-Reply-To: <20261203064014.2272012-1-dave.seddon.ca@gmail.com>
Return an error from get_time(), get_time64() and get_time_rtt() when
the parsed time does not fit the result, and from the first two when it
is not a number. Today
# tc qdisc add dev lo root fq_codel target 5000s
# ip route add 198.51.100.0/24 dev lo rto_min 5000000s
install "target 705s" and "rto_min lock 705033s", and
# tc qdisc add dev lo root fq_codel target nan
is accepted and installs the default target.
LLONG_MAX rounds to 2^63 as a double, so get_time64() rejects equality
as well. get_time() truncates and get_time_rtt() rounds up, hence the
different 32-bit limits. The cast in get_time() is needed: UINT_MAX + 1
is 0 in unsigned arithmetic. floor() is not used there, as lib/utils.c
is linked into ip and others without -lm.
get_time_rtt() cannot see NaN: a string without a '.' is parsed by
strtoul(), and one with a '.' leaves a suffix that is not a time unit.
Fixes: 54e0b2e71d72 ("rto support for ip command")
Fixes: abf70ef494fd ("tc: support conversions to or from 64 bit nanosecond-based time")
Signed-off-by: Dave Seddon <dave.seddon.ca@gmail.com>
---
lib/utils.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lib/utils.c b/lib/utils.c
index f4bd53ff..7314f5b9 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -307,6 +307,9 @@ int get_time_rtt(unsigned int *val, const char *arg, int *raw)
return -1;
}
+ if (t > UINT_MAX)
+ return -1;
+
/* emulate ceil() without having to bring-in -lm and always be >= 1 */
*val = t;
if (*val < t)
@@ -1722,6 +1725,9 @@ int get_time(unsigned int *time, const char *str)
return -1;
}
+ if (isnan(t) || t >= (double)UINT_MAX + 1)
+ return -1;
+
*time = t;
return 0;
}
@@ -1781,6 +1787,9 @@ int get_time64(__s64 *time, const char *str)
return -1;
}
+ if (isnan(nsec) || nsec >= (double)LLONG_MAX)
+ return -1;
+
*time = nsec;
return 0;
}
--
2.56.0
next prev parent reply other threads:[~2026-12-03 6:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 6:40 [PATCH iproute2 0/5] reject rates, sizes and times that overflow or are NaN Dave Seddon
2026-12-03 6:40 ` [PATCH iproute2 1/5] lib: get_rate64: reject overflow and NaN Dave Seddon
2026-12-03 6:40 ` [PATCH iproute2 2/5] lib: get_size: do not copy the size out when get_size64() fails Dave Seddon
2026-12-03 6:40 ` [PATCH iproute2 3/5] lib: test for overflow before converting a rate or size Dave Seddon
2026-12-03 6:40 ` Dave Seddon [this message]
2026-12-03 6:40 ` [PATCH iproute2 5/5] ip route: reject an rtt or rttvar that overflows when scaled Dave Seddon
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=20261203064014.2272012-5-dave.seddon.ca@gmail.com \
--to=dave.seddon.ca@gmail.com \
--cc=dsahern@kernel.org \
--cc=jhs@mojatatu.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/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