Re: [PATCH] net/sched: sch_netem: prevent packet length underflow with negative overhead
From: Stephen Hemminger
Date: Sat Oct 10 2026 - 20:03:57 EST
On Thu, 8 Oct 2026 10:56:56 +0700
Bui Viet Dung <dungvn2345@xxxxxxxxx> wrote:
> packet_time_ns() calculates transmission time for netem rate shaping.
> It adds q->packet_overhead (signed 32-bit int) to len (unsigned
> 64-bit int).
>
> When userspace configures a negative packet overhead (via
> TCA_NETEM_RATE packet_overhead attribute) and an enqueued packet's
> length is smaller than the absolute overhead, (s64)len +
> q->packet_overhead is negative. Because len is u64, the addition wraps
> into an astronomical value (~2^64 - 1). When multiplied by NSEC_PER_SEC
> and divided by q->rate, the calculated delay spans hours or days,
> causing enqueued packets to be frozen in the qdisc indefinitely and
> stalling transmission.
>
> A similar underflow can occur in cell length calculation when
> (q->cell_size + q->cell_overhead) is non-positive.
>
> Clamp the effective packet length to 0 if the overhead adjustment
> would underflow, and return 0 delay if effective cell length is
> non-positive, matching the behavior in sch_cake and sch_tbf.
>
> Fixes: 7bc0f28c7a0c ("netem: rate extension")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Bui Viet Dung <dungvn2345@xxxxxxxxx>
> ---
I would rather cover this corner case in two ways: