Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The 10 us floor only limits a single gate action.
- [Medium] The commit message says the bug needs 'CAP_NET_ADMIN in the
initial user namespace (netlink_capable() checks init_user_ns, so a…
- [Medium] The commit message says 'An act_gate schedule is not tied to a
device, so unlike taprio there is no frame time to derive a bound…
- [Low] entry_policy still declares TCA_GATE_ENTRY_INTERVAL as a plain `{
.type = NLA_U32 }`, while fill_gate_entry() enforces the new 10000 ns…
- [Low] The 'Some context' paragraph says 'The request that reproduces
the cycle-time stall also carries a 1 ns entry interval'.
--
net/sched: act_gate: refuse schedule entries shorter than 10 us
This commit changes fill_gate_entry() so that act_gate schedule entries
must be at least 10 us long (GATE_MIN_INTERVAL_NSEC). Before, only a zero
interval was refused. The goal is to stop the soft hrtimer that
gate_timer_func() re-arms from keeping a CPU busy in the timer softirq.
Closes: https://sashiko.dev/#/patchset/tencent_4ED9536B0375C96183B2244CF7709768C605@qq.com
Some context:
The request that reproduces the cycle-time stall also carries a 1 ns
entry interval. With the cycle time derived from the entries, that alone
sets a 1 ns timer period: the report covers both defects.
[Severity: Low]
Which request does this paragraph mean?
The earlier commit in this series, "net/sched: act_gate: bound the cycle
time and start time arithmetic", documents a cycle-time reproducer that
uses TCA_GATE_BASE_TIME = 1, TCA_GATE_CYCLE_TIME = 0xffffffffffffffff and
"one schedule entry of 1000000 ns". That is 1 ms, not 1 ns.
The second sentence is accurate. gate_timer_func() advances
current_close_time by next->interval, so a single 1 ns entry does set a
1 ns period.
If this refers to a different reproducer, such as the Sashiko one, could
the message name it? As written, the two commits disagree about which
input triggers which defect.
Conditions to recreate the bug:
CONFIG_NET_ACT_GATE=y, and CAP_NET_ADMIN in the initial user namespace
(netlink_capable() checks init_user_ns, so a user namespace of its own
does not help), in a new network namespace:
[Severity: Medium]
Is this accurate for every way a gate action can be created?
The init_user_ns check is only in the standalone RTM_NEWACTION path:
net/sched/act_api.c:tc_ctl_action() {
...
if ((n->nlmsg_type != RTM_GETACTION) &&
!netlink_capable(skb, CAP_NET_ADMIN))
return -EPERM;
...
}
A gate action can also be created inline with a classifier, for example:
tc filter add dev lo ingress matchall action gate sched-entry close 1
That goes through:
RTM_NEWTFILTER
tc_new_tfilter()
tcf_exts_validate_ex()
tcf_action_init()
tcf_gate_init()
The only capability check on that path is relative to the netns:
net/core/rtnetlink.c:rtnetlink_rcv_msg() {
...
if (kind != RTNL_KIND_GET && !netlink_net_capable(skb, CAP_NET_ADMIN))
return -EPERM;
...
}
So it looks like an unprivileged user who runs unshare -Urn can set up
the 1 ns stall on kernels without this patch.
With Cc: stable on this patch, could the reachability description be
corrected? Backport and security triage will rely on it.
quoted hunk ↗ jump to hunk
diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c
index 4835f65439011..797562dbde693 100644
--- a/net/sched/act_gate.c
+++ b/net/sched/act_gate.c
@@ -25,6 +25,11 @@ static struct tc_action_ops act_gate_ops;
*/
#define GATE_ENTRIES_MAX 1024U
+/* An entry shorter than this lets the next expiry land before the softirq
+ * servicing the current one can finish, so the timer stays permanently behind.
+ */
+#define GATE_MIN_INTERVAL_NSEC 10000U
[Severity: High]
Does a per-entry floor bound the total timer softirq load on a CPU?
Each gate action owns a soft hrtimer (HRTIMER_MODE_ABS_SOFT). That timer
re-arms itself on every expiry with no exit condition:
net/sched/act_gate.c:gate_timer_func() {
...
gact->current_close_time = ktime_add_safe(gact->current_close_time,
next->interval);
...
hrtimer_set_expires(&gact->hitimer, close_time);
spin_unlock(&gact->tcf_lock);
return HRTIMER_RESTART;
}
Nothing limits how many gate actions a netns can have. tcf_gate_init()
calls tcf_idr_check_alloc() with a u32 index, and every filter with an
inline action gate creates a new instance and starts a new timer.
The commit message puts one expiry at a few hundred ns. At that cost,
about 33 actions with a single 10000 ns entry each, created from a task
pinned to one CPU, would keep that CPU fully busy in the timer softirq.
On the debug or PREEMPT_RT kernels the message mentions, where an expiry
costs a few us, 3 to 5 actions would be enough.
Wouldn't that bring back the "holds a CPU in the timer softirq for as
long as it exists" condition this patch is meant to remove? Fully fixing
it seems to need a limit on the combined load, for example a per-netns
cap on active gate timers or on their total expiry rate.
[ ... ]
quoted hunk ↗ jump to hunk
@@ -199,8 +204,10 @@ static int fill_gate_entry(struct nlattr **tb, struct tcfg_gate_entry *entry,
if (tb[TCA_GATE_ENTRY_INTERVAL])
interval = nla_get_u32(tb[TCA_GATE_ENTRY_INTERVAL]);
- if (interval == 0) {
- NL_SET_ERR_MSG(extack, "Invalid interval for schedule entry");
+ if (interval < GATE_MIN_INTERVAL_NSEC) {
+ NL_SET_ERR_MSG_FMT(extack,
+ "Entry interval must be at least %u ns",
+ GATE_MIN_INTERVAL_NSEC);
return -EINVAL;
}
[Severity: Medium]
The commit message says:
An act_gate schedule is not tied to a device, so unlike taprio there is
no frame time to derive a bound from
Does that hold for offloaded gate actions? act_gate is offloaded as
FLOW_ACTION_GATE to 802.1Qci PSFP hardware in sja1105, felix_vsc9959,
ocelot_flower, enetc and sparx5.
fill_gate_entry() runs for every gate action before the offload path
does, including flower skip_sw rules. sja1105 accepts much finer
schedules than 10 us:
drivers/net/dsa/sja1105/sja1105_vl.c:sja1105_vl_gate() {
...
div_s64_rem(entries[i].interval,
sja1105_delta_to_ns(1), &rem);
if (rem) {
NL_SET_ERR_MSG_MOD(extack,
"Interval must be multiple of 200 ns");
rc = -ERANGE;
goto out;
}
if (!entries[i].interval) {
NL_SET_ERR_MSG_MOD(extack,
"Interval cannot be zero");
...
}
Schedules such as "sched-entry OPEN 5000 -1 -1 sched-entry CLOSE 5000
-1 -1" used to install on sja1105. They now fail with -EINVAL and "Entry
interval must be at least 10000 ns". The driver's zero-interval check also
becomes unreachable.
The software hrtimer still runs for offloaded actions, so the CPU cost
argument may still justify the floor. Could the commit message say that
this rejects schedules that offload hardware used to accept? With
Cc: stable, the new limit would also reach deployed TSN setups.
[Severity: Low]
This isn't a bug, but could the minimum go in the policy instead of being
open-coded? entry_policy still declares the interval as a plain u32:
[TCA_GATE_ENTRY_INTERVAL] = { .type = NLA_U32 },
With NLA_POLICY_MIN(NLA_U32, GATE_MIN_INTERVAL_NSEC), nla_parse_nested()
would report the bad attribute in extack, and the policy would advertise
the correct range.
Also, when TCA_GATE_ENTRY_INTERVAL is missing, interval stays 0 and the
user is told the interval must be at least 10000 ns, even though no
interval was sent. Would NL_SET_ERR_ATTR_MISS describe that case better?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/ACT-WEXM.v4.r0.20261124074514%40mojatatu.com