Skip to content

Commit 8dafd32

Browse files
shemmingergregkh
authored andcommitted
net/sched: netem: check for negative latency and jitter
[ Upstream commit 90be9fe ] Reject requests with negative latency or jitter. A negative value added to current timestamp (u64) wraps to an enormous time_to_send, disabling dequeue. The original UAPI used u32 for these values; the conversion to 64-bit time values via TCA_NETEM_LATENCY64 and TCA_NETEM_JITTER64 allowed signed values to reach the kernel without validation. Jitter is already silently clamped by an abs() in netem_change(); that abs() can be removed in a follow-up once this rejection is in place. Fixes: 9980317 ("netem: add uapi to express delay and jitter in nanoseconds") Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20260418032027.900913-7-stephen@networkplumber.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ffb40e6 commit 8dafd32

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

net/sched/sch_netem.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,16 @@ static int get_dist_table(struct disttable **tbl, const struct nlattr *attr)
824824
return 0;
825825
}
826826

827+
static int validate_time(const struct nlattr *attr, const char *name,
828+
struct netlink_ext_ack *extack)
829+
{
830+
if (nla_get_s64(attr) < 0) {
831+
NL_SET_ERR_MSG_ATTR_FMT(extack, attr, "negative %s", name);
832+
return -EINVAL;
833+
}
834+
return 0;
835+
}
836+
827837
static int validate_slot(const struct nlattr *attr, struct netlink_ext_ack *extack)
828838
{
829839
const struct tc_netem_slot *c = nla_data(attr);
@@ -1066,6 +1076,18 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt,
10661076
goto table_free;
10671077
}
10681078

1079+
if (tb[TCA_NETEM_LATENCY64]) {
1080+
ret = validate_time(tb[TCA_NETEM_LATENCY64], "latency", extack);
1081+
if (ret)
1082+
goto table_free;
1083+
}
1084+
1085+
if (tb[TCA_NETEM_JITTER64]) {
1086+
ret = validate_time(tb[TCA_NETEM_JITTER64], "jitter", extack);
1087+
if (ret)
1088+
goto table_free;
1089+
}
1090+
10691091
sch_tree_lock(sch);
10701092
/* backup q->clg and q->loss_model */
10711093
old_clg = q->clg;

0 commit comments

Comments
 (0)