Skip to content

Commit a2b1a5d

Browse files
peilin-yekuba-moo
authored andcommitted
net/sched: sch_netem: Fix arithmetic in netem_dump() for 32-bit platforms
As reported by Yuming, currently tc always show a latency of UINT_MAX for netem Qdisc's on 32-bit platforms: $ tc qdisc add dev dummy0 root netem latency 100ms $ tc qdisc show dev dummy0 qdisc netem 8001: root refcnt 2 limit 1000 delay 275s 275s ^^^^^^^^^^^^^^^^ Let us take a closer look at netem_dump(): qopt.latency = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->latency, UINT_MAX); qopt.latency is __u32, psched_tdiff_t is signed long, (psched_tdiff_t)(UINT_MAX) is negative for 32-bit platforms, so qopt.latency is always UINT_MAX. Fix it by using psched_time_t (u64) instead. Note: confusingly, users have two ways to specify 'latency': 1. normally, via '__u32 latency' in struct tc_netem_qopt; 2. via the TCA_NETEM_LATENCY64 attribute, which is s64. For the second case, theoretically 'latency' could be negative. This patch ignores that corner case, since it is broken (i.e. assigning a negative s64 to __u32) anyways, and should be handled separately. Thanks Ted Lin for the analysis [1] . [1] raspberrypi/linux#3512 Reported-by: Yuming Chen <[email protected]> Fixes: 112f9cb ("netem: convert to qdisc_watchdog_schedule_ns") Reviewed-by: Cong Wang <[email protected]> Signed-off-by: Peilin Ye <[email protected]> Acked-by: Stephen Hemminger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a3bb7b6 commit a2b1a5d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/sched/sch_netem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,9 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
11461146
struct tc_netem_rate rate;
11471147
struct tc_netem_slot slot;
11481148

1149-
qopt.latency = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->latency),
1149+
qopt.latency = min_t(psched_time_t, PSCHED_NS2TICKS(q->latency),
11501150
UINT_MAX);
1151-
qopt.jitter = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->jitter),
1151+
qopt.jitter = min_t(psched_time_t, PSCHED_NS2TICKS(q->jitter),
11521152
UINT_MAX);
11531153
qopt.limit = q->limit;
11541154
qopt.loss = q->loss;

0 commit comments

Comments
 (0)