act_gate fixes and gate selftest update
Subsystems (5)
cover act_gate fixes and gate selftest update
This series fixes act_gate schedule update races by switching to an RCU prepare-then-swap update pattern and ensures netlink dump structs are zeroed to avoid leaking padding to userspace. It also updates the tc-testing gate replace test to include the mandatory schedule entries so the test suite reflects the action's strict semantics.
Paul Moses (3):
selftests: tc-testing: fix gate replace schedule net/sched: act_gate: fix schedule updates with RCU swap net/sched: act_gate: zero-initialize netlink dump struct
include/net/tc_act/tc_gate.h | 43 ++- net/sched/act_gate.c | 287 +++++++++++++----- .../tc-testing/tc-tests/actions/gate.json | 2 +- 3 files changed, 254 insertions(+), 78 deletions(-)
Signature · 1 line
2.52.GIT
PATCH 1/3 selftests: tc-testing: fix gate replace schedule
The tdc test case 3719 ("Replace gate base-time action") fails with:
Error: Empty schedule entry list.
We have an error talking to the kernel
The test runs a 'replace' command while only specifying 'base-time' and omitting the mandatory schedule entries. The act_gate action (and tc userspace) requires a schedule to be present; replace is atomic and does not support partial updates or inheriting the previous schedule.
Update the test case to include a valid 'sched-entry' list in the replace command so it matches the kernel's expected behavior.
--- tools/testing/selftests/tc-testing/tc-tests/actions/gate.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/tc-testing/tc-tests/actions/gate.json +1 -1
@@ -131,7 +131,7 @@ 255 ] ], - "cmdUnderTest": "$TC action replace action gate base-time 400000000000ns index 20", + "cmdUnderTest": "$TC action replace action gate base-time 400000000000ns sched-entry open 200000000ns -1 8000000b index 20", "expExitCode": "0", "verifyCmd": "$TC action get action gate index 20", "matchPattern": "action order [0-9]*: .*base-time 400s.*index 20 ref",
Signature · 1 line
2.52.GIT
PATCH 2/3 net/sched: act_gate: fix schedule updates with RCU swap
In reply to Paul MosesSwitch act_gate parameters to an RCU-protected pointer and update schedule changes using a prepare-then-swap pattern. This avoids races between the timer/data paths and configuration updates, and cancels the hrtimer before swapping schedules.
A gate action replace could free and swap schedules while the hrtimer callback or data path still dereferences the old entries, leaving a use-after-free window during updates. The deferred swap and RCU free close that window. A reproducer is available on request.
Also clear params on early error for newly created actions to avoid leaving a dangling reference, and reject overflowing cycle times.
--- include/net/tc_act/tc_gate.h | 43 +++++- net/sched/act_gate.c | 276 +++++++++++++++++++++++++++-------- 2 files changed, 248 insertions(+), 71 deletions(-)
include/net/tc_act/tc_gate.h +36 -7
@@ -32,6 +32,7 @@ struct tcf_gate_params {s32 tcfg_clockid;size_t num_entries;struct list_head entries; +struct rcu_head rcu; };#define GATE_ACT_GATE_OPEN BIT(0)
@@ -39,7 +40,7 @@ struct tcf_gate_params {struct tcf_gate {struct tc_action common; -struct tcf_gate_params param; +struct tcf_gate_params __rcu *param;u8 current_gate_status;ktime_t current_close_time;u32 current_entry_octets;
@@ -53,45 +54,70 @@ struct tcf_gate {static inline s32 tcf_gate_prio (const struct tc_action *a) { +struct tcf_gate *gact =to_gate (a); +struct tcf_gate_params *p;s32 tcfg_prio; - tcfg_prio =to_gate (a)->param.tcfg_priority; + p =rcu_dereference_protected (gact->param, +lockdep_is_held (&a->tcfa_lock) || +lockdep_rtnl_is_held ()); + tcfg_prio = p->tcfg_priority;return tcfg_prio; }static inline u64 tcf_gate_basetime (const struct tc_action *a) { +struct tcf_gate *gact =to_gate (a); +struct tcf_gate_params *p;u64 tcfg_basetime; - tcfg_basetime =to_gate (a)->param.tcfg_basetime; + p =rcu_dereference_protected (gact->param, +lockdep_is_held (&a->tcfa_lock) || +lockdep_rtnl_is_held ()); + tcfg_basetime = p->tcfg_basetime;return tcfg_basetime; }static inline u64 tcf_gate_cycletime (const struct tc_action *a) { +struct tcf_gate *gact =to_gate (a); +struct tcf_gate_params *p;u64 tcfg_cycletime; - tcfg_cycletime =to_gate (a)->param.tcfg_cycletime; + p =rcu_dereference_protected (gact->param, +lockdep_is_held (&a->tcfa_lock) || +lockdep_rtnl_is_held ()); + tcfg_cycletime = p->tcfg_cycletime;return tcfg_cycletime; }static inline u64 tcf_gate_cycletimeext (const struct tc_action *a) { +struct tcf_gate *gact =to_gate (a); +struct tcf_gate_params *p;u64 tcfg_cycletimeext; - tcfg_cycletimeext =to_gate (a)->param.tcfg_cycletime_ext; + p =rcu_dereference_protected (gact->param, +lockdep_is_held (&a->tcfa_lock) || +lockdep_rtnl_is_held ()); + tcfg_cycletimeext = p->tcfg_cycletime_ext;return tcfg_cycletimeext; }static inline u32 tcf_gate_num_entries (const struct tc_action *a) { +struct tcf_gate *gact =to_gate (a); +struct tcf_gate_params *p;u32 num_entries; - num_entries =to_gate (a)->param.num_entries; + p =rcu_dereference_protected (gact->param, +lockdep_is_held (&a->tcfa_lock) || +lockdep_rtnl_is_held ()); + num_entries = p->num_entries;return num_entries; }
@@ -100,12 +126,15 @@ static inline struct action_gate_entry *tcf_gate_get_list(const struct tc_action *a) {struct action_gate_entry *oe; +struct tcf_gate *gact =to_gate (a);struct tcf_gate_params *p;struct tcfg_gate_entry *entry;u32 num_entries;int i =0 ; - p = &to_gate (a)->param; + p =rcu_dereference_protected (gact->param, +lockdep_is_held (&a->tcfa_lock) || +lockdep_rtnl_is_held ()); num_entries = p->num_entries;list_for_each_entry (entry, &p->entries, list)
net/sched/act_gate.c +212 -64
412 lines not on this page · raw message
Signature · 1 line
2.52.GIT
Jakub Kicinski
maintainerRe: [net,v1,2/3] net/sched: act_gate: fix schedule updates with RCU swap
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net/sched: act_gate: fix schedule updates with RCU swap
This patch switches act_gate parameters to an RCU-protected pointer and uses prepare-then-swap to avoid races during schedule updates.
Quoted 4 lines
net/sched/act_gate.c +0
-0
[ ... ]
Quoted 17 lines
net/sched/act_gate.c +17
-0+if (!list_empty (&newp.entries)) { +list_splice_init (&newp.entries, &p->entries); + p->num_entries = newp.num_entries; + }else if (ret !=ACT_P_CREATED ) { +struct tcfg_gate_entry *entry, *ne; + +list_for_each_entry (entry, &oldp->entries, list) { + ne =kmemdup (entry,sizeof (*ne),GFP_KERNEL ); +if (!ne) { + err = -ENOMEM ; + goto free_p; + } +INIT_LIST_HEAD (&ne->list); +list_add_tail (&ne->list, &p->entries); + } + p->num_entries = oldp->num_entries; + }
[ ... ]
net/sched/act_gate.c
Quoted 2 lines
net/sched/act_gate.c +2
-0+free_p: +kfree (p);
When kmemdup() fails partway through the loop copying entries from oldp->entries to p->entries, can the entries already added to p->entries be leaked? The jump to free_p calls kfree(p) but p->entries may contain allocated entries that are not released first.
The release_entry_list() call at release_new_entries releases newp.entries rather than p->entries:
net/sched/act_gate.c static int tcf_gate_init(struct net *net, struct nlattr *nla, · line 584
Quoted 2 lines
net/sched/act_gate.c +2
-0+release_new_entries: +release_entry_list (&newp.entries);
It looks like release_entry_list(&p->entries) should be called before kfree(p) at the free_p label.
PATCH 3/3 net/sched: act_gate: zero-initialize netlink dump struct
In reply to Paul MosesZero-initialize the tc_gate dump struct to avoid leaking padding bytes to userspace. Without clearing the struct, uninitialized stack padding can be copied into the netlink reply during action dumps.
--- net/sched/act_gate.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
net/sched/act_gate.c +5 -6
@@ -644,19 +644,18 @@ static int dumping_entry(struct sk_buff *skb,static int tcf_gate_dump (struct sk_buff *skb,struct tc_action *a,int bind,int ref) { -unsigned char *b =skb_tail_pointer (skb);struct tcf_gate *gact =to_gate (a); -struct tc_gate opt = { - .index = gact->tcf_index, - .refcnt =refcount_read (&gact->tcf_refcnt) - ref, - .bindcnt =atomic_read (&gact->tcf_bindcnt) - bind, - };struct tcfg_gate_entry *entry;struct tcf_gate_params *p;struct nlattr *entry_list; +struct tc_gate opt = { };struct tcf_t t; +unsigned char *b =skb_tail_pointer (skb);spin_lock_bh (&gact->tcf_lock); + opt.index = gact->tcf_index; + opt.refcnt =refcount_read (&gact->tcf_refcnt) - ref; + opt.bindcnt =atomic_read (&gact->tcf_bindcnt) - bind; opt.action = gact->tcf_action; p = rcu_dereference_protected(gact->param,
Signature · 1 line
2.52.GIT
Jakub Kicinski
maintainerRe: [PATCH net v1 3/3] net/sched: act_gate: zero-initialize netlink dump struct
net/sched/act_gate.c static int dumping_entry(struct sk_buff *skb, · line 653
Quoted 13 lines · On Fri, 16 Jan 2026 11:26:08 +0000 Paul Moses wrote:
net/sched/act_gate.c +2
-6-unsigned char *b =skb_tail_pointer (skb);struct tcf_gate *gact =to_gate (a); -struct tc_gate opt = { - .index = gact->tcf_index, - .refcnt =refcount_read (&gact->tcf_refcnt) - ref, - .bindcnt =atomic_read (&gact->tcf_bindcnt) - bind, - };struct tcfg_gate_entry *entry;struct tcf_gate_params *p;struct nlattr *entry_list; +struct tc_gate opt = { };struct tcf_t t; +unsigned char *b =skb_tail_pointer (skb);
Why is *b moving? Please avoid unnecessary code changes in fixes.
Also -- we prefer the declaration lines to be sorted longest to shortest. If a dependency prevents that the init needs to be moved to the body of the function (this mostly applies to patch 2).
Jakub Kicinski
maintainerQuoted 5 lines · On Fri, 16 Jan 2026 11:25:50 +0000 Paul Moses wrote:
This series fixes
act_gateschedule update races by switching to an RCU prepare-then-swap update pattern and ensures netlink dump structs are zeroed to avoid leaking padding to userspace. It also updates the tc-testing gate replace test to include the mandatory schedule entries so the test suite reflects the action's strict semantics.
Please repost and CC appropriate maintainers and authors. ./scripts/get_maintainer.pl $patch
Signature · 1 line
pw-bot: cr
Hi Jakub,
I originally submitted to [email protected] on Dec 27th and this submission was a direct request from the maintainers. So if your concern is whether or not they are tracking, I can confirm that they are. If it's just a matter of adherence to process, than I will go ahead and do it, but wanted to avoid the churn if unnecessary.
The big question currently is what is appropriate for stable. I do not believe it's possible to fix this issue without negatively impacting the performance of the gate without either using a unlock → cancel → relock pattern or conversion to RCU. Neither of which is ideal for stable, so more constructive input is needed.
Thanks
Paul
Quoted 15 lines · Jakub Kicinski
Quoted 5 lines · On Fri, 16 Jan 2026 11:25:50 +0000 Paul Moses wrote:
This series fixes
act_gateschedule update races by switching to an RCU prepare-then-swap update pattern and ensures netlink dump structs are zeroed to avoid leaking padding to userspace. It also updates the tc-testing gate replace test to include the mandatory schedule entries so the test suite reflects the action's strict semantics.Please repost and CC appropriate maintainers and authors.
./scripts/get_maintainer.pl$patch
--
pw-bot: cr
Jakub Kicinski
maintainerQuoted 5 lines · On Mon, 19 Jan 2026 18:50:08 +0000 Paul Moses wrote:
The big question currently is what is appropriate for stable. I do not believe it's possible to fix this issue without negatively impacting the performance of the gate without either using a unlock → cancel → relock pattern or conversion to RCU. Neither of which is ideal for stable, so more constructive input is needed.
The conversion to RCU looks like a solid choice and I think it's acceptable for stable.
Let me send you a couple of trivial comments on patch 2, hopefully once CCed the authors can provide deeper review.