Re: net: act_gate bug. was: [syzbot] [tomoyo?] [mm?] INFO: rcu detected stall in security_file_ioctl (9)

From: Jamal Hadi Salim

Date: Tue Nov 24 2026 - 05:03:50 EST


On Tue, Nov 24, 2026 at 1:00 AM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> On Mon, Nov 23, 2026 at 08:45 PM syzbot <syzbot+b6f8640465bdf47ca708@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> > rcu: hardirqs softirqs csw/system
> > rcu: number: 5264 0 0
> > rcu: cputime: 138 52351 25 ==> 52490(ms)
>
> It's not tomoyo, mm or bpf. Looks like act_gate.
> Zero new softirqs in 52 sec, so one hrtimer_run_softirq() doesn't return.
>
> > RBP: ffff88807ed35538 R08: ffffffff91be1bbf R09: 1ffffffff237c377
> > R10: dffffc0000000000 R11: fffffbfff237c378 R12: ffff8880b8228600
> > R13: ffffffff89fd0480 R14: ffff8880b8228600 R15: 1ffff1101704514a
>
> The registers with lockdep struct sizes:
>
> reg value points to
> -------- ---------------- --------------------------------------
> R14 ffff8880b8228600 cpu_base
> R15 << 3 ffff8880b8228a50 clock_base[HRTIMER_BASE_TAI_SOFT].seq
> RBP ffff88807ed35538 kmalloc-512 + 0x138, tcf_gate->hitimer
>
> act_gate has the only soft hrtimer that can be on CLOCK_TAI.
> bpf_timer_init() rejects that clock.
>
> TCA_GATE_CYCLE_TIME is an unchecked u64. In gate_timer_func():
>
> n = div64_u64(ktime_sub_ns(now, base), cycle);
> close_time = ktime_add_ns(base, (n + 1) * cycle);
>
> With base = 0 and cycle = U64_MAX, n is 0 and close_time is -1.
> The timer restarts in the past and __hrtimer_run_queues() runs it again.
> It's there since
> commit a51c328df310 ("net: qos: introduce a gate control flow action").
>
> Jamal,
> taprio's INT_MAX limit doesn't fit. tdc uses cycle-time of 600 sec.
> The diff saturates the sum instead.

Looks familiar - i will take a look.

cheers,
jamal
> Here is a potential fix:
>
> diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c
> index 711cf24..5422d60 100644
> --- a/net/sched/act_gate.c
> +++ b/net/sched/act_gate.c
> @@ -45,8 +45,9 @@ static void gate_get_start_time(struct tcf_gate *gact,
> const struct tcf_gate_params *param,
> ktime_t *start)
> {
> - ktime_t now, base, cycle;
> - u64 n;
> + u64 cycle = param->tcfg_cycletime;
> + ktime_t now, base;
> + u64 rem;
>
> base = ns_to_ktime(param->tcfg_basetime);
> now = gate_get_time(gact);
> @@ -56,10 +57,9 @@ static void gate_get_start_time(struct tcf_gate *gact,
> return;
> }
>
> - cycle = param->tcfg_cycletime;
> -
> - n = div64_u64(ktime_sub_ns(now, base), cycle);
> - *start = ktime_add_ns(base, (n + 1) * cycle);
> + /* cycle is an unchecked u64, the sum must not wrap into the past */
> + div64_u64_rem(ktime_sub(now, base), cycle, &rem);
> + *start = ktime_add_safe(now, cycle - rem);
> }
>
> static void gate_start_timer(struct tcf_gate *gact, ktime_t start)
> @@ -107,15 +107,8 @@ static enum hrtimer_restart gate_timer_func(struct hrtimer *timer)
>
> now = gate_get_time(gact);
>
> - if (ktime_after(now, close_time)) {
> - ktime_t cycle, base;
> - u64 n;
> -
> - cycle = p->tcfg_cycletime;
> - base = ns_to_ktime(p->tcfg_basetime);
> - n = div64_u64(ktime_sub_ns(now, base), cycle);
> - close_time = ktime_add_ns(base, (n + 1) * cycle);
> - }
> + if (ktime_after(now, close_time))
> + gate_get_start_time(gact, p, &close_time);
>
> gact->next_entry = next;
>