Re: [PATCH net v3 7/7] net/sched: act_gate: guard NULL params in accessors
From: Victor Nogueira <hidden>
Date: 2026-01-21 19:47:34
Also in:
lkml, stable
On 21/01/2026 10:21, Paul Moses wrote:
quoted hunk ↗ jump to hunk
Guard NULL params in accessors/dump/timer paths to avoid crashes during teardown or failed initialization. Other actions already guard params before RCU cleanup (act_pedit, commit 52cf89f78c01bf; act_vlan, commits 4c5b9d9642c859 and 1edf8abe04090c), so act_gate should tolerate NULL in reader paths too. [...]diff --git a/include/net/tc_act/tc_gate.h b/include/net/tc_act/tc_gate.h index 9587d9e9fa38f..8c3309b0dd779 100644 --- a/include/net/tc_act/tc_gate.h +++ b/include/net/tc_act/tc_gate.h@@ -54,12 +54,13 @@ struct tcf_gate { static inline s32 tcf_gate_prio(const struct tc_action *a) { - s32 tcfg_prio; + s32 tcfg_prio = 0; struct tcf_gate_params *p; rcu_read_lock(); p = rcu_dereference(to_gate(a)->param); - tcfg_prio = p->tcfg_priority; + if (p) + tcfg_prio = p->tcfg_priority;
I don't believe you need to check for NULL in these helper functions. From what I understood, the only place setting this to NULL is the cleanup callback. You also won't be able to run this in parallel with the init callback.
quoted hunk ↗ jump to hunk
[...] list_for_each_entry(entry, &p->entries, list)diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c index e4134b9a4a314..65b53cbf37e67 100644 --- a/net/sched/act_gate.c +++ b/net/sched/act_gate.c@@ -82,7 +82,11 @@ static enum hrtimer_restart gate_timer_func(struct hrtimer *timer) p = rcu_dereference_protected(gact->param, lockdep_is_held(&gact->tcf_lock)); + if (!p) + goto out_unlock;
Also don't think you need to check this here. Unless I'm missing something, cleanup will only set param to NULL after the timer callback has finished executing.
quoted hunk ↗ jump to hunk
[...]@@ -643,6 +652,8 @@ static int tcf_gate_dump(struct sk_buff *skb, struct tc_action *a, rcu_read_lock(); p = rcu_dereference(gact->param); + if (!p) + goto nla_put_failure_rcu;
I don't think you need the check here either. Take a look at act_vlan. cheers, Victor